Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix payment_intent_unexpected_state error when voiding payment intents #115

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/decorators/models/spree/payment_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ def gateway_order_identifier
gateway_order_id
end

def handle_void_response(response)
record_response(response)

if response.success? ||
(response.params['error'] && response.params['error']['code'] == 'payment_intent_unexpected_state')
self.response_code = response.authorization
void
else
gateway_error(response)
end
end

::Spree::Payment.prepend(self)
end
end
12 changes: 12 additions & 0 deletions spec/models/solidus_stripe/create_intents_payment_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@
it "invalidates it" do
expect { subject }.to change { payment.reload.state }.to 'void'
end

context "and the response returns a payment_intent_unexpected_state error" do
before do
response_params = { 'error' => { 'code' => 'payment_intent_unexpected_state' } }
response = double(success?: false, authorization: payment.response_code, params: response_params)
expect_any_instance_of(Spree::PaymentMethod::StripeCreditCard).to receive(:void) { response }
end

it "invalidates it" do
expect { subject }.to change { payment.reload.state }.to 'void'
end
end
end

context "when none is a Payment Intent" do
Expand Down