Class: Spree::CreditCard
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::CreditCard
- Defined in:
- app/models/spree/credit_card.rb
Direct Known Subclasses
Defined Under Namespace
Classes: CardDetector
Instance Attribute Summary collapse
-
#number ⇒ Object
Returns the value of attribute number.
-
#verification_value ⇒ Object
Returns the value of attribute verification_value.
Instance Method Summary collapse
- #actions ⇒ Object
-
#brand ⇒ Object
needed for some of the ActiveMerchant gateways (eg. SagePay).
-
#can_capture?(payment) ⇒ Boolean
Indicates whether its possible to capture the payment.
-
#can_credit?(payment) ⇒ Boolean
Indicates whether its possible to credit the payment.
-
#can_void?(payment) ⇒ Boolean
Indicates whether its possible to void the payment.
-
#display_number ⇒ Object
Show the card number, with all but last 4 numbers replace with “X”.
- #has_payment_profile? ⇒ Boolean
- #name ⇒ Object
- #name? ⇒ Boolean
-
#set_card_type ⇒ Object
sets self.cc_type while we still have the card number.
- #set_last_digits ⇒ Object
- #spree_cc_type ⇒ Object
- #verification_value? ⇒ Boolean
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
8 9 10 |
# File 'app/models/spree/credit_card.rb', line 8 def number @number end |
#verification_value ⇒ Object
Returns the value of attribute verification_value.
8 9 10 |
# File 'app/models/spree/credit_card.rb', line 8 def verification_value @verification_value end |
Instance Method Details
#actions ⇒ Object
60 61 62 |
# File 'app/models/spree/credit_card.rb', line 60 def actions %w{capture void credit} end |
#brand ⇒ Object
needed for some of the ActiveMerchant gateways (eg. SagePay)
56 57 58 |
# File 'app/models/spree/credit_card.rb', line 56 def brand spree_cc_type end |
#can_capture?(payment) ⇒ Boolean
Indicates whether its possible to capture the payment
65 66 67 |
# File 'app/models/spree/credit_card.rb', line 65 def can_capture?(payment) payment.pending? || payment.checkout? end |
#can_credit?(payment) ⇒ Boolean
Indicates whether its possible to credit the payment. Note that most gateways require that the payment be settled first which generally happens within 12-24 hours of the transaction.
76 77 78 79 80 |
# File 'app/models/spree/credit_card.rb', line 76 def can_credit?(payment) return false unless payment.completed? return false unless payment.order.payment_state == 'credit_owed' payment.credit_allowed > 0 end |
#can_void?(payment) ⇒ Boolean
Indicates whether its possible to void the payment.
70 71 72 |
# File 'app/models/spree/credit_card.rb', line 70 def can_void?(payment) !payment.void? end |
#display_number ⇒ Object
Show the card number, with all but last 4 numbers replace with “X”. (XXXX-XXXX-XXXX-4338)
51 52 53 |
# File 'app/models/spree/credit_card.rb', line 51 def display_number "XXXX-XXXX-XXXX-#{last_digits}" end |
#has_payment_profile? ⇒ Boolean
82 83 84 |
# File 'app/models/spree/credit_card.rb', line 82 def has_payment_profile? gateway_customer_profile_id.present? end |
#name ⇒ Object
42 43 44 |
# File 'app/models/spree/credit_card.rb', line 42 def name "#{first_name} #{last_name}" end |
#name? ⇒ Boolean
38 39 40 |
# File 'app/models/spree/credit_card.rb', line 38 def name? first_name? && last_name? end |
#set_card_type ⇒ Object
sets self.cc_type while we still have the card number
34 35 36 |
# File 'app/models/spree/credit_card.rb', line 34 def set_card_type self.cc_type ||= CardDetector.brand?(number) end |
#set_last_digits ⇒ Object
19 20 21 22 23 |
# File 'app/models/spree/credit_card.rb', line 19 def set_last_digits number.to_s.gsub!(/\s/,'') verification_value.to_s.gsub!(/\s/,'') self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1) end |
#spree_cc_type ⇒ Object
86 87 88 89 |
# File 'app/models/spree/credit_card.rb', line 86 def spree_cc_type return 'visa' if Rails.env.development? cc_type end |
#verification_value? ⇒ Boolean
46 47 48 |
# File 'app/models/spree/credit_card.rb', line 46 def verification_value? verification_value.present? end |