Skip to content

Commit

Permalink
API v2 checkout update rescue from GatewayError
Browse files Browse the repository at this point in the history
  • Loading branch information
johannboutet authored and damianlegawiec committed Jul 23, 2020
1 parent e29fc66 commit d4895b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/app/controllers/spree/api/v2/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class BaseController < ActionController::API
include Spree::Core::ControllerHelpers::Store
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
rescue_from CanCan::AccessDenied, with: :access_denied
rescue_from Spree::Core::GatewayError, with: :gateway_error

def content_type
Spree::Api::Config[:api_v2_content_type]
Expand Down Expand Up @@ -108,6 +109,10 @@ def record_not_found
def access_denied(exception)
render_error_payload(exception.message, 403)
end

def gateway_error(exception)
render_error_payload(exception.message)
end
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions api/spec/requests/spree/api/v2/storefront/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,17 @@
expect(order.payments.last.source.last_digits).to eq('1111')
end
end

context 'when the gateway rejects the payment source' do
let(:params) { payment_params }

before do
allow_any_instance_of(Spree::Order).to receive(:update_from_params).and_raise(Spree::Core::GatewayError.new('Card declined'))
execute
end

it_behaves_like 'returns 422 HTTP status'
end
end

context 'special instructions' do
Expand Down

0 comments on commit d4895b4

Please sign in to comment.