Skip to content

Commit

Permalink
fix #5829
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpbrett committed Dec 5, 2020
1 parent dfabc5f commit 9646232
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/models/spree/gateway/stripe_sca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def void(response_code, _creditcard, gateway_options)
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
Expand All @@ -79,6 +79,11 @@ def create_profile(payment)

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
Expand Down
4 changes: 3 additions & 1 deletion spec/support/request/stripe_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def payment_intent_authorize_response_mock(options)
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)
Expand Down

0 comments on commit 9646232

Please sign in to comment.