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 double order note issue #3331

Merged
merged 6 commits into from
Aug 7, 2024
Merged

Fix double order note issue #3331

merged 6 commits into from
Aug 7, 2024

Conversation

Mayisha
Copy link
Contributor

@Mayisha Mayisha commented Aug 1, 2024

Fixes #2463 #2331

Changes proposed in this Pull Request:

  • Lock the order before creating and confirming the intent. Details here.

Testing instructions

  • Checkout to develop branch.
  • Ensure that webhooks are configured properly.
  • Use jurassic tube or ngrok for making your site publicly accessible (do not use localhost, I can not reproduce the issue in localhost)
  • As a shopper, purchase a product with a card.
  • Now check the order in your admin dashboard. You will find 2 order notes about the charge and order status transition.
Screenshot 2024-08-02 at 12 22 14 AM
  • Now checkout to this branch fix/double-processing.
  • As a shopper, purchase a product with a card again.
  • Now check the order in your admin dashboard. This time the order should not have any duplicate notes.

@Mayisha Mayisha marked this pull request as draft August 1, 2024 18:09
@Mayisha Mayisha requested a review from a-danae August 2, 2024 08:15
@Mayisha Mayisha marked this pull request as ready for review August 2, 2024 19:40
@james-allan
Copy link
Contributor

james-allan commented Aug 5, 2024

Nice work @Mayisha! I ran through some tests, however I came across an issue with CashApp and maybe other payment methods too.

CARD PAYMENT

develop This branch
Screenshot 2024-08-05 at 3 53 30 PM Screenshot 2024-08-05 at 3 55 11 PM

3D-SECURE CARD PAYMENT

I tested a 3D-Secure card because I thought it had to be processed via the webhook. 3DS cards still work because the order is processed via WC_Stripe_Intent_Controller->update_order_status_ajax() once the modal is completed.

OTHER PAYMENT METHODS
Next I tested other payment methods that I know require webhook processing like CashApp. If I attempt to purchase a product using CashApp, the webhook processing gets skipped here (code link), because the order is still locked. This is because the lock is only lifted in this PR if there is a charge.

With that in mind I think we need to consider also lifting the lock even if there isn't any charge. ie before we return from process_payment_with_deferred_intent(). I'm not sure though, is there a case where you think the order should remain locked?

Copy link
Contributor

@a-danae a-danae left a comment

Choose a reason for hiding this comment

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

Nice work replicating and sending a PR for the duplicated order notes issue, @Mayisha !

The changes in the code make sense to me. I tested the following scenarios, and they look good.

✅ Double processing doesn’t happen in this branch. I got double notes, emails, and inventory reduction in develop when paying with Cards and they no longer happen in this branch.

✅ CashPay works as expected. I was able to replicate the issue James mentioned in 57293c5, and CashApp orders now do change to “Processing”.

I tested the following cases that use webhooks:

✅ Authorize and capture later works as expected with Cards, Klarna, and Afterpay

✅ SEPA orders behave as expected, including when using [IBANs](https://docs.stripe.com/payments/sepa-debit/accept-a-payment?web-or-mobile=web&payments-ui-type=stripe-hosted#test-ibans) that simulate delayed transitions

I'm leaving the final approval of this PR to @james-allan since he spotted an issue in the previous review. But things look good on my end 👍

Copy link
Contributor

@james-allan james-allan left a comment

Choose a reason for hiding this comment

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

Yep looks good to me. Thanks for fixing that @Mayisha and for the additional review @a-danae!

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.

Double Notes & Double Emails
3 participants