Event Types
List of supported event types and their payloads.
How to parse and Handle the Webhook Event
Parse the event json
import json
# Example JSON string (as received from API/Webhook)
json_str = r'''
{
"object": {
"mode": "test",
"order": {
"amount": 397.16,
"object": "order",
"status": "paid",
"currency": "usd",
"order_id": "ORD_1967143798153777154",
"created_at": "2025-09-14 08:30:02.653",
"product_id": "prod_1967143613700870145",
"tax_amount": 0,
"updated_at": "2025-09-14 08:30:02.653"
},
"object": "checkout",
"product": {
"mode": "test",
"name": "New_Product_6987",
"price": 397.1632,
"object": "product",
"currency": "USD",
"created_at": "2025-09-14 08:29:20",
"is_archive": true,
"product_id": "prod_1967143613700870145",
"updated_at": "2025-09-14 08:29:22",
"description": "New_Description_of_product_1129",
"billing_type": "subscription",
"tax_category": "ebooks",
"tax_inclusive": false
},
"customer": {
"id": "1967143106647265282",
"email": "andrew@gettrust.ai"
},
"metadata": {
"source": "website",
"campaign": "summer_sale",
"order_id": "req_20250914_162923"
},
"payment_id": "ch_1967143798107639810",
"request_id": "c9b1a4c1-f8ac-40dd-8dea-ba20c92744bb",
"success_url": "https://yourapp.com/success"
},
"event_id": "evt_1S7BJuG2wtflaO0u6Vx3DefT",
"created_at": "2025-09-14 08:30:00",
"event_type": "checkout.completed"
}
'''
# Parse JSON string into Python dictionary
data = json.loads(json_str)
# Process top-level event information
event_id = data.get("event_id")
event_type = data.get("event_type")
event_created_at = data.get("created_at")
print(f"Event ID: {event_id}")
print(f"Event Type: {event_type}")
print(f"Event Created At: {event_created_at}")
# Access the main object section
obj = data.get("object", {})
# Handle the order block
order = obj.get("order", {})
print("\n[Order Information]")
print(f"Order ID: {order.get('order_id')}")
print(f"Amount: {order.get('amount')} {order.get('currency').upper()}")
print(f"Status: {order.get('status')}")
print(f"Created At: {order.get('created_at')}")
print(f"Product ID: {order.get('product_id')}")
print(f"Tax Amount: {order.get('tax_amount')}")
# Handle the product block
product = obj.get("product", {})
print("\n[Product Information]")
print(f"Product ID: {product.get('product_id')}")
print(f"Name: {product.get('name')}")
print(f"Price: {product.get('price')} {product.get('currency')}")
print(f"Description: {product.get('description')}")
print(f"Billing Type: {product.get('billing_type')}")
print(f"Tax Category: {product.get('tax_category')}")
print(f"Is Archived: {product.get('is_archive')}")
# Handle the customer block
customer = obj.get("customer", {})
print("\n[Customer Information]")
print(f"Customer ID: {customer.get('id')}")
print(f"Email: {customer.get('email')}")
# Handle the metadata block
metadata = obj.get("metadata", {})
print("\n[Metadata]")
for key, value in metadata.items():
print(f"{key}: {value}")
# Other information
print("\n[Other Information]")
print(f"Mode: {obj.get('mode')}")
print(f"Payment ID: {obj.get('payment_id')}")
print(f"Request ID: {obj.get('request_id')}")
print(f"Success URL: {obj.get('success_url')}")
Deal with metadata
How metadata
Works
metadata
WorksWhen creating a checkout session you can attach your own custom info (e.g. internal order_id, campaign) in
metadata
.When you receive the webhook after payment, that same
metadata
comes back so you can update your system.
1. Create checkout session with metadata
session = checkout.create_session(
...
metadata={
"source": "website",
"campaign": "summer_sale",
"order_id": "req_20250914_162923"
}
)
You pass metadata
here so your payment provider stores custom info.
2. Read metadata in webhook
def handle_webhook(event):
if event.get("event_type") == "checkout.completed":
metadata = event["object"].get("metadata", {})
order_id = metadata.get("order_id")
# Use metadata to update your order in DB
print(f"Order {order_id} paid, campaign: {metadata.get('campaign')}")
You set metadata
when starting checkout → it comes back unchanged in the webhook → you use it to find and update the correct order in your system.
Event List
checkout.completed
The webhook endpoint will received this event, when:
A one-time payment has been successfully processed, and the fund collection has been finalized.
A recurring subscription payment has been successfully processed.
Sample Request Body
{
"object": {
"mode": "test",
"order": {
"amount": 397.16,
"object": "order",
"status": "paid",
"currency": "usd",
"order_id": "ORD_1967143798153777154",
"created_at": "2025-09-14 08:30:02.653",
"product_id": "prod_1967143613700870145",
"tax_amount": 0,
"updated_at": "2025-09-14 08:30:02.653"
},
"object": "checkout",
"product": {
"mode": "test",
"name": "New_Product_6987",
"price": 397.1632,
"object": "product",
"currency": "USD",
"created_at": "2025-09-14 08:29:20",
"is_archive": true,
"product_id": "prod_1967143613700870145",
"updated_at": "2025-09-14 08:29:22",
"description": "New_Description_of_product_1129",
"billing_type": "subscription",
"tax_category": "ebooks",
"tax_inclusive": false
},
"customer": {
"id": "1967143106647265282",
"email": "andrew@gettrust.ai"
},
"metadata": {
"source": "website",
"campaign": "summer_sale",
"order_id": "req_20250914_162923"
},
"payment_id": "ch_1967143798107639810",
"request_id": "c9b1a4c1-f8ac-40dd-8dea-ba20c92744bb",
"success_url": "https://yourapp.com/success"
},
"event_id": "evt_1S7BJuG2wtflaO0u6Vx3DefT",
"created_at": "2025-09-14 08:30:00",
"event_type": "checkout.completed"
}
checkout.failed
The webhook endpoint will received this event, when:
Unsuccessful processing of a one-time payment.
The automatic renew failure for a subscription payment.
A one-time or subscription payment was blocked by Radar.
Sample Request Body
{
"object": {
"mode": "test",
"order": {
"amount": 12210,
"object": "order",
"status": "canceled",
"currency": "usd",
"order_id": "ORD_1966406841447669761",
"created_at": "2025-09-12 15:41:40",
"product_id": "prod_1966379396824723457",
"tax_amount": 0,
"updated_at": "2025-09-12 15:41:40"
},
"object": "checkout",
"product": {
"mode": "test",
"name": "Product name",
"price": 1110.0,
"object": "product",
"currency": "usd",
"created_at": "2025-09-12 13:52:36",
"is_archive": true,
"product_id": "prod_1966379396824723457",
"updated_at": "2025-09-12 13:52:36",
"description": "Product description",
"billing_type": "single_payment",
"tax_category": "saas_services",
"tax_inclusive": false
},
"metadata": {
"test": "111",
"userId": "222",
"orderId": "333"
},
"payment_id": "ch_1966406841422503937",
"request_id": "123456",
"success_url": "https://baodu.com"
},
"event_id": "evt_3S6Rc92YqhGdWPuN09AnjT42",
"created_at": "2025-09-12 15:52:00",
"event_type": "checkout.failed"
}
checkout.cancel
The webhook endpoint will received this event, when:
After an order is initiated and proceeds to third-party payment, if the payment page is closed, the third-party payment system will return a message, triggering a cancel event.
A dispute arises over a payment transaction.
Sample Request Body
{
"id": "19a9e3a8-5ebb-43fc-b94a-251f85f05717",
"mode": "test",
"object": {
"id": "sub_1S6SXS2YqhGdWPuNGTacUBaw",
"object": "subscription",
"status": "canceled",
"product": {
"mode": "test",
"name": "Product name",
"price": 10.0,
"object": "product",
"currency": "usd",
"created_at": "2025-09-12 12:15:22",
"is_archive": true,
"product_id": "prod_1966354925946605570",
"updated_at": "2025-09-12 12:15:22",
"description": "Product description",
"billing_type": "subscription",
"tax_category": "digital_products",
"tax_inclusive": false
},
"metadata": {
"test": "111",
"userId": "222",
"orderId": "333"
},
"customer": {
"id": "1966380027341860866",
"email": "user@gmail.com"
},
"created_at": 1757666462,
"canceled_at": 1757666484
},
"created_at": "2025-09-12 16:41:24.746",
"event_type": "subscription.canceled"
}
subscription.trialing
The webhook endpoint will received this event, when:
When a new trial subscription is created, BagelPay collected the payment method and create a new trial subscription object in your account, this subscription started a trial period.
Sample Request Body
{
"object": {
"mode": "test",
"order": {
"amount": 0,
"object": "order",
"status": "paid",
"currency": "usd",
"order_id": "ORD_1966423704764325891",
"created_at": "2025-09-12 16:48:39.561",
"product_id": "prod_1966423597650190338",
"tax_amount": 0,
"updated_at": "2025-09-12 16:48:39.561"
},
"object": "subscription",
"product": {
"mode": "test",
"name": "Product name",
"price": 10.0,
"object": "product",
"currency": "usd",
"created_at": "2025-09-12 16:48:15",
"is_archive": true,
"product_id": "prod_1966423597650190338",
"updated_at": "2025-09-12 16:48:15",
"description": "Product description",
"billing_type": "subscription",
"tax_category": "ebooks",
"tax_inclusive": false
},
"metadata": {
"test": "111",
"userId": "222",
"orderId": "333"
},
"customer": {
"id": "1966380027341860866",
"email": "user@gmail.com"
},
"payment_id": "ch_1966423704747548674",
"request_id": "6f5c7ee8-3690-4758-a837-21e742aae2f9",
"subscription": {
"id": "sub_1966423704764325890",
"mode": "test",
"last4": "",
"status": "trialing",
"units": 1,
"store_id": "store_1961344502709432322",
"trial_end": "2025-09-19 16:48:37",
"created_at": "2025-09-12 16:48:39",
"product_id": "prod_1966423597650190338",
"updated_at": "2025-09-12 16:48:39",
"trial_start": "2025-09-12 16:48:37",
"product_name": "Product name",
"billing_amount": 10,
"payment_method": "",
"recurring_interval": "monthly"
}
},
"event_id": "ffcc4978-c860-4ba6-b3cd-2ef075ef0185",
"created_at": "2025-09-12 16:48:40.893",
"event_type": "subscription.trialing"
}
subscription.paid
The webhook endpoint will received this event, when:
When a trial period was ends, and the customer completes payment for the initial subscription transaction.
Or when a recurring subscription transaction is successfully paid by the customer at each billing cycle.
Sample Request Body
{
"object": {
"mode": "test",
"order": {
"amount": 10,
"object": "order",
"status": "paid",
"currency": "usd",
"order_id": "ORD_1966423205633761282",
"created_at": "2025-09-12 16:46:39.839",
"product_id": "prod_1966354925946605570",
"tax_amount": 0,
"updated_at": "2025-09-12 16:46:39.839"
},
"object": "subscription",
"product": {
"mode": "test",
"name": "Product name",
"price": 10.0,
"object": "product",
"currency": "usd",
"created_at": "2025-09-12 12:15:22",
"is_archive": true,
"product_id": "prod_1966354925946605570",
"updated_at": "2025-09-12 12:15:22",
"description": "Product description",
"billing_type": "subscription",
"tax_category": "digital_products",
"tax_inclusive": false
},
"metadata": {
"test": "111",
"userId": "222",
"orderId": "333"
},
"customer": {
"id": "1966380027341860866",
"email": "z916722885@gmail.com"
},
"payment_id": "ch_1966423205621178370",
"request_id": "3029f27a-637a-42d7-a914-69aa0681a101",
"subscription": {
"id": "sub_1966423205633761281",
"mode": "test",
"last4": "4242",
"status": "active",
"units": 1,
"store_id": "store_1961344502709432322",
"created_at": "2025-09-12 16:46:39",
"product_id": "prod_1966354925946605570",
"updated_at": "2025-09-12 16:46:39",
"product_name": "Product description",
"billing_amount": 10,
"payment_method": "card",
"billing_period_end": "2025-10-12 16:46:35",
"recurring_interval": "monthly",
"billing_period_start": "2025-09-12 16:46:35"
}
},
"event_id": "18429bf6-e12f-4087-92d6-6db728fdb9ce",
"created_at": "2025-09-12 16:46:41.789",
"event_type": "subscription.paid"
}
subscription.canceled
The webhook endpoint will received this event, when:
A merchant manually clicks the cancel subscription button in the control panel
A customer cancels a subscription via viewOrder, or when a customer unlinks their Visa card, signifying the unbinding and cancellation of the subscription.
Sample Request Body
{
"event_id": "evt_3S6SWZ2YqhGdWPuN1sP6L9aR",
"mode": "test",
"object": {
"id": "sub_1S6SXS2YqhGdWPuNGTacUBaw",
"object": "subscription",
"status": "canceled",
"product": {
"mode": "test",
"name": "Product name",
"price": 10.0,
"object": "product",
"currency": "usd",
"created_at": "2025-09-12 12:15:22",
"is_archive": true,
"product_id": "prod_1966354925946605570",
"updated_at": "2025-09-12 12:15:22",
"description": "Product description",
"billing_type": "subscription",
"tax_category": "digital_products",
"tax_inclusive": false
},
"metadata": {
"test": "111",
"userId": "222",
"orderId": "333"
},
"customer": {
"id": "1966380027341860866",
"email": "user@gmail.com"
},
"created_at": "2025-09-12 12:15:22",
"canceled_at": "2025-09-12 12:15:22"
},
"created_at": "2025-09-12 16:41:24.746",
"event_type": "subscription.canceled"
}
refund.created
The webhook endpoint will received this event, when:
When the merchant clicks the refund button in the control panel and processes a refund of any amount, whether it is a partial or full refund.
Sample Request Body
{
"object": {
"mode": "test",
"object": "subscription",
"status": "canceled",
"product": {
"mode": "test",
"name": "Product Name",
"price": 10.0,
"object": "product",
"currency": "usd",
"created_at": "2025-09-12 12:15:22",
"is_archive": true,
"product_id": "prod_1966354925946605570",
"updated_at": "2025-09-12 12:15:22",
"description": "231321",
"billing_type": "subscription",
"tax_category": "digital_products",
"tax_inclusive": false
},
"metadata": {
"test": "111",
"userId": "222",
"orderId": "333"
},
"customer": {
"id": "1966380027341860866",
"email": "user@example.com"
},
"created_at": "2025-09-12 19:12:28",
"canceled_at": "2025-09-12 19:12:44",
"subscription": {
"mode": "test",
"last4": "4242",
"units": 1,
"status": "canceled",
"store_id": "store_1961344502709432322",
"cancel_at": "2025-09-12 19:12:45",
"created_at": "2025-09-12 19:12:33",
"product_id": "prod_1966354925946605570",
"updated_at": "2025-09-12 19:12:33",
"product_name": "Product Name",
"payment_method": "card",
"subscription_id": "sub_1966459918691274753",
"billing_period_end": "2025-10-12 19:12:28",
"recurring_interval": "monthly",
"next_billing_amount": 10.0,
"billing_period_start": "2025-09-12 19:12:28",
"cancel_at_period_end": false
},
"subscription_id": "sub_1S6Uu02YqhGdWPuNNnQY42yo"
},
"event_id": "902742f8-8b0c-4e0e-a9f7-eda837b45d17",
"created_at": "2025-09-12 19:12:44",
"event_type": "subscription.canceled"
}
Last updated