From 96462325d2158a6e5caadcba6a4d2a9402a7d692 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Thu, 3 Dec 2020 15:07:58 -0800 Subject: [PATCH] fix #5829 --- app/models/spree/gateway/stripe_sca.rb | 7 ++++++- spec/support/request/stripe_stubs.rb | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/spree/gateway/stripe_sca.rb b/app/models/spree/gateway/stripe_sca.rb index 02681ae210..200dbd4a0e 100644 --- a/app/models/spree/gateway/stripe_sca.rb +++ b/app/models/spree/gateway/stripe_sca.rb @@ -61,7 +61,7 @@ module Spree payment_intent_response = Stripe::PaymentIntent.retrieve(payment_intent_id, stripe_account: stripe_account_id) gateway_options[:stripe_account] = stripe_account_id - provider.refund(payment_intent_response.amount_received, response_code, gateway_options) + provider.refund(refundable_amount(payment_intent_response), response_code, gateway_options) end # NOTE: the name of this method is determined by Spree::Payment::Processing @@ -79,6 +79,11 @@ module Spree private + def refundable_amount(payment_intent_response) + payment_intent_response.amount_received - + payment_intent_response.charges.data.map(&:amount_refunded).sum + end + # In this gateway, what we call 'secret_key' is the 'login' def options options = super diff --git a/spec/support/request/stripe_stubs.rb b/spec/support/request/stripe_stubs.rb index 909604b9ae..ba9f877e59 100644 --- a/spec/support/request/stripe_stubs.rb +++ b/spec/support/request/stripe_stubs.rb @@ -75,7 +75,9 @@ module StripeStubs amount_received: 2000, status: options[:intent_status] || "requires_capture", last_payment_error: nil, - charges: { data: [{ id: "ch_1234", amount: 2000 }] }) } + charges: { + data: [{ id: "ch_1234", amount: 2000, amount_refunded: 0 }] }) + } end def payment_intent_redirect_response_mock(redirect_url)