Class: SpreeStripe::CreateSource
- Inherits:
-
Object
- Object
- SpreeStripe::CreateSource
- Defined in:
- app/services/spree_stripe/create_source.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(stripe_payment_method_details:, stripe_payment_method_id:, gateway:, stripe_billing_details:, order: nil, user: nil) ⇒ CreateSource
constructor
A new instance of CreateSource.
Constructor Details
#initialize(stripe_payment_method_details:, stripe_payment_method_id:, gateway:, stripe_billing_details:, order: nil, user: nil) ⇒ CreateSource
Returns a new instance of CreateSource.
3 4 5 6 7 8 9 10 |
# File 'app/services/spree_stripe/create_source.rb', line 3 def initialize(stripe_payment_method_details:, stripe_payment_method_id:, gateway:, stripe_billing_details:, order: nil, user: nil) @stripe_payment_method_details = stripe_payment_method_details @stripe_payment_method_id = stripe_payment_method_id @gateway = gateway @user = user || order&.user @stripe_billing_details = stripe_billing_details @order = order end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/spree_stripe/create_source.rb', line 12 def call case stripe_payment_method_details.type when 'card' find_or_create_credit_card when 'klarna' SpreeStripe::PaymentSources::Klarna.create!(source_params) when 'afterpay_clearpay' SpreeStripe::PaymentSources::AfterPay.create!(source_params) when 'sepa_debit' SpreeStripe::PaymentSources::SepaDebit.create!(source_params) when 'p24' SpreeStripe::PaymentSources::Przelewy24.create!(source_params.merge(bank: stripe_payment_method_details.p24.bank)) when 'ideal' SpreeStripe::PaymentSources::Ideal.create!( source_params.merge( bank: stripe_payment_method_details.ideal.bank, last4: stripe_payment_method_details.ideal.iban_last4 ) ) when 'alipay' SpreeStripe::PaymentSources::Alipay.create!(source_params) when 'link' SpreeStripe::PaymentSources::Link.create!(source_params) when 'affirm' SpreeStripe::PaymentSources::Affirm.create!(source_params) else raise "[STRIPE] Unknown payment method #{stripe_payment_method_details.type}" end end |