Module: Pay::Billable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pay/billable.rb,
lib/pay/billable/sync_email.rb
Defined Under Namespace
Modules: SyncEmail
Class Attribute Summary collapse
-
.includers ⇒ Object
readonly
Returns the value of attribute includers.
Class Method Summary collapse
Instance Method Summary collapse
- #braintree? ⇒ Boolean
- #charge(amount_in_cents, options = {}) ⇒ Object
- #customer ⇒ Object
- #customer_name ⇒ Object
- #has_incomplete_payment?(name: Pay.default_product_name) ⇒ Boolean
- #invoice!(options = {}) ⇒ Object
- #on_generic_trial? ⇒ Boolean
- #on_trial?(name: Pay.default_product_name, plan: nil) ⇒ Boolean
- #on_trial_or_subscribed?(name: Pay.default_product_name, processor_plan: nil) ⇒ Boolean
- #paddle? ⇒ Boolean
- #paypal? ⇒ Boolean
- #processor=(value) ⇒ Object
- #processor_subscription(subscription_id, options = {}) ⇒ Object
- #stripe? ⇒ Boolean
- #subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
- #subscribed?(name: Pay.default_product_name, processor_plan: nil) ⇒ Boolean
- #subscription(name: Pay.default_product_name) ⇒ Object
- #upcoming_invoice ⇒ Object
- #update_card(token) ⇒ Object
Class Attribute Details
.includers ⇒ Object (readonly)
Returns the value of attribute includers.
9 10 11 |
# File 'lib/pay/billable.rb', line 9 def includers @includers end |
Class Method Details
.included(base = nil, &block) ⇒ Object
12 13 14 15 16 |
# File 'lib/pay/billable.rb', line 12 def self.included(base = nil, &block) @includers ||= [] @includers << base if base super end |
Instance Method Details
#braintree? ⇒ Boolean
114 115 116 |
# File 'lib/pay/billable.rb', line 114 def braintree? processor == "braintree" end |
#charge(amount_in_cents, options = {}) ⇒ Object
50 51 52 53 |
# File 'lib/pay/billable.rb', line 50 def charge(amount_in_cents, = {}) check_for_processor send("create_#{processor}_charge", amount_in_cents, ) end |
#customer ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/pay/billable.rb', line 37 def customer check_for_processor raise Pay::Error, I18n.t("errors.email_required") if email.nil? customer = send("#{processor}_customer") update_card(card_token) if card_token.present? customer end |
#customer_name ⇒ Object
46 47 48 |
# File 'lib/pay/billable.rb', line 46 def customer_name [try(:first_name), try(:last_name)].compact.join(" ") end |
#has_incomplete_payment?(name: Pay.default_product_name) ⇒ Boolean
126 127 128 |
# File 'lib/pay/billable.rb', line 126 def has_incomplete_payment?(name: Pay.default_product_name) subscription(name: name)&.has_incomplete_payment? end |
#invoice!(options = {}) ⇒ Object
102 103 104 |
# File 'lib/pay/billable.rb', line 102 def invoice!( = {}) send("#{processor}_invoice!", ) end |
#on_generic_trial? ⇒ Boolean
75 76 77 |
# File 'lib/pay/billable.rb', line 75 def on_generic_trial? trial_ends_at? && trial_ends_at > Time.zone.now end |
#on_trial?(name: Pay.default_product_name, plan: nil) ⇒ Boolean
66 67 68 69 70 71 72 73 |
# File 'lib/pay/billable.rb', line 66 def on_trial?(name: Pay.default_product_name, plan: nil) return true if default_generic_trial?(name, plan) sub = subscription(name: name) return sub&.on_trial? if plan.nil? sub&.on_trial? && sub.processor_plan == plan end |
#on_trial_or_subscribed?(name: Pay.default_product_name, processor_plan: nil) ⇒ Boolean
93 94 95 96 |
# File 'lib/pay/billable.rb', line 93 def on_trial_or_subscribed?(name: Pay.default_product_name, processor_plan: nil) on_trial?(name: name, plan: processor_plan) || subscribed?(name: name, processor_plan: processor_plan) end |
#paddle? ⇒ Boolean
122 123 124 |
# File 'lib/pay/billable.rb', line 122 def paddle? processor == "paddle" end |
#paypal? ⇒ Boolean
118 119 120 |
# File 'lib/pay/billable.rb', line 118 def paypal? braintree? && card_type == "PayPal" end |
#processor=(value) ⇒ Object
32 33 34 35 |
# File 'lib/pay/billable.rb', line 32 def processor=(value) super(value) self.processor_id = nil if processor_changed? end |
#processor_subscription(subscription_id, options = {}) ⇒ Object
79 80 81 82 |
# File 'lib/pay/billable.rb', line 79 def processor_subscription(subscription_id, = {}) check_for_processor send("#{processor}_subscription", subscription_id, ) end |
#stripe? ⇒ Boolean
110 111 112 |
# File 'lib/pay/billable.rb', line 110 def stripe? processor == "stripe" end |
#subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
55 56 57 58 |
# File 'lib/pay/billable.rb', line 55 def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **) check_for_processor send("create_#{processor}_subscription", name, plan, ) end |
#subscribed?(name: Pay.default_product_name, processor_plan: nil) ⇒ Boolean
84 85 86 87 88 89 90 91 |
# File 'lib/pay/billable.rb', line 84 def subscribed?(name: Pay.default_product_name, processor_plan: nil) subscription = subscription(name: name) return false if subscription.nil? return subscription.active? if processor_plan.nil? subscription.active? && subscription.processor_plan == processor_plan end |
#subscription(name: Pay.default_product_name) ⇒ Object
98 99 100 |
# File 'lib/pay/billable.rb', line 98 def subscription(name: Pay.default_product_name) subscriptions.loaded? ? subscriptions.reverse.detect { |s| s.name == name } : subscriptions.for_name(name).last end |
#upcoming_invoice ⇒ Object
106 107 108 |
# File 'lib/pay/billable.rb', line 106 def upcoming_invoice send("#{processor}_upcoming_invoice") end |
#update_card(token) ⇒ Object
60 61 62 63 64 |
# File 'lib/pay/billable.rb', line 60 def update_card(token) check_for_processor customer if processor_id.nil? send("update_#{processor}_card", token) end |