Files
medusa-store/www/apps/resources/app/commerce-modules/payment/webhook-events/page.mdx
Shahed Nasser 4fe28f5a95 chore: reorganize docs apps (#7228)
* reorganize docs apps

* add README

* fix directory

* add condition for old docs
2024-05-03 17:36:38 +03:00

45 lines
1.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const metadata = {
title: `Webhook Events`,
}
# {metadata.title}
In this document, youll learn how the Payment Module supports listening to webhook events.
## What's a Webhook Event?
A webhook event is sent from a third-party payment provider to your application. It indicates a change in a payments status. This is useful in different cases such as when a payment is being processed asynchronously or when a request is interrupted.
---
## processEvent Method
The Payment Modules main service (`IPaymentModuleService`) provides a `processEvent` method used to handle incoming webhook events from third-party providers. The method delegates the handling to the associated payment provider, which returns the event's details.
If the event's details indicate that the payment should be authorized, then the `authorizePaymentSession` of the main service is executed on the specified payment session.
If the event's details indicate that the payment should be captured, then the `capturePayment` of the main service is executed on the payment of the specified payment session.
![A diagram showcasing the steps of how the processEvent method words](https://res.cloudinary.com/dza7lstvk/image/upload/v1711567415/Medusa%20Resources/payment-webhook_seaocg.jpg)
You can use this method in your webhook listener API routes or endpoints.
<Note>
Medusa V2 implements a webhook listener at the `/hooks/payment/[provider]` API route, where `[provider]` is the ID of the provider (for example, `stripe`). You can use that webhook listener in your third-party payment provider's configurations.
</Note>
For example:
```ts
await paymentModuleService.processEvent({
provider: "stripe",
payload: {
// webhook event data
},
})
```
Learn more about the methods parameters and return types in [this reference](/references/payment/processEvent).