Class: Payola::Subscription
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Payola::Subscription
- Includes:
- AASM, GuidBehavior
- Defined in:
- app/models/payola/subscription.rb
Instance Attribute Summary collapse
-
#old_plan ⇒ Object
Returns the value of attribute old_plan.
-
#old_quantity ⇒ Object
Returns the value of attribute old_quantity.
Instance Method Summary collapse
- #custom_fields ⇒ Object
- #instrument_plan_changed(old_plan) ⇒ Object
- #instrument_quantity_changed(old_quantity) ⇒ Object
- #name ⇒ Object
- #price ⇒ Object
- #redirect_path(sale) ⇒ Object
- #redirector ⇒ Object
- #sync_with!(stripe_sub) ⇒ Object
- #to_param ⇒ Object
- #verifier ⇒ Object
- #verify_charge ⇒ Object
- #verify_charge! ⇒ Object
Methods included from GuidBehavior
Instance Attribute Details
#old_plan ⇒ Object
Returns the value of attribute old_plan.
23 24 25 |
# File 'app/models/payola/subscription.rb', line 23 def old_plan @old_plan end |
#old_quantity ⇒ Object
Returns the value of attribute old_quantity.
23 24 25 |
# File 'app/models/payola/subscription.rb', line 23 def old_quantity @old_quantity end |
Instance Method Details
#custom_fields ⇒ Object
86 87 88 89 90 91 92 |
# File 'app/models/payola/subscription.rb', line 86 def custom_fields if self.signed_custom_fields.present? verifier.verify(self.signed_custom_fields) else nil end end |
#instrument_plan_changed(old_plan) ⇒ Object
113 114 115 116 117 |
# File 'app/models/payola/subscription.rb', line 113 def instrument_plan_changed(old_plan) self.old_plan = old_plan Payola.instrument(instrument_key('plan_changed'), self) Payola.instrument(instrument_key('plan_changed', false), self) end |
#instrument_quantity_changed(old_quantity) ⇒ Object
119 120 121 122 123 |
# File 'app/models/payola/subscription.rb', line 119 def instrument_quantity_changed(old_quantity) self.old_quantity = old_quantity Payola.instrument(instrument_key('quantity_changed'), self) Payola.instrument(instrument_key('quantity_changed', false), self) end |
#name ⇒ Object
53 54 55 |
# File 'app/models/payola/subscription.rb', line 53 def name self.plan.name end |
#price ⇒ Object
57 58 59 |
# File 'app/models/payola/subscription.rb', line 57 def price self.plan.amount end |
#redirect_path(sale) ⇒ Object
61 62 63 |
# File 'app/models/payola/subscription.rb', line 61 def redirect_path(sale) self.plan.redirect_path(self) end |
#redirector ⇒ Object
125 126 127 |
# File 'app/models/payola/subscription.rb', line 125 def redirector plan end |
#sync_with!(stripe_sub) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/models/payola/subscription.rb', line 94 def sync_with!(stripe_sub) self.current_period_start = Time.at(stripe_sub.current_period_start) self.current_period_end = Time.at(stripe_sub.current_period_end) self.ended_at = Time.at(stripe_sub.ended_at) if stripe_sub.ended_at self.trial_start = Time.at(stripe_sub.trial_start) if stripe_sub.trial_start self.trial_end = Time.at(stripe_sub.trial_end) if stripe_sub.trial_end self.canceled_at = Time.at(stripe_sub.canceled_at) if stripe_sub.canceled_at self.quantity = stripe_sub.quantity self.stripe_status = stripe_sub.status self.cancel_at_period_end = stripe_sub.cancel_at_period_end self.save! self end |
#to_param ⇒ Object
109 110 111 |
# File 'app/models/payola/subscription.rb', line 109 def to_param guid end |
#verifier ⇒ Object
65 66 67 |
# File 'app/models/payola/subscription.rb', line 65 def verifier @verifier ||= ActiveSupport::MessageVerifier.new(Payola.secret_key_for_sale(self), digest: 'SHA256') end |
#verify_charge ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/models/payola/subscription.rb', line 69 def verify_charge begin self.verify_charge! rescue RuntimeError => e self.error = e. self.fail! end end |
#verify_charge! ⇒ Object
78 79 80 81 82 83 84 |
# File 'app/models/payola/subscription.rb', line 78 def verify_charge! if Payola.charge_verifier.arity > 1 Payola.charge_verifier.call(self, custom_fields) else Payola.charge_verifier.call(self) end end |