feat(payment, payment-stripe): Add Stripe module provider (#6311)

This commit is contained in:
Oli Juhl
2024-02-26 19:48:15 +01:00
committed by GitHub
parent ac829fc67f
commit ce39b9b66e
49 changed files with 1256 additions and 119 deletions
@@ -0,0 +1,9 @@
import { MiddlewareRoute } from "../../types/middlewares"
export const hooksRoutesMiddlewares: MiddlewareRoute[] = [
{
method: ["POST"],
bodyParser: { preserveRawBody: true },
matcher: "/hooks/payment/:provider",
},
]
@@ -0,0 +1,32 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { PaymentWebhookEvents } from "@medusajs/utils"
import { PaymentModuleOptions } from "@medusajs/types"
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
try {
const { provider } = req.params
const options: PaymentModuleOptions =
req.scope.resolve(ModuleRegistrationName.PAYMENT).options || {}
const event = {
provider,
payload: { data: req.body, rawData: req.rawBody, headers: req.headers },
}
const eventBus = req.scope.resolve("eventBusService")
// we delay the processing of the event to avoid a conflict caused by a race condition
await eventBus.emit(PaymentWebhookEvents.WebhookReceived, event, {
delay: options.webhook_delay || 5000,
attempts: options.webhook_retries || 3,
})
} catch (err) {
res.status(400).send(`Webhook Error: ${err.message}`)
return
}
res.sendStatus(200)
}