chore: rename route from api-v2 to api (#7379)

* chore: rename route from api-v2 to api

* chore: change oas references

* chore: remove v2 ref
This commit is contained in:
Riqwan Thamir
2024-05-21 10:44:02 +02:00
committed by GitHub
parent e72174c4ff
commit 442b0b2038
368 changed files with 43 additions and 46 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(ModuleRegistrationName.EVENT_BUS)
// 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)
}