Class: Jackpot::Customer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Jackpot::Customer
- Defined in:
- app/models/jackpot/customer.rb
Instance Attribute Summary (collapse)
-
- (Object) credit_card_verification_value
Returns the value of attribute credit_card_verification_value.
Instance Method Summary (collapse)
- - (Object) expiration_date
-
- (Boolean) expiring?(number_of_months = 3)
Checks if this customer's card will expire within the next :months.
- - (Object) pay_subscription
- - (Object) update_credit_card(card)
Instance Attribute Details
- (Object) credit_card_verification_value
Returns the value of attribute credit_card_verification_value
35 36 37 |
# File 'app/models/jackpot/customer.rb', line 35 def credit_card_verification_value @credit_card_verification_value end |
Instance Method Details
- (Object) expiration_date
62 63 64 |
# File 'app/models/jackpot/customer.rb', line 62 def expiration_date "#{credit_card_expiry_month}/#{credit_card_expiry_year}" end |
- (Boolean) expiring?(number_of_months = 3)
Checks if this customer's card will expire within the next :months.
number_of_months -> Number of months within this card will expire. Defaults to 3
70 71 72 |
# File 'app/models/jackpot/customer.rb', line 70 def expiring?(number_of_months=3) (Date.parse(expiration_date) - number_of_months.months) <= Date.today.at_beginning_of_month end |
- (Object) pay_subscription
37 38 39 40 41 42 43 44 45 |
# File 'app/models/jackpot/customer.rb', line 37 def pay_subscription if credit_card_token if subscription.present? && subscription.charge(self) update_attribute(:good_until, Date.today + 1.month) end else raise Jackpot::Errors::CustomerHasNoCardSaved.new end end |
- (Object) update_credit_card(card)
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/jackpot/customer.rb', line 48 def update_credit_card(card) raise Errors::CardIsInvalid unless card.valid? write_attribute :credit_card_number , card.masquerade_number write_attribute :credit_card_expiry_month , card.month write_attribute :credit_card_expiry_year , card.year # This should never be recorded self.credit_card_verification_value = card.verification_value stored_card_response = Jackpot::Base.gateway.store(card) write_attribute :credit_card_token , stored_card_response.params["customer_vault_id"] save end |