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

Allow payment_intent_succeeded webhook to handle orders without intent_id attached #3118

Merged
merged 13 commits into from
Oct 21, 2021

Conversation

daquinons
Copy link
Contributor

@daquinons daquinons commented Oct 14, 2021

Fixes 1202-gh-Automattic/woocommerce-payments-server

Changes proposed in this Pull Request

There has been a lot of reports in different merchants about a situation where an order was successfully paid in Stripe side, but canceled in WooCommerce (because of woocommerce_hold_stock_minutes).

Find more about it and its investigation in the shared links here 1202-gh-Automattic/woocommerce-payments-server

This PR allows the webhook to obtain an order using the attached order_id in the metadata of the object, in case the intent_id was not properly attached into the order because of any racing condition.

@dmallory42 has also contributed moving attach_intent_info_to_order and attach_exchange_info_to_order higher in the execution to try to mitigate the racing condition as we spoke here p1634210077172300-slack-C0208C3BXHP

Testing instructions

  • Run the tests, I've added a new one that gets an order when one is not found using intent_id.
  • To test it manually, go to this line
    $order = $this->wcpay_db->order_from_intent_id( $intent_id );
    and change it for
    $order = $this->wcpay_db->order_from_intent_id( "anything" ); in order to simulate getting an intent_id that we had no record of.
  • Make a purchase
  • See in the logs intent_id not found, using order_id to retrieve order, that indicates the webhook has gone into the new added logic.
  • Check the order is successfully marked as payment_complete after the order was successfully retrieved using the webhook metadata.

  • Added changelog entry (or does not apply)
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@daquinons daquinons changed the title WIP: Allow payment_intent_succeeded webhook to handle orders without intent_id attached Allow payment_intent_succeeded webhook to handle orders without intent_id attached Oct 14, 2021
@daquinons daquinons marked this pull request as ready for review October 14, 2021 11:33
@daquinons daquinons requested a review from a team October 14, 2021 11:33
@daquinons daquinons added the status: has pr The issue has a PR. label Oct 14, 2021
Copy link
Contributor

@dmallory42 dmallory42 left a comment

Choose a reason for hiding this comment

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

LGTM and works well, thanks for working on this! :shipit:

As mentioned via Slack, I think we should add a few GlobalStep flows to the next release for using the checkout and the blocks checkout purchasing a simple product, subscription product, etc.

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

Successfully merging this pull request may close these issues.

2 participants