Submitting an order to an external system
Understand how order-specific webhooks are triggered after a Recharge checkout or recurring subscription processes.
Recharge fires order-specific webhooks after a Recharge checkout or recurring subscription order processes, so that orders can be synced with an external system.
Platform:
- Custom
Overview
After Recharge processes a subscription or checkout, the system fires several webhooks that can be used to sync the order to your external system.
There are three webhooks relevant to this flow:
order/created
order/processed
order/updated
Processing checkout and recurring subscription orders
Step 1 - Receive order/created
webhook
order/created
webhookListen for the order/created
webhook after the order processes. When you catch this webhook, evaluate the incoming response, confirming that the response sends the SUCCESS
status. A SUCCESS
status webhook signifies that the Recharge subscription was charged successfully, and the order was created in Recharge.
Step 2 - Create the order in the external system
After confirming the order status, create the order in the external system by consuming the webhook payload and transforming it into the relevant format. Use the system's API to inject the order, and note the external order's properties.
The webhook payload from the order/created
event contains the data your application needs to construct an order for your external system, including billing, product, and customer information.
Step 3 - Update the order in Recharge
Update the Recharge order with properties from your external system order after the order is successfully created in the external system. Ensure the following properties are updated:
external_order_id
: The platform database's unique order ID (ie.92812948
).external_order_number
: - A customer-friendly order ID (ie.101
)
Note:
Depending on the platform being used, only one ID may exist for both properties.
import requests
import json
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"X-Recharge-Access-Token": "<your_api_token>"
}
url = "https://api.rechargeapps.com/orders/<recharge_order_id>"
data = {
"external_order_id": "<platform_order_id>"
"external_order_number": "<platform_order_number>",
}
result = requests.put(url, json.dumps(data), headers=headers)
See Update an order in the Recharge API Reference Guide for more information.
Processing prepaid orders
Prepaid orders require customers to pay for multiple shipments at one time. The workflow for syncing prepaid subscription products to your external system differs from syncing regular subscription orders.
Step 1 - Receive the order/created
webhook or the order/processed
webhook
order/created
webhook or the order/processed
webhookListen for the order/created
or order/processed
webhook after the order processes. When you catch this webhook, evaluate the incoming response, confirming that the response sends the SUCCESS
status. A SUCCESS
status webhook signifies that the Recharge subscription was charged successfully, and the order was created in Recharge.
Each webhook represents a type of prepaid order:
- The
order/created
webhook indicates it is the first prepaid order, and a customer paid for multiple shipments - The
order/processed
webhook indicates it is a subsequent prepaid order, and the customer must receive a prepaid shipment
Step 2 - Create the order in the external system
After confirming the order status, create the order in the external system by consuming the webhook payload and transforming it into the relevant format. Use the system's API to inject the order, and note the external order's properties.
The webhook payloads from the order/created
or order/processed
events contains the data your application needs to construct an order for your external system, including billing, product, and customer information.
3. Update the Recharge order
Update the Recharge order with properties from your external system order after the order is successfully created in the external system. Ensure the following properties are updated:
external_order_id
: The platform database's unique order ID (ie.92812948
).external_order_number
: - A customer-friendly order ID (ie.101
)
Note:
Depending on the platform being used, only one ID may exist for both properties.
import requests
import json
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"X-Recharge-Access-Token": "<your_api_token>"
}
url = "https://api.rechargeapps.com/orders/<recharge_order_id>"
data = {
"external_order_id": "<platform_order_id>"
"external_order_number": "<platform_order_number>",
}
result = requests.put(url, json.dumps(data), headers=headers)
See Update an order in the Recharge API Reference Guide for more information.
4. Update the charge in Recharge
Update the href="https://developer.rechargepayments.com/2021-11/charges" target="_blank">charge object with the external_order_id
.
import requests
import json
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"X-Recharge-Access-Token": "<your_api_token>"
}
url = "https://api.rechargeapps.com/charges/<recharge_charge_id>"
data = {
"external_order_id": "<platform_order_id>"
}
result = requests.put(url, json.dumps(data), headers=headers)
Updated 7 months ago