Webhooks
Using webhooks to track Affirm events.
Affirm uses webhooks to notify your application any time events happen.
Webhook endpoints are not self-serve. Please reach out to Affirm via the support widget.
Affirm creates a checkout event object for each occurrence that is worth notifying you about. Some of these occurrences could be a new checkout from a customer or a confirmed checkout, and each event will have its own status.
When you create a webhook endpoint, it normally listens for specific events, and then takes action whenever those events are being received. Technically, a webhook endpoint is hosted on your server-side code (e.g., in python, node, etc.), which handles any push from third and/or specific parties.
About Affirm's webhooks
Affirm will send an HTTP POST
request to a URL that you provide us with. The provided URL should be a page or endpoint that has been set up to receive requests from our servers.
Merchants cannot add a webhook endpoint or manage events by themselves via Affirm Dashboard. Please reach out to Affirm via the support widget for details.
Affirm policies
Customers must opt-in for the approval decisions to be included. The confirmed event is the only webhook event that is guaranteed to be present for each successful Affirm checkout attempt. All other events (approved/not approved/etc.) will only be present if the customer has opted into the Affirm data sharing policy. Customers are actively prompted to enable data sharing, and they can toggle this setting ("Personalized Services") in their Affirm user profile at any time.
Endpoint requirements
- HTTP/HTTPS
- Receives POST method
- Returns 20x status
- Support TLS 1.2 (self-signed or expired certificates are not accepted)
- Rate dependent on merchant checkout traffic
- Inbound IP is dynamic
- Content-Type: application/x-www-form-urlencoded and application/json
- Accept-Encoding: gzip
Webhook request properties
- POST method
- User-Agent: Affirm-Webhook
- Origin IP is dynamic
Respond to a webhook event
Your endpoint should respond to Affirm with a 2xx status code to communicate that you have successfully received the webhook event notification. Affirm will treat all other response types as a failed delivery, including 3xx status codes. This means that we will treat URL redirections and "Not Modified" responses as failures. Affirm will ignore any other information returned in the request headers or request body.
Webhook requirements
For checkout events, the requests sent from Affirm to your webhook endpoint come with the
content-type
application/x-www-form-urlencoded
and aapplication/x-www-form-urlencoded
version of the data in the body field. Prequal events are sent with thecontent-type
application/json
and aJSON
version of the data in the body field.
Affirm does not currently resend a webhook event if your endpoint did not successfully receive it.
Webhook events
Checkout events
When your customers go through Affirm's checkout flow, you can receive different checkout status events in real-time via your webhook endpoint.
- Enters checkout.
- Receives a credit decision.
- Confirms their loan.
User experience | Affirm event | Webhook event |
---|---|---|
The Affirm checkout flow is opened and the customer is asked to login. | Checkout created | opened |
Creates or signs into an Affirm account. | None | None |
Processing Screen | Approval decision | approved not_approved |
The Affirm checkout flow opened by the user. | None | None |
Clicks confirm and is sent back to merchant site. | Checkout confirmation | confirmed |
Prequal events
When your customers go through Affirm's prequalification flow, you can receive different prequalification status events via your webhook endpoint.
- Receives a credit decision.
- The prequalification expires.
User experience | Affirm event | Webhook event |
---|---|---|
Customer clicks the “See if you qualify” button in the “Learn More” modal. | None | None |
Creates or signs into an Affirm account. | None | None |
Processing Screen | Approval decision | prequal_decision |
Prequalification expires, could occur within or up to 7 days later. | Prequalification Expiration | prequal_expiry |
When to use webhooks
Webhooks are optional but sometimes preferred for behind-the-scenes or asynchronous transactions, such as In-store integration since we are waiting on the customer to complete their checkout to receive the checkout_id
. In APIs like these, Affirm needs to notify your integration about changes to the status of the object so that you can act on them.
Some Affirm requests (e.g., checkout or prequalification) generate events that Affirm catches and these events allow you to share information with other systems as well. You can also use webhooks to automate business tasks:
- Performance metrics (e.g., funnel conversion, etc.).
- Streamline and automate operation processes.
Including a session ID in the webhook response
You can include a session ID in the webhook responses by including the session ID in the checkout object that is sent, or by including a session ID in Affirm.js
.
To include the session ID in Affirm.js
, follow the format included in the example below:
_affirm_config =
{ public_api_key: "YOUR_PUBLIC_KEY",
script: "https://cdn1-sandbox.affirm.com/js/v2/affirm.js",
session_id: "YOUR_VISITOR_SESSION_ID" }
Webhook practice
For additional information about webhooks, check out our Changelog article, "How to use webhooks with Affirm," a step-by-step guide on how to create webhooks.
Updated 9 months ago