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 #6964: don't try to complete a failed payment #6965

Merged
merged 1 commit into from
Mar 4, 2021

Conversation

andrewpbrett
Copy link
Contributor

@andrewpbrett andrewpbrett commented Feb 27, 2021

What? Why?

Closes #6964

Here we only complete a payment if it's in a state where it can be completed, and list those states explicitly

What should we test?

Choosing not to authorize an SCA payment should not result in a snail.

This might be pretty difficult to write an automated test for since we're testing what happens when the customer interacts with the Stripe website.

Release notes

I don't think this is happening in production

Changelog Category: Technical changes

Dependencies

Documentation updates

@andrewpbrett andrewpbrett self-assigned this Feb 28, 2021
@sauloperez
Copy link
Contributor

This might be pretty difficult to write an automated test for since we're testing what happens when the customer interacts with the Stripe website.

but we do know the exact Stripe request we receive when that happens, don't we? We would need to stub that out and we'd be reproducing the same scenario.

@@ -20,7 +20,7 @@ def call!

last_payment.update_attribute(:cvv_response_message, nil)
OrderWorkflow.new(@order).next
last_payment.complete! if !last_payment.completed?
last_payment.complete! if %w('pending processing').include?(last_payment.state)
Copy link
Contributor

@sauloperez sauloperez Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally make the effort to extract a method out of this and find a name for this so 1) we don't mix levels of abstraction in #call! 2) we make it easier for the next dev to understand why pending and processing states and not others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'm not sure I didn't just use the can_complete? method in the first place.

Copy link
Contributor

@sauloperez sauloperez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test this new behavior.

EDIT nice! the test is failing

@filipefurtad0 filipefurtad0 self-assigned this Mar 4, 2021
@filipefurtad0 filipefurtad0 added the pr-staged-fr staging.coopcircuits.fr label Mar 4, 2021
@filipefurtad0
Copy link
Contributor

Hey @andrewpbrett ,

thanks for addressing this.

Before this PR we had the following scenario:

i) placing an order in the BO (admin)
ii) using the email received per email to proceed with authentication (customer)
iii) clicking "Fail Authentication" leads to the bug as below (left, admin; right, customer):

image

After this PR:
iii) does not trigger a snail anymore, and looks like this:

image

Also, please not that I was not able to reproduce bug #6683 after this PR 🎉
Neither by refusing authentication nor by using an invalid card like 4000008260003178.

image

We can see, that the (3 eur) transaction fee do not pile up, despite the failed payment attempts:

image

The fact that the order is still in the balance due state relates to bug #5574.

It would be good to have a spec covering us from the re-occurrence of #6683. Should I open a tech-debt for this?

Awesome, let's get this merged 🎉

@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label Mar 4, 2021
@sauloperez sauloperez merged commit 982c3d2 into openfoodfoundation:master Mar 4, 2021
@sauloperez
Copy link
Contributor

It would be good to have a spec covering us from the re-occurrence of #6683. Should I open a tech-debt for this?

Yes, I think it's worth exploring why no test failed after we introduced this regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Admin][Orders] Snail when failing Stripe SCA-Payments
3 participants