Skip to content

Commit

Permalink
Merge pull request #185 from solidusio/kennyadsl/fix-nil-autocapture
Browse files Browse the repository at this point in the history
Allow to use the auto_capture global preference
  • Loading branch information
kennyadsl authored Jan 18, 2023
2 parents e463a01 + 6b21267 commit ed0661f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ed0661f

Please sign in to comment.