Class: Spree::Wallet::AddPaymentSourcesToWallet

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/wallet/add_payment_sources_to_wallet.rb

Overview

This class is responsible for saving payment sources in the user’s “wallet” for future use. You can substitute your own class via ‘Spree::Config.add_payment_sources_to_wallet_class`.

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ AddPaymentSourcesToWallet

Returns a new instance of AddPaymentSourcesToWallet.



5
6
7
# File 'app/models/spree/wallet/add_payment_sources_to_wallet.rb', line 5

def initialize(order)
  @order = order
end

Instance Method Details

#add_to_walletundefined

This is called after an order transistions to complete and should save the order’s payment source/s in the user’s “wallet” for future use.

Returns:

  • (undefined)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/spree/wallet/add_payment_sources_to_wallet.rb', line 13

def add_to_wallet
  if !order.temporary_credit_card &&
     order.user_id &&
     order.valid_credit_cards.present?
    # arbitrarily pick the first one for the default
    default_cc = order.valid_credit_cards.first
    # TODO: target for refactoring -- why is order checkout responsible for the user -> credit_card relationship?
    default_cc.user_id = order.user_id
    default_cc.default = true
    default_cc.save
  end
end