Module: ActsAsSubscription::Subscription::SubscriptionInstanceMethods
- Defined in:
- lib/acts_as_subscription/subscription.rb
Overview
Instance methods for an ActsAsSubscription::Subscription instance, which use ActiveMerchant to validate credit card information.
These instance methods should be included in ActiveRecord::Base to provide subscription validation support.
Instance Attribute Summary collapse
-
#cc_number ⇒ Object
Allows entry of a complete credit card number, even though we only store the last 4 digits internally.
-
#credit_card ⇒ Object
readonly
Instantiates an instance of ActiveMerchant::Billing::CreditCard if one hasn’t already been created.
Instance Method Summary collapse
- #backend_save ⇒ Object
-
#is_free_plan? ⇒ Boolean
Returns true if the current plan is free, false otherwise.
-
#require_verification_value? ⇒ Boolean
This can be overridden in the implementing model, to turn off verification-value validation.
-
#require_zip_code? ⇒ Boolean
This can be overridden in the implementing model, to turn off zip-code validation.
Instance Attribute Details
#cc_number ⇒ Object
Allows entry of a complete credit card number, even though we only store the last 4 digits internally.
144 145 146 |
# File 'lib/acts_as_subscription/subscription.rb', line 144 def cc_number @cc_number end |
#credit_card ⇒ Object (readonly)
Instantiates an instance of ActiveMerchant::Billing::CreditCard if one hasn’t already been created.
140 141 142 |
# File 'lib/acts_as_subscription/subscription.rb', line 140 def credit_card @credit_card end |
Instance Method Details
#backend_save ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/acts_as_subscription/subscription.rb', line 160 def backend_save p "+++++++++++++++++++++++ saving +++++++++++++++++++++++" if self.new_record? result = ActsAsSubscription::Subscription::Backend.instance.create_subscription(self) else result = ActsAsSubscription::Subscription::Backend.instance.update_subscription(self) end # No way of knowing what fields the errors are for for some backends - just add a top-level error. unless result == true self.errors.add :base, result return false end return true end |
#is_free_plan? ⇒ Boolean
Returns true if the current plan is free, false otherwise.
147 148 149 150 151 152 |
# File 'lib/acts_as_subscription/subscription.rb', line 147 def is_free_plan? # If no plan-code is given, assume this is a paid plan to be on the safe side. return false unless self.plan_code return (self.plan_code =~ /free/i) != nil end |
#require_verification_value? ⇒ Boolean
This can be overridden in the implementing model, to turn off verification-value validation.
183 184 185 |
# File 'lib/acts_as_subscription/subscription.rb', line 183 def require_verification_value? return self.is_free_plan? == false end |
#require_zip_code? ⇒ Boolean
This can be overridden in the implementing model, to turn off zip-code validation.
178 179 180 |
# File 'lib/acts_as_subscription/subscription.rb', line 178 def require_zip_code? return self.is_free_plan? == false end |