Module: Workarea::Payment::CreditCard

Extended by:
ActiveSupport::Concern
Included in:
SavedCreditCard, Tender::CreditCard
Defined in:
app/models/workarea/payment/credit_card.rb

Instance Method Summary collapse

Instance Method Details

#card_change?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/workarea/payment/credit_card.rb', line 50

def card_change?
  persisted? && (number_changed? || month_changed? || year_changed?)
end

#expired?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/workarea/payment/credit_card.rb', line 42

def expired?
  Time.current > Time.zone.parse("#{month}/#{year}").next_month.beginning_of_month
end

#number=(val) ⇒ Object



38
39
40
# File 'app/models/workarea/payment/credit_card.rb', line 38

def number=(val)
  @number = val.to_s.gsub(/\D/, '')
end

#number_changed?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/workarea/payment/credit_card.rb', line 46

def number_changed?
  number.present? && number.to_s.last(4) != display_number.to_s.last(4)
end

#to_active_merchantObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/workarea/payment/credit_card.rb', line 58

def to_active_merchant
  ActiveMerchant::Billing::CreditCard.new(
    # TODO token doesn't make sense here because ActiveMerchant::CreditCard
    # strips anything that's not a number and most tokens are alpha numberic
    number: token.presence || number.presence || display_number,
    month: month,
    year: year,
    verification_value: cvv,
    first_name: first_name,
    last_name: last_name
  )
end

#tokenized?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/models/workarea/payment/credit_card.rb', line 54

def tokenized?
  token.present?
end