diff --git a/app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb b/app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb index bb9147a..9ee112e 100644 --- a/app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb +++ b/app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb @@ -7,7 +7,7 @@ class PaypalOrdersController < ::Spree::Api::BaseController def show authorize! :show, @order, order_token - order_request = @payment_method.gateway.create_order(@order, @payment_method.auto_capture) + order_request = @payment_method.gateway.create_order(@order, @payment_method.auto_capture?) render json: order_request, status: order_request.status_code end diff --git a/app/models/solidus_paypal_commerce_platform/payment_method.rb b/app/models/solidus_paypal_commerce_platform/payment_method.rb index 45bc55e..9964b35 100644 --- a/app/models/solidus_paypal_commerce_platform/payment_method.rb +++ b/app/models/solidus_paypal_commerce_platform/payment_method.rb @@ -83,7 +83,7 @@ def javascript_sdk_url(order: nil, currency: nil) parameters = { 'client-id': client_id, - intent: auto_capture ? "capture" : "authorize", + intent: auto_capture? ? "capture" : "authorize", commit: commit_immediately ? "false" : "true", components: options[:display_credit_messaging] ? "buttons,messages" : "buttons", currency: currency, diff --git a/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb b/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb index 17d4149..dfd3819 100644 --- a/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb @@ -153,6 +153,31 @@ def Struct(data) # rubocop:disable Naming/MethodName end end + context 'when autocapture value is true' do + it 'sets the intent to capture' do + paypal_payment_method.update(auto_capture: true) + + expect(url.query.split("&")).to include("intent=capture") + end + end + + context 'when autocapture value is false' do + it 'sets the intent to capture' do + paypal_payment_method.update(auto_capture: false) + + expect(url.query.split("&")).to include("intent=authorize") + end + end + + context 'when autocapture value is nil' do + it 'sets the intent to the global auto_capture value' do + paypal_payment_method.update(auto_capture: nil) + stub_spree_preferences(auto_capture: true) + + expect(url.query.split("&")).to include("intent=capture") + end + end + context 'when messaging is turned on' do it 'includes messaging component' do paypal_payment_method.preferences.update(display_credit_messaging: true)