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

Use metadata stored on the intent to fetch an order for webhook processing #3567

Merged
merged 13 commits into from
Nov 13, 2024

Conversation

james-allan
Copy link
Contributor

Changes proposed in this Pull Request:

This PR updates the webhook handler to enable it to fetch the relevant order from payment_intent metadata.

This has two impacts:

  1. If we fail to record the intent ID on the order after we've sent the payment intent request to Stripe, we can use this mechanism to process the response from Stripe.
  2. It improves the performance of webhook processing because we no longer run a database query to locate an order by the intent ID.

We've seen at least 1 large store where we fire off the payment intent request to Stripe, however, we never process the response. This means we don't record the intent ID on the order and therefore cannot process the webhook when we receive it. This PR adds a way for us to fetch the order from data stored in the intent's metadata. Internal link to this case: pcJe93-4NE-p2#comment-4929

cc @geektzu

Testing instructions

  1. This should have no impact on payments.
  2. You should notice two changes:
    • Payments in the Stripe Dashboard will now record a "signature" in metadata. This value will contain the order ID followed by a hash.
    • The webhook processing will now use the order ID in this signature to validate and process the webhook.

Screenshot 2024-10-31 at 3 40 18 pm
The new signature stored in payment intent metadata.

Because this changes a core part of the way we process webhook payments, please scrutinize this change to make sure we root out any potential gotchas.


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

Post merge

@geektzu
Copy link

geektzu commented Nov 6, 2024

Hi, team; thank you for looking into this issue. Let us know when there is an ETA so we can inform the merchant for updates.

@wjrosa wjrosa marked this pull request as ready for review November 12, 2024 20:26
@wjrosa wjrosa requested review from a team and Mayisha and removed request for a team November 12, 2024 20:31
Copy link
Contributor

@Mayisha Mayisha 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 🎉

✅ Confirmed from logs that a signature is sent as a metadata during payment intent request. Also the signature is received as a metadata in the webhook event data.
✅ I can see the signature present in the relevant transaction in my Stripe dashboard.

Screenshot 2024-11-13 at 8 02 51 PM

✅ Checkout with regular card.
✅ Checkout with 3DS card.
✅ Checkout with GPay (PRB and ECE)
✅ Checkout with iDeal.
✅ Checkout with SEPA.
✅ Checkout with CashApp (Wallet)
✅ Checkout with Klarna (BNPL)
✅ Checkout with Multibanco (Voucher)

@wjrosa
Copy link
Contributor

wjrosa commented Nov 13, 2024

I will merge this since tests are still failing for some reason unrelated to the test itself (checking). Test results locally:
Screenshot 2024-11-13 at 11 55 12

@wjrosa wjrosa merged commit bf78808 into develop Nov 13, 2024
20 of 35 checks passed
@wjrosa wjrosa deleted the fix/webhook-processing-when-intent-id-is-missing branch November 13, 2024 14:58
@wjrosa
Copy link
Contributor

wjrosa commented Nov 13, 2024

diegocurbelo pushed a commit that referenced this pull request Nov 14, 2024
…ssing (#3567)

* Use metadata stored on the intent to fetch an order for webhook processing

* Tidy comments

* More comment changes

* Comment tweaks

* Add changelog entries

* Add signature to root generate_payment_request() function

* Update unit test to expect signature

* Make sure guest customers are accounted for

* Update tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php

Co-authored-by: Mayisha <[email protected]>

* Update tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php

Co-authored-by: Mayisha <[email protected]>

---------

Co-authored-by: Wesley Rosa <[email protected]>
Co-authored-by: Mayisha <[email protected]>
@geektzu
Copy link

geektzu commented Nov 21, 2024

@wjrosa Believe this change was released with version 8.9.0?

= 8.9.0 - 2024-11-14 =

  • Update - Enhance webhook processing to enable retrieving orders using payment_intent metadata.

I'm double-checking there to see if the webhook was processed for the subscription renewal order. Will the Woo subscription status be set from "On hold" back to "Active"?

@wjrosa
Copy link
Contributor

wjrosa commented Nov 22, 2024

@wjrosa Believe this change was released with version 8.9.0?

= 8.9.0 - 2024-11-14 =

  • Update - Enhance webhook processing to enable retrieving orders using payment_intent metadata.

Yes, released with 8.9.0.

I'm double-checking there to see if the webhook was processed for the subscription renewal order. Will the Woo subscription status be set from "On hold" back to "Active"?

That's the expected behavior, yes. Are you having issues specific with this flow, related to this change?

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.

4 participants