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

feat(medusa-payment-stripe): Add delay to Stripe webhook #5838

Merged
merged 13 commits into from
Jan 5, 2024

Conversation

olivermrbl
Copy link
Contributor

@olivermrbl olivermrbl commented Dec 10, 2023

What

  • Migrate Stripe plugin to use API Routes + Subscribers
  • Change the behaviour of Stripe webhook
    Instead of processing webhook events immediately, we fire an event to perform the work in the background. The primary reason for changing the webhook is that the previous implementation led to occasional conflicts due to a race condition between the client's and the webhook's request to complete a cart. Now, we emit an event with a configurable delay (defaults to 2s) to prevent this from happening

This approach was preferred over adding a timeout directly to the webhook execution, as it is generally best practice to respond to a webhook event immediately after receiving it.

Copy link

changeset-bot bot commented Dec 10, 2023

🦋 Changeset detected

Latest commit: 7d99018

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@medusajs/medusa Patch
medusa-payment-stripe Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Visit Preview Jan 5, 2024 0:16am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Jan 5, 2024 0:16am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Jan 5, 2024 0:16am

@olivermrbl olivermrbl force-pushed the feat/stripe-webhook-delay branch from 8e06a32 to 3f99ed5 Compare December 10, 2023 20:26
@olivermrbl olivermrbl force-pushed the feat/stripe-webhook-delay branch from 3f99ed5 to 910c831 Compare December 10, 2023 20:26
@olivermrbl olivermrbl changed the title [wip] feat(medusa-payment-stripe): Add delay to Stripe webhook feat(medusa-payment-stripe): Add delay to Stripe webhook Dec 12, 2023
@olivermrbl olivermrbl added linear and removed linear labels Dec 12, 2023
@olivermrbl olivermrbl marked this pull request as ready for review December 12, 2023 15:36
@olivermrbl olivermrbl requested a review from a team as a code owner December 12, 2023 15:36
@olivermrbl
Copy link
Contributor Author

/snapshot-this

Copy link
Contributor

🚀 A snapshot release has been made for this PR

Test the snapshots by updating your package.json with the newly published versions:

yarn add @medusajs/admin@7.1.9-snapshot-20231212154115
yarn add @medusajs/admin-ui@2.1.10-snapshot-20231212154115
yarn add @medusajs/core-flows@0.0.3-snapshot-20231212154115
yarn add @medusajs/ui@2.2.4-snapshot-20231212154115
yarn add @medusajs/link-modules@0.2.5-snapshot-20231212154115
yarn add @medusajs/medusa@1.19.0-snapshot-20231212154115
yarn add @medusajs/medusa-cli@1.3.22-snapshot-20231212154115
yarn add medusa-payment-klarna@1.4.0-snapshot-20231212154115
yarn add medusa-payment-stripe@6.0.7-snapshot-20231212154115
yarn add medusa-react@9.0.12-snapshot-20231212154115
yarn add @medusajs/modules-sdk@1.12.5-snapshot-20231212154115
yarn add @medusajs/orchestration@0.5.1-snapshot-20231212154115
yarn add @medusajs/pricing@0.1.6-snapshot-20231212154115
yarn add @medusajs/product@0.3.6-snapshot-20231212154115
yarn add @medusajs/types@1.11.9-snapshot-20231212154115
yarn add @medusajs/utils@1.11.2-snapshot-20231212154115

Latest commit: 07107f3

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

Looks very clean, we need to test it :)

@olivermrbl
Copy link
Contributor Author

@adrien2p, have tested this locally on my machine :)

@adrien2p
Copy link
Member

Splendide, you ve used the stripe cli?

@olivermrbl
Copy link
Contributor Author

Used their console + ngrok

@adrien2p
Copy link
Member

Ok works too, eaiser with the cli 😅

@olivermrbl
Copy link
Contributor Author

I see, felt like it was pretty easy with the console. I'll have to try the CLI next time

@adrien2p
Copy link
Member

adrien2p commented Jan 2, 2024

Should we move forward with this one?

@olivermrbl
Copy link
Contributor Author

Yes, let me get it up to speed so we can merge :)

@olivermrbl
Copy link
Contributor Author

@carlos-r-l-rodrigues, would you like to give this a review?

Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues left a comment

Choose a reason for hiding this comment

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

LGTM

@kodiakhq kodiakhq bot merged commit 99a4f94 into develop Jan 5, 2024
15 checks passed
@kodiakhq kodiakhq bot deleted the feat/stripe-webhook-delay branch January 5, 2024 12:37
This was referenced Jan 5, 2024
@piereligio
Copy link

piereligio commented Jan 9, 2024

Hey there, a question: would it be possible/beneficial to update medusa-payment-paypal plugin in the same way? I think it might fix some issues I'm meeting on it, but I am not sure about it. Thanks

@olivermrbl
Copy link
Contributor Author

@piereligio, I'll look into how much effort it would require.

PayPal can be cumbersome to work with directly through their SDKs. Are you aware, that you can use PayPal via Stripe (which is also supported by this plugin)?

@piereligio
Copy link

@piereligio, I'll look into how much effort it would require.

PayPal can be cumbersome to work with directly through their SDKs. Are you aware, that you can use PayPal via Stripe (which is also supported by this plugin)?

Oh, I had no idea, thanks for the info!
I noticed the snapshot mentioned here got rid of all the webhook issues I got from stripe, so it's working very well.

But how can I add more payment methods in stripe? I enabled automatic_payment_methods from medusa-config.js, but nothing changed. Basically in the storefront I only see the credit card option, with the fields for it. For now I enabled Google Pay and Apple Pay (PayPal is pending). Do I need to write my own custom code for storefront?

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

Successfully merging this pull request may close these issues.

4 participants