-
-
Notifications
You must be signed in to change notification settings - Fork 730
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 #5829 (Voiding an initial payment (i.e. a full refund) after partially refunding the order is not possible with Stripe-SCA) #6453
Conversation
61ea144
to
9646232
Compare
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there are unsuccessful charges? Looking at the docs it seems that they might not even include them all?
This list only contains the latest charge, even if there were previously multiple unsuccessful charges. To view all previous charges for a PaymentIntent, you can filter the charges list using the payment_intent parameter.
source: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-charges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this still works, because each time we try to make a payment for an order it creates a new PaymentIntent. I tried a couple things:
At first, I thought you meant "what if there are multiple partial refunds" so I tried that: I placed an order, then in the backend I made two adjustments to the order and issued a refund each time. The amount_refunded
returns the sum across all refunds.
Then I realized you might be asking "what if the customer or an admin creates unsuccessful charges?" For the admin side, I placed an order through the front end and chose Cash. Then on the backend, I created two unsuccessful charges and one successful one. I was still able to do the partial refunds on the successful charge. I found the same when the unsuccessful charges were created by the customer on the front end.
The option to do the refund on the failed charge never appears in the first place, only on the successful one:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But does that mean that the payment_intent_response.charges
includes only successful charges then? Sorry, I'm still wrapping my head around this Stripe API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm saying is that for our case, the PaymentIntent that we're querying Stripe about will only have the single successful charge. It's definitely complex! Especially since our mapping is not as direct as it could be if we were only dealing with Stripe as a provider.
Hey @andrewpbrett , I took the initial issue and reproduced those steps, after staging the PR. Tried this for 3D-auth and non-3D-auth cards (not sure this would make any difference). I associated a transaction fee for Stripe-SCA. Issuing one refund, and voiding the initial payment Issuing several refunds and voiding the initial payment - with transaction fees The dashboard from Stripe shows all these changes correctly: The values above are not correct - this is because of issue #3584, so we're all good here 👍 Failing payments (unsuccessful charges), issuing partial refunds and voiding the initial payment This case works fine as well. All correct in the BO and in the Stripe-dashboard: Ready to go! PS: also bumped on a known issue related to the removal of the last item from an order - #5546 |
What? Why?
Closes #5829
This adds a method to calculate the refundable amount by looking at the
charges
property of the returnedPaymentIntent
from Stripe. A charge is created when a partial refund is issued. If there are no partial refunds issued, the full amount will still be refunded.What should we test?
See issue's Steps to Reproduce
Release notes
Fixed a bug that prevented payments from being refunded if a partial refund had already been issued.
Changelog Category: User facing changes
Dependencies
Documentation updates