Class: Workarea::Payment::StoreCreditCard

Inherits:
Object
  • Object
show all
Includes:
CreditCardOperation
Defined in:
app/models/workarea/payment/store_credit_card.rb

Instance Method Summary collapse

Methods included from CreditCardOperation

#gateway, #handle_active_merchant_errors

Constructor Details

#initialize(credit_card, options = {}) ⇒ StoreCreditCard

Returns a new instance of StoreCreditCard.



6
7
8
9
# File 'app/models/workarea/payment/store_credit_card.rb', line 6

def initialize(credit_card, options = {})
  @credit_card = credit_card
  @options = options
end

Instance Method Details

#perform!Boolean

Reaches out to the credit card gateway to store a new credit card

Returns:

  • (Boolean)

    the result of the gateway call



14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/workarea/payment/store_credit_card.rb', line 14

def perform!
  return true if @credit_card.token.present?

  response = handle_active_merchant_errors do
    gateway.store(@credit_card.to_active_merchant)
  end

  @credit_card.token = response.params['billingid']

  response.success?
end

#save!Boolean

Reaches out to the credit card gateway to store a new credit card

Returns:

  • (Boolean)

    the result of the gateway call and saving to the db



29
30
31
# File 'app/models/workarea/payment/store_credit_card.rb', line 29

def save!
  perform! && @credit_card.save
end