Class: Spree::CreditCard
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::CreditCard
- Defined in:
- app/models/spree/credit_card.rb
Direct Known Subclasses
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
-
#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.
-
#cc_type=(type) ⇒ Object
cc_type is set by jquery.payment, which helpfully provides different types from Active Merchant.
-
#display_number ⇒ Object
Show the card number, with all but last 4 numbers replace with “X”.
- #expiry=(expiry) ⇒ Object
- #has_payment_profile? ⇒ Boolean
- #name ⇒ Object
- #name? ⇒ Boolean
- #set_last_digits ⇒ Object
- #to_active_merchant ⇒ Object
- #verification_value? ⇒ Boolean
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
7 8 9 |
# File 'app/models/spree/credit_card.rb', line 7 def number @number end |
#verification_value ⇒ Object
Returns the value of attribute verification_value.
7 8 9 |
# File 'app/models/spree/credit_card.rb', line 7 def verification_value @verification_value end |
Instance Method Details
#actions ⇒ Object
67 68 69 |
# File 'app/models/spree/credit_card.rb', line 67 def actions %w{capture void credit} end |
#can_capture?(payment) ⇒ Boolean
Indicates whether its possible to capture the payment
72 73 74 |
# File 'app/models/spree/credit_card.rb', line 72 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.
83 84 85 86 87 |
# File 'app/models/spree/credit_card.rb', line 83 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.
77 78 79 |
# File 'app/models/spree/credit_card.rb', line 77 def can_void?(payment) !payment.void? end |
#cc_type=(type) ⇒ Object
cc_type is set by jquery.payment, which helpfully provides different types from Active Merchant. Converting them is necessary.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/spree/credit_card.rb', line 30 def cc_type=(type) real_type = case type when 'mastercard', 'maestro' 'master' when 'amex' 'american_express' when 'dinersclub' 'diners_club' else type end self[:cc_type] = real_type end |
#display_number ⇒ Object
Show the card number, with all but last 4 numbers replace with “X”. (XXXX-XXXX-XXXX-4338)
63 64 65 |
# File 'app/models/spree/credit_card.rb', line 63 def display_number "XXXX-XXXX-XXXX-#{last_digits}" end |
#expiry=(expiry) ⇒ Object
19 20 21 22 |
# File 'app/models/spree/credit_card.rb', line 19 def expiry=(expiry) self[:month], self[:year] = expiry.split(" / ") self[:year] = "20" + self[:year] end |
#has_payment_profile? ⇒ Boolean
89 90 91 |
# File 'app/models/spree/credit_card.rb', line 89 def has_payment_profile? gateway_customer_profile_id.present? end |
#name ⇒ Object
54 55 56 |
# File 'app/models/spree/credit_card.rb', line 54 def name "#{first_name} #{last_name}" end |
#name? ⇒ Boolean
50 51 52 |
# File 'app/models/spree/credit_card.rb', line 50 def name? first_name? && last_name? end |
#set_last_digits ⇒ Object
44 45 46 47 48 |
# File 'app/models/spree/credit_card.rb', line 44 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 |
#to_active_merchant ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/spree/credit_card.rb', line 93 def to_active_merchant ActiveMerchant::Billing::CreditCard.new( :number => number, :month => month, :year => year, :verification_value => verification_value, :first_name => first_name, :last_name => last_name ) end |
#verification_value? ⇒ Boolean
58 59 60 |
# File 'app/models/spree/credit_card.rb', line 58 def verification_value? verification_value.present? end |