Module: SpreePaypalCheckout::Gateway::PaymentSetupSessions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/spree_paypal_checkout/gateway/payment_setup_sessions.rb
Instance Method Summary collapse
-
#complete_payment_setup_session(setup_session:, params: {}) ⇒ Object
Completes a setup session by exchanging the approved setup token for a permanent payment token, creates a Spree::PaymentSource representing the vaulted PayPal account, and transitions the session.
-
#create_payment_setup_session(customer:, external_data: {}) ⇒ Spree::PaymentSetupSessions::PaypalCheckout
Creates a PayPal Vault setup token (temporary, awaiting buyer approval) and persists a Spree::PaymentSetupSessions::PaypalCheckout record.
- #payment_setup_session_class ⇒ Object
- #setup_session_supported? ⇒ Boolean
Instance Method Details
#complete_payment_setup_session(setup_session:, params: {}) ⇒ Object
Completes a setup session by exchanging the approved setup token for a permanent payment token, creates a Spree::PaymentSource representing the vaulted PayPal account, and transitions the session.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/spree_paypal_checkout/gateway/payment_setup_sessions.rb', line 53 def complete_payment_setup_session(setup_session:, params: {}) protect_from_error do response = client.vault.create_payment_token( 'body' => { 'payment_source' => { 'token' => { 'id' => setup_session.external_id, 'type' => 'SETUP_TOKEN' } } } ) payment_token = response.data setup_session.payment_source = build_payment_source_from_token(setup_session, payment_token) setup_session.update!( external_data: setup_session.external_data.to_h.merge('payment_token' => payment_token.as_json) ) setup_session.complete if setup_session.can_complete? rescue PaypalServerSdk::APIException => e setup_session.fail if setup_session.can_fail? raise Spree::Core::GatewayError, "PayPal Vault error: #{e.}" end setup_session end |
#create_payment_setup_session(customer:, external_data: {}) ⇒ Spree::PaymentSetupSessions::PaypalCheckout
Creates a PayPal Vault setup token (temporary, awaiting buyer approval) and persists a Spree::PaymentSetupSessions::PaypalCheckout record.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/spree_paypal_checkout/gateway/payment_setup_sessions.rb', line 21 def create_payment_setup_session(customer:, external_data: {}) return_url = external_data[:return_url] || external_data['return_url'] || default_setup_return_url cancel_url = external_data[:cancel_url] || external_data['cancel_url'] || default_setup_cancel_url protect_from_error do response = client.vault.create_setup_token( SpreePaypalCheckout::SetupTokenPresenter.new( customer: customer, return_url: return_url, cancel_url: cancel_url ).to_h ) payment_setup_session_class.create!( customer: customer, payment_method: self, status: 'pending', external_id: response.data.id, external_data: response.data.as_json.merge( 'return_url' => return_url, 'cancel_url' => cancel_url ) ) end end |
#payment_setup_session_class ⇒ Object
10 11 12 |
# File 'app/models/spree_paypal_checkout/gateway/payment_setup_sessions.rb', line 10 def payment_setup_session_class Spree::PaymentSetupSessions::PaypalCheckout end |
#setup_session_supported? ⇒ Boolean
6 7 8 |
# File 'app/models/spree_paypal_checkout/gateway/payment_setup_sessions.rb', line 6 def setup_session_supported? true end |