Sha256: c6fb81767887c56f52ec721ea4bb41eca58eacbd455d27a0dd0925c44ab6225b

Contents?: true

Size: 841 Bytes

Versions: 133

Compression:

Stored size: 841 Bytes

Contents

# frozen_string_literal: true

# 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.
class Spree::Wallet::DefaultPaymentBuilder
  def initialize(order)
    @order = order
  end

  # Build a payment to be added to an order prior to moving into the "payment"
  # state.
  #
  # @return [Payment] the unsaved payment to be added, or nil if none.
  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

  private

  attr_reader :order
end

Version data entries

133 entries across 133 versions & 2 rubygems

Version Path
solidus_core-4.4.2 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.4.1 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.4.0 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.3.4 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.2.4 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.1.5 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.3.3 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.3.2 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.1.4 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.3.1 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.3.0 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.2.3 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.1.3 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.0.4 app/models/spree/wallet/default_payment_builder.rb
solidus_core-3.4.6 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.0.3 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.1.2 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.2.2 app/models/spree/wallet/default_payment_builder.rb
solidus_core-3.4.5 app/models/spree/wallet/default_payment_builder.rb
solidus_core-4.2.1 app/models/spree/wallet/default_payment_builder.rb