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

**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.
This commit is contained in:
Oli Juhl
2024-01-05 12:37:53 +00:00
committed by GitHub
parent 37fba9a168
commit 99a4f94db5
16 changed files with 92 additions and 98 deletions
@@ -1,10 +1,9 @@
import { IsEmail, IsNotEmpty } from "class-validator"
import jwt from "jsonwebtoken"
import { EntityManager } from "typeorm"
import { defaultRelations } from "."
import AuthService from "../../../../services/auth"
import CustomerService from "../../../../services/customer"
import { validator } from "../../../../utils/validator"
import { defaultRelations } from "."
/**
* @oas [post] /store/auth