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: "default") ⇒ Boolean
- #invoice!(options = {}) ⇒ Object
- #on_generic_trial? ⇒ Boolean
- #on_trial?(name: "default", plan: nil) ⇒ Boolean
- #on_trial_or_subscribed?(name: "default", processor_plan: nil) ⇒ Boolean
- #paypal? ⇒ Boolean
- #processor=(value) ⇒ Object
- #processor_subscription(subscription_id, options = {}) ⇒ Object
- #stripe? ⇒ Boolean
- #subscribe(name: "default", plan: "default", **options) ⇒ Object
- #subscribed?(name: "default", processor_plan: nil) ⇒ Boolean
- #subscription(name: "default") ⇒ 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
113 114 115 |
# File 'lib/pay/billable.rb', line 113 def braintree? processor == "braintree" end |
#charge(amount_in_cents, options = {}) ⇒ Object
49 50 51 52 |
# File 'lib/pay/billable.rb', line 49 def charge(amount_in_cents, = {}) check_for_processor send("create_#{processor}_charge", amount_in_cents, ) end |
#customer ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/pay/billable.rb', line 36 def customer check_for_processor raise Pay::Error, "Email is required to create a customer" if email.nil? customer = send("#{processor}_customer") update_card(card_token) if card_token.present? customer end |
#customer_name ⇒ Object
45 46 47 |
# File 'lib/pay/billable.rb', line 45 def customer_name [try(:first_name), try(:last_name)].compact.join(" ") end |
#has_incomplete_payment?(name: "default") ⇒ Boolean
121 122 123 |
# File 'lib/pay/billable.rb', line 121 def has_incomplete_payment?(name: "default") subscription(name: name)&.has_incomplete_payment? end |
#invoice!(options = {}) ⇒ Object
101 102 103 |
# File 'lib/pay/billable.rb', line 101 def invoice!( = {}) send("#{processor}_invoice!", ) end |
#on_generic_trial? ⇒ Boolean
74 75 76 |
# File 'lib/pay/billable.rb', line 74 def on_generic_trial? trial_ends_at? && trial_ends_at > Time.zone.now end |
#on_trial?(name: "default", plan: nil) ⇒ Boolean
65 66 67 68 69 70 71 72 |
# File 'lib/pay/billable.rb', line 65 def on_trial?(name: "default", 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: "default", processor_plan: nil) ⇒ Boolean
92 93 94 95 |
# File 'lib/pay/billable.rb', line 92 def on_trial_or_subscribed?(name: "default", processor_plan: nil) on_trial?(name: name, plan: processor_plan) || subscribed?(name: name, processor_plan: processor_plan) end |
#paypal? ⇒ Boolean
117 118 119 |
# File 'lib/pay/billable.rb', line 117 def paypal? braintree? && card_type == "PayPal" end |
#processor=(value) ⇒ Object
31 32 33 34 |
# File 'lib/pay/billable.rb', line 31 def processor=(value) super(value) self.processor_id = nil if processor_changed? end |
#processor_subscription(subscription_id, options = {}) ⇒ Object
78 79 80 81 |
# File 'lib/pay/billable.rb', line 78 def processor_subscription(subscription_id, = {}) check_for_processor send("#{processor}_subscription", subscription_id, ) end |
#stripe? ⇒ Boolean
109 110 111 |
# File 'lib/pay/billable.rb', line 109 def stripe? processor == "stripe" end |
#subscribe(name: "default", plan: "default", **options) ⇒ Object
54 55 56 57 |
# File 'lib/pay/billable.rb', line 54 def subscribe(name: "default", plan: "default", **) check_for_processor send("create_#{processor}_subscription", name, plan, ) end |
#subscribed?(name: "default", processor_plan: nil) ⇒ Boolean
83 84 85 86 87 88 89 90 |
# File 'lib/pay/billable.rb', line 83 def subscribed?(name: "default", 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: "default") ⇒ Object
97 98 99 |
# File 'lib/pay/billable.rb', line 97 def subscription(name: "default") subscriptions.for_name(name).last end |
#upcoming_invoice ⇒ Object
105 106 107 |
# File 'lib/pay/billable.rb', line 105 def upcoming_invoice send("#{processor}_upcoming_invoice") end |
#update_card(token) ⇒ Object
59 60 61 62 63 |
# File 'lib/pay/billable.rb', line 59 def update_card(token) check_for_processor customer if processor_id.nil? send("update_#{processor}_card", token) end |