Class: Spree::Wallet::DefaultPaymentBuilder

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

Overview

This class is responsible for building a default payment on an order, using a payment source that is already in the user's “wallet” and is marked as being the default payment source.

Instance Method Summary (collapse)

Constructor Details

- (DefaultPaymentBuilder) initialize(order)

Returns a new instance of DefaultPaymentBuilder



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

def initialize(order)
  @order = order
end

Instance Method Details

- (Payment) build

Build a payment to be added to an order prior to moving into the “payment” state.

Returns:

  • (Payment)

    the unsaved payment to be added, or nil if none.



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

def build
  default = order.user.try!(:wallet).try!(:default_wallet_payment_source)
  if default && order.payments.where(source_type: default.payment_source_type).none?
    Spree::Payment.new(
      payment_method: default.payment_source.payment_method,
      source: default.payment_source,
    )
  end
end