Class: Spree::PaypalPlatform::CreateSource
- Inherits:
-
Object
- Object
- Spree::PaypalPlatform::CreateSource
- Defined in:
- app/services/spree/paypal_platform/create_source.rb
Overview
Builds a PaymentSources record from a PayPal Orders payment_source.
PayPal returns one of paypal, apple_pay, or card (Card Fields).
Unknown keys raise so a new wallet is not silently dropped.
Instance Method Summary collapse
- #call ⇒ Spree::PaymentSource
-
#initialize(paypal_payment_source:, gateway:, order: nil, user: nil) ⇒ CreateSource
constructor
A new instance of CreateSource.
Constructor Details
#initialize(paypal_payment_source:, gateway:, order: nil, user: nil) ⇒ CreateSource
Returns a new instance of CreateSource.
18 19 20 21 22 23 |
# File 'app/services/spree/paypal_platform/create_source.rb', line 18 def initialize(paypal_payment_source:, gateway:, order: nil, user: nil) @paypal_payment_source = paypal_payment_source.with_indifferent_access @gateway = gateway @user = user || order&.user @order = order end |
Instance Method Details
#call ⇒ Spree::PaymentSource
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/spree/paypal_platform/create_source.rb', line 29 def call if paypal_payment_source[:paypal].present? create_paypal_source elsif paypal_payment_source[:apple_pay].present? create_apple_pay_source elsif paypal_payment_source[:card].present? create_card_source else raise ArgumentError, "Unsupported PayPal payment source: #{paypal_payment_source.keys.join(', ')}" end end |