www/apps/resources/app/commerce-modules/payment/webhook-events/page.mdx
export const metadata = {
title: Payment Webhook Events,
}
In this guide, you’ll learn how you can handle payment webhook events in your Medusa application and using the Payment Module.
A payment webhook event is a request sent from a third-party payment provider to your application. It indicates a change in a payment’s status.
This is useful in many cases such as:
So, it's essential to handle webhook events to ensure that your application is aware of updated payment statuses and can take appropriate actions.
The Medusa application has a /hooks/payment/[identifier]_[provider] API route out-of-the-box that allows you to listen to webhook events from third-party payment providers, where:
[identifier] is the identifier static property defined in the payment provider. For example, stripe.[provider] is the ID of the provider. For example, stripe.For example, when integrating basic Stripe payments with the Stripe Module Provider, the webhook listener route is /hooks/payment/stripe_stripe.
You can use this webhook listener when configuring webhook events in your third-party payment provider.
The webhook listener API route executes the getWebhookActionAndData method of the Payment Module's main service. This method delegates handling of incoming webhook events to the relevant payment provider.
<Note title="Tip">Payment providers have a similar getWebhookActionAndData method to process the webhook event. So, if you're implementing a custom payment provider, make sure to implement it to handle webhook events.
</Note>If the getWebhookActionAndData method returns an authorized or captured action, the Medusa application will perform one of the following actions:
View the full flow of the webhook event processing in the processPaymentWorkflow reference.
</Note>authorized action, Medusa will set the associated payment session to authorized.captured action, Medusa will set the associated payment session to captured.