Class: Spree::Wallet::CreatePaymentSource

Inherits:
Object
  • Object
show all
Includes:
ServiceModule::Base
Defined in:
app/services/spree/wallet/create_payment_source.rb

Instance Method Summary collapse

Methods included from ServiceModule::Base

prepended

Instance Method Details

#call(payment_method:, params: {}, user: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/spree/wallet/create_payment_source.rb', line 6

def call(payment_method:, params: {}, user: nil)
  return failure(nil, :missing_attributes) if params.nil?

  source_attributes = {
    payment_method_id: payment_method.id,
    user_id: user&.id,
    gateway_payment_profile_id: params[:gateway_payment_profile_id],
    gateway_customer_profile_id: params[:gateway_customer_profile_id],
    last_digits: params[:last_digits],
    month: params[:month],
    year: params[:year],
    name: params[:name]
  }

  source = payment_method.payment_source_class.new(source_attributes)

  source.save ? success(source) : failure(source)
end