# Create an order
Create an order and its Lightning invoice.
```json
{
"/v1/orders": {
"post": {
"tags": [
"orders"
],
"operationId": "orders.create",
"parameters": [
{
"name": "idempotency-key",
"in": "header",
"schema": {
"type": "string",
"description": "16–128 letters, digits, `_` or `-`. Use a new UUID for each order and reuse it when retrying.",
"examples": [
"5f2b7c1e-9a4d-4e8b-b1c3-7d6e0a9f2c41"
]
},
"required": true
}
],
"security": [
{
"bearer": []
}
],
"responses": {
"201": {
"description": "Order",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Order"
}
}
}
},
"400": {
"description": "The request is malformed.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": [
"INVALID_INPUT",
"BODY_TOO_LARGE"
],
"description": "Machine-readable error code.",
"examples": [
"INVALID_INPUT"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"INVALID_INPUT"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "The request is malformed."
}
}
}
},
"401": {
"description": "The API key is missing, invalid, or deleted.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"UNAUTHORIZED"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"UNAUTHORIZED"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"UNAUTHORIZED"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "The API key is missing, invalid, or deleted."
}
}
}
},
"409": {
"description": "The request conflicts with the current state.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": [
"IDEMPOTENCY_CONFLICT",
"ORDER_IN_PROGRESS",
"MERCHANT_DISABLED"
],
"description": "Machine-readable error code.",
"examples": [
"IDEMPOTENCY_CONFLICT"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"IDEMPOTENCY_CONFLICT"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "The request conflicts with the current state."
}
}
}
},
"422": {
"description": "The pay link does not exist or is not yours.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"SLUG_NOT_FOUND"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"SLUG_NOT_FOUND"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"SLUG_NOT_FOUND"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "The pay link does not exist or is not yours."
}
}
}
},
"429": {
"description": "Too many requests for this API key.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"RATE_LIMITED"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"RATE_LIMITED"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"RATE_LIMITED"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "Too many requests for this API key."
}
}
}
},
"500": {
"description": "Unexpected server error.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"INTERNAL_ERROR"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"INTERNAL_ERROR"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"INTERNAL_ERROR"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "Unexpected server error."
}
}
}
},
"503": {
"description": "Payments are temporarily unavailable. Retry later.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": [
"WALLET_UNAVAILABLE",
"QUOTE_UNAVAILABLE",
"PAYMENTS_PAUSED",
"PAYMENTS_UNAVAILABLE",
"PAYMENTS_NOT_CONFIGURED",
"WALLET_NOT_CONFIGURED"
],
"description": "Machine-readable error code.",
"examples": [
"WALLET_UNAVAILABLE"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"WALLET_UNAVAILABLE"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "Payments are temporarily unavailable. Retry later."
}
}
}
}
},
"description": "Creates an order and its Lightning invoice. Send the customer to `checkoutUrl`, or show `invoice` yourself.",
"summary": "Create an order",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NewOrder"
}
}
},
"required": true
}
}
},
"components": {
"schemas": {
"Order": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Order ID, a UUID.",
"examples": [
"12345678-1234-4234-8234-123456789abc"
]
},
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"reference": {
"type": "string",
"description": "The reference you sent.",
"examples": [
"WC-10234"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"amountSat": {
"type": "integer",
"minimum": 1,
"maximum": 9007199254740,
"description": "Amount in satoshis, quoted when the order was created. The invoice is for exactly this amount.",
"examples": [
15000
]
},
"status": {
"type": "string",
"enum": [
"pending",
"paid",
"expired"
],
"description": "`pending` until the invoice is paid or expires. `paid` is final. An `expired` order can still become `paid` if a late payment arrives.",
"examples": [
"pending"
]
},
"invoice": {
"type": "string",
"description": "BOLT11 Lightning invoice. Show it yourself or send the customer to `checkoutUrl`.",
"examples": [
"lnbc150u1p5..."
]
},
"checkoutUrl": {
"type": "string",
"description": "Hosted checkout page for this order.",
"examples": [
"https://www.cashpayment.co/invoice/12345678-1234-4234-8234-123456789abc"
]
},
"successUrl": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "The success URL you sent, or null.",
"examples": [
"https://shop.example.com/thanks"
]
},
"cancelUrl": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "The cancel URL you sent, or null.",
"examples": [
"https://shop.example.com/cart"
]
},
"createdAt": {
"type": "string",
"description": "When the order was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:00:00.000Z"
]
},
"expiresAt": {
"type": "string",
"description": "When the invoice expires, one hour after creation. ISO 8601, UTC.",
"examples": [
"2026-11-17T13:00:00.000Z"
]
},
"paidAt": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "When the payment arrived, or null. ISO 8601, UTC.",
"examples": [
null
]
}
},
"required": [
"id",
"slug",
"reference",
"amountUsdCents",
"amountSat",
"status",
"invoice",
"checkoutUrl",
"successUrl",
"cancelUrl",
"createdAt",
"expiresAt",
"paidAt"
],
"additionalProperties": false
},
"NewOrder": {
"type": "object",
"properties": {
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"reference": {
"type": "string",
"maxLength": 128,
"description": "Your own order number, up to 128 characters. It is returned as is and does not need to be unique.",
"examples": [
"WC-10234"
]
},
"successUrl": {
"type": "string",
"maxLength": 2048,
"format": "uri",
"pattern": "^https://",
"description": "HTTPS URL the checkout page sends the customer to after payment.",
"examples": [
"https://shop.example.com/thanks"
]
},
"cancelUrl": {
"type": "string",
"maxLength": 2048,
"format": "uri",
"pattern": "^https://",
"description": "HTTPS URL behind the checkout page's “Return to store” link while the order is unpaid.",
"examples": [
"https://shop.example.com/cart"
]
}
},
"required": [
"slug",
"amountUsdCents",
"reference"
],
"additionalProperties": false
},
"WebhookEvent": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Event ID. Retries and manual resends carry the same ID, so use it to skip duplicates.",
"examples": [
"0b6a3c52-7f0e-4c4e-9d43-5a0f1f4c2e9b"
]
},
"type": {
"type": "string",
"enum": [
"order.paid",
"order.expired"
],
"description": "Event type.",
"examples": [
"order.paid"
]
},
"timestamp": {
"type": "string",
"description": "When the event was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:03:42.000Z"
]
},
"data": {
"$ref": "#/components/schemas/WebhookOrder"
}
},
"required": [
"id",
"type",
"timestamp",
"data"
],
"additionalProperties": false
},
"WebhookOrder": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Order ID, a UUID.",
"examples": [
"12345678-1234-4234-8234-123456789abc"
]
},
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"reference": {
"type": "string",
"description": "The reference you sent.",
"examples": [
"WC-10234"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"amountSat": {
"type": "integer",
"minimum": 1,
"maximum": 9007199254740,
"description": "Amount in satoshis, quoted when the order was created. The invoice is for exactly this amount.",
"examples": [
15000
]
},
"status": {
"type": "string",
"enum": [
"pending",
"paid",
"expired"
],
"description": "Order status when the event was created: `paid` for `order.paid`, `expired` for `order.expired`.",
"examples": [
"paid"
]
},
"createdAt": {
"type": "string",
"description": "When the order was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:00:00.000Z"
]
},
"expiresAt": {
"type": "string",
"description": "When the invoice expires. ISO 8601, UTC.",
"examples": [
"2026-11-17T13:00:00.000Z"
]
},
"paidAt": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "When the payment arrived, or null. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:03:41.000Z"
]
}
},
"required": [
"id",
"slug",
"reference",
"amountUsdCents",
"amountSat",
"status",
"createdAt",
"expiresAt",
"paidAt"
],
"additionalProperties": false
}
},
"securitySchemes": {
"bearer": {
"description": "Your secret API key, `cp_live_…`, created in the merchant console.",
"type": "http",
"scheme": "Bearer"
}
}
}
}
```
# Retrieve an order
Read one of your orders and its current status.
```json
{
"/v1/orders/{orderId}": {
"get": {
"tags": [
"orders"
],
"operationId": "orders.order",
"parameters": [
{
"name": "orderId",
"in": "path",
"schema": {
"type": "string",
"description": "Order ID, a UUID.",
"examples": [
"12345678-1234-4234-8234-123456789abc"
]
},
"required": true
}
],
"security": [
{
"bearer": []
}
],
"responses": {
"200": {
"description": "Order",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Order"
}
}
}
},
"400": {
"description": "The request is malformed.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": [
"INVALID_INPUT",
"BODY_TOO_LARGE"
],
"description": "Machine-readable error code.",
"examples": [
"INVALID_INPUT"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"INVALID_INPUT"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "The request is malformed."
}
}
}
},
"401": {
"description": "The API key is missing, invalid, or deleted.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"UNAUTHORIZED"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"UNAUTHORIZED"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"UNAUTHORIZED"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "The API key is missing, invalid, or deleted."
}
}
}
},
"404": {
"description": "No order with this ID belongs to you.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"ORDER_NOT_FOUND"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"ORDER_NOT_FOUND"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"ORDER_NOT_FOUND"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "No order with this ID belongs to you."
}
}
}
},
"409": {
"description": "Your merchant account is disabled.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"MERCHANT_DISABLED"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"MERCHANT_DISABLED"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"MERCHANT_DISABLED"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "Your merchant account is disabled."
}
}
}
},
"429": {
"description": "Too many requests for this API key.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"RATE_LIMITED"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"RATE_LIMITED"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"RATE_LIMITED"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "Too many requests for this API key."
}
}
}
},
"500": {
"description": "Unexpected server error.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"anyOf": [
{
"type": "string",
"enum": [
"INTERNAL_ERROR"
]
}
],
"description": "Machine-readable error code.",
"examples": [
"INTERNAL_ERROR"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"INTERNAL_ERROR"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "Unexpected server error."
}
}
}
},
"503": {
"description": "Payments are temporarily unavailable. Retry later.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": [
"WALLET_UNAVAILABLE",
"QUOTE_UNAVAILABLE",
"PAYMENTS_PAUSED",
"PAYMENTS_UNAVAILABLE",
"PAYMENTS_NOT_CONFIGURED",
"WALLET_NOT_CONFIGURED"
],
"description": "Machine-readable error code.",
"examples": [
"WALLET_UNAVAILABLE"
]
},
"message": {
"type": "string",
"description": "Same as `code`. Do not show it to customers.",
"examples": [
"WALLET_UNAVAILABLE"
]
}
},
"required": [
"code",
"message"
],
"additionalProperties": false,
"description": "Payments are temporarily unavailable. Retry later."
}
}
}
}
},
"description": "Returns one of your orders. An unpaid order is checked against the wallet before it is returned.",
"summary": "Retrieve an order"
}
},
"components": {
"schemas": {
"Order": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Order ID, a UUID.",
"examples": [
"12345678-1234-4234-8234-123456789abc"
]
},
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"reference": {
"type": "string",
"description": "The reference you sent.",
"examples": [
"WC-10234"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"amountSat": {
"type": "integer",
"minimum": 1,
"maximum": 9007199254740,
"description": "Amount in satoshis, quoted when the order was created. The invoice is for exactly this amount.",
"examples": [
15000
]
},
"status": {
"type": "string",
"enum": [
"pending",
"paid",
"expired"
],
"description": "`pending` until the invoice is paid or expires. `paid` is final. An `expired` order can still become `paid` if a late payment arrives.",
"examples": [
"pending"
]
},
"invoice": {
"type": "string",
"description": "BOLT11 Lightning invoice. Show it yourself or send the customer to `checkoutUrl`.",
"examples": [
"lnbc150u1p5..."
]
},
"checkoutUrl": {
"type": "string",
"description": "Hosted checkout page for this order.",
"examples": [
"https://www.cashpayment.co/invoice/12345678-1234-4234-8234-123456789abc"
]
},
"successUrl": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "The success URL you sent, or null.",
"examples": [
"https://shop.example.com/thanks"
]
},
"cancelUrl": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "The cancel URL you sent, or null.",
"examples": [
"https://shop.example.com/cart"
]
},
"createdAt": {
"type": "string",
"description": "When the order was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:00:00.000Z"
]
},
"expiresAt": {
"type": "string",
"description": "When the invoice expires, one hour after creation. ISO 8601, UTC.",
"examples": [
"2026-11-17T13:00:00.000Z"
]
},
"paidAt": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "When the payment arrived, or null. ISO 8601, UTC.",
"examples": [
null
]
}
},
"required": [
"id",
"slug",
"reference",
"amountUsdCents",
"amountSat",
"status",
"invoice",
"checkoutUrl",
"successUrl",
"cancelUrl",
"createdAt",
"expiresAt",
"paidAt"
],
"additionalProperties": false
},
"NewOrder": {
"type": "object",
"properties": {
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"reference": {
"type": "string",
"maxLength": 128,
"description": "Your own order number, up to 128 characters. It is returned as is and does not need to be unique.",
"examples": [
"WC-10234"
]
},
"successUrl": {
"type": "string",
"maxLength": 2048,
"format": "uri",
"pattern": "^https://",
"description": "HTTPS URL the checkout page sends the customer to after payment.",
"examples": [
"https://shop.example.com/thanks"
]
},
"cancelUrl": {
"type": "string",
"maxLength": 2048,
"format": "uri",
"pattern": "^https://",
"description": "HTTPS URL behind the checkout page's “Return to store” link while the order is unpaid.",
"examples": [
"https://shop.example.com/cart"
]
}
},
"required": [
"slug",
"amountUsdCents",
"reference"
],
"additionalProperties": false
},
"WebhookEvent": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Event ID. Retries and manual resends carry the same ID, so use it to skip duplicates.",
"examples": [
"0b6a3c52-7f0e-4c4e-9d43-5a0f1f4c2e9b"
]
},
"type": {
"type": "string",
"enum": [
"order.paid",
"order.expired"
],
"description": "Event type.",
"examples": [
"order.paid"
]
},
"timestamp": {
"type": "string",
"description": "When the event was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:03:42.000Z"
]
},
"data": {
"$ref": "#/components/schemas/WebhookOrder"
}
},
"required": [
"id",
"type",
"timestamp",
"data"
],
"additionalProperties": false
},
"WebhookOrder": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Order ID, a UUID.",
"examples": [
"12345678-1234-4234-8234-123456789abc"
]
},
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"reference": {
"type": "string",
"description": "The reference you sent.",
"examples": [
"WC-10234"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"amountSat": {
"type": "integer",
"minimum": 1,
"maximum": 9007199254740,
"description": "Amount in satoshis, quoted when the order was created. The invoice is for exactly this amount.",
"examples": [
15000
]
},
"status": {
"type": "string",
"enum": [
"pending",
"paid",
"expired"
],
"description": "Order status when the event was created: `paid` for `order.paid`, `expired` for `order.expired`.",
"examples": [
"paid"
]
},
"createdAt": {
"type": "string",
"description": "When the order was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:00:00.000Z"
]
},
"expiresAt": {
"type": "string",
"description": "When the invoice expires. ISO 8601, UTC.",
"examples": [
"2026-11-17T13:00:00.000Z"
]
},
"paidAt": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "When the payment arrived, or null. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:03:41.000Z"
]
}
},
"required": [
"id",
"slug",
"reference",
"amountUsdCents",
"amountSat",
"status",
"createdAt",
"expiresAt",
"paidAt"
],
"additionalProperties": false
}
},
"securitySchemes": {
"bearer": {
"description": "Your secret API key, `cp_live_…`, created in the merchant console.",
"type": "http",
"scheme": "Bearer"
}
}
}
}
```
# Authentication
Authenticate requests with a secret API key.
Every request to `/v1/*` carries an API key in the `Authorization` header:
```http
Authorization: Bearer cp_live_xxx
```
## Managing keys [#managing-keys]
Create keys in the [merchant console](https://merchant.cashpayment.co) under **API 密钥** (API keys). Each merchant can have up to 3 keys, so you can rotate without downtime: create a new key, deploy it, then delete the old one.
- The full key is shown once, when it is created. Afterwards only its first characters are visible.
- Deleting a key takes effect immediately. Requests with it fail with `401 UNAUTHORIZED`.
- The console shows how many requests each key has made and when it was last used.
- Every order records the key that created it.
## Keeping keys secret [#keeping-keys-secret]
An API key can create orders and read every order of your account. Keep it on your server:
- Load it from an environment variable or a secret manager. Don't commit it to source control.
- Never send it to a browser or ship it in a mobile app.
- If a key leaks, delete it in the console and create a new one.
## Errors [#errors]
| Status | Code | Meaning |
| ------ | ------------------- | -------------------------------------------------------- |
| 401 | `UNAUTHORIZED` | The header is missing, or the key is invalid or deleted. |
| 409 | `MERCHANT_DISABLED` | Your merchant account is disabled. Contact us. |
# Checkout & redirects
The hosted checkout page, expiry, and returning to your store.
Each order has a hosted checkout page at `checkoutUrl`. It shows the amount in dollars, a QR code with the Lightning invoice, a copy button, and a button to open Cash App. The customer can pay from any Lightning wallet.
## Expiry [#expiry]
The invoice expires one hour after the order is created (`expiresAt`). The checkout page counts down and shows the order as expired afterwards. To let the customer try again, create a new order with a new idempotency key.
If a payment arrives after expiry, the order still becomes `paid` and you receive `order.paid`. Your store should handle a paid order whose checkout already timed out.
## Returning to your store [#returning-to-your-store]
Both URLs are optional and must be HTTPS.
| URL | When it is used |
| ------------ | ------------------------------------------------------------------------------------------------ |
| `cancelUrl` | Behind the **Return to store** link, shown while the order is unpaid. |
| `successUrl` | After payment the page counts down 3 seconds and opens it. The customer can also click a button. |
Without a URL, the page doesn't show the matching link or redirect. The URLs are opened as you sent them, with no added parameters, so include your own order number if you need it:
```txt
https://shop.example.com/orders/WC-10234/thanks
```
Reaching `successUrl` doesn't prove payment. Confirm with the `order.paid` webhook or [Retrieve an
order](/en/api-reference/retrieve-order) before you fulfil.
## Showing the invoice yourself [#showing-the-invoice-yourself]
Instead of the hosted page you can render `invoice` (a BOLT11 string) as a QR code in your own checkout. You then handle expiry and status display yourself, using webhooks to learn about payment.
# Errors
Error format, codes, and how to handle them.
Errors use standard HTTP status codes and a JSON body:
```json
{ "code": "SLUG_NOT_FOUND", "message": "SLUG_NOT_FOUND" }
```
Branch on `code`, not on the status or `message`. `message` repeats the code and is not meant for customers.
Every response carries an `X-Request-Id` header. Include it when you contact us about a request.
## Codes [#codes]
| Status | Code | What to do |
| ------ | ---------------------- | ------------------------------------------------------------------------------------------------ |
| 400 | `INVALID_INPUT` | Fix the request: invalid JSON, a missing or invalid field or header, or an unknown field. |
| 400 | `BODY_TOO_LARGE` | The body is larger than 8 KiB. |
| 401 | `UNAUTHORIZED` | Check the API key. See [Authentication](/en/concepts/authentication). |
| 404 | `ORDER_NOT_FOUND` | No order with this ID belongs to you. |
| 409 | `IDEMPOTENCY_CONFLICT` | The idempotency key was used for a different order. See [Idempotency](/en/concepts/idempotency). |
| 409 | `ORDER_IN_PROGRESS` | The first request with this key is still running. Retry after `Retry-After` seconds. |
| 409 | `MERCHANT_DISABLED` | Your account or this pay link is disabled. Contact us. |
| 422 | `SLUG_NOT_FOUND` | `slug` is not one of your pay links. |
| 429 | `RATE_LIMITED` | Slow down and retry with backoff. See [Rate limits](/en/concepts/rate-limits). |
| 500 | `INTERNAL_ERROR` | Retry with the same idempotency key. Contact us if it persists. |
| 503 | `PAYMENTS_PAUSED` | Payments are paused for now. Retry later. |
| 503 | `QUOTE_UNAVAILABLE` | The exchange rate is unavailable. Retry later. |
| 503 | `WALLET_UNAVAILABLE` | The invoice could not be created. Retry with the same idempotency key. |
| 503 | `PAYMENTS_UNAVAILABLE` | Temporary failure. Retry with the same idempotency key. |
`503 PAYMENTS_NOT_CONFIGURED` and `503 WALLET_NOT_CONFIGURED` mean the service is misconfigured on our side. Retry later and contact us if it persists.
When order creation fails, no order is saved. You can safely retry with the same idempotency key, or show the customer an error and let them try again.
# Idempotency
Retry order creation safely with the Idempotency-Key header.
A network error can leave you unsure whether an order was created. [Create an order](/en/api-reference/create-order) therefore requires an `Idempotency-Key` header, so a retry returns the same order instead of creating a second one.
```http
Idempotency-Key: 5f2b7c1e-9a4d-4e8b-b1c3-7d6e0a9f2c41
```
## Rules [#rules]
- The key is 16 to 128 characters: letters, digits, `_` and `-`. A UUID works well.
- Generate one key per order attempt, store it with your order, and reuse it for every retry of that request.
- Keys belong to your merchant account and do not expire. Never reuse a key for a different order.
## What a retry returns [#what-a-retry-returns]
| Situation | Response |
| ------------------------------------------------------- | -------------------------------------------------------------------- |
| Same key, same body, order already created | The original order, in its current status |
| Same key, same body, the first request is still running | `409 ORDER_IN_PROGRESS` with `Retry-After: 1`. Retry after 1 second. |
| Same key, different `slug`, amount, `reference` or URLs | `409 IDEMPOTENCY_CONFLICT` |
| Missing or malformed key | `400 INVALID_INPUT` |
A retried request returns the original order even if it has since been paid or has expired. When an order expires and the customer wants to pay again, create a new order with a new key.
## When to retry [#when-to-retry]
Retry with the same key on network errors, timeouts, `429`, `500` and `503`. Use exponential backoff, for example 1, 2, 4 and 8 seconds. Don't retry `400`, `401`, `409 IDEMPOTENCY_CONFLICT` or `422`: the same request fails again.
# Rate limits
How many requests you can make.
| Limit | Value |
| ----------------------- | ------------------------------------------- |
| Requests per API key | 120 per minute |
| New orders per merchant | 5 per second, across all keys and pay links |
Requests over a limit fail with `429 RATE_LIMITED` before they do any work. Retry with exponential backoff and the same idempotency key.
The per-key limit is counted separately in each Cloudflare location, so it is approximate. Don't build against the exact number.
## Avoid polling [#avoid-polling]
Don't poll [Retrieve an order](/en/api-reference/retrieve-order) to wait for payments. Use [webhooks](/en/webhooks), and call the API only when you need the current state, for example when a customer returns to your store or a webhook is late.
# Introduction
Accept Bitcoin Lightning payments on your store with the CashPayment API.
The CashPayment API lets your store create a payment for each checkout and learn when it is paid. Customers pay a Lightning invoice in US dollars, from any Lightning wallet or Cash App.
## How it works [#how-it-works]
Your server [creates an order](/en/api-reference/create-order) with the amount and your own order number.
You send the customer to the order's `checkoutUrl`. The hosted checkout page shows a QR code and the invoice.
When the payment arrives, CashPayment sends an [`order.paid` webhook](/en/webhooks/events) to your server, and the checkout page returns the customer to your store.
## What you need [#what-you-need]
- A CashPayment merchant account and at least one pay link. Contact us if you don't have one.
- An API key, created in the [merchant console](https://merchant.cashpayment.co).
- An HTTPS endpoint on your server to receive webhooks.
## Base URL [#base-url]
All requests go to:
```txt
https://api.cashpayment.co
```
The OpenAPI 3.1 definition is at [`/openapi.json`](https://docs.cashpayment.co/openapi.json), and an AI-friendly version of these docs at [`/llms-full.txt`](https://docs.cashpayment.co/llms-full.txt).
Requests and responses are JSON. Amounts are integers: US cents (`amountUsdCents`) and satoshis (`amountSat`). Times are ISO 8601 strings in UTC.
# Quickstart
Create an order, take a payment, and receive the webhook.
## 1. Create an API key [#1-create-an-api-key]
In the [merchant console](https://merchant.cashpayment.co), open **API 密钥** (API keys) and create a key. The full key, starting with `cp_live_`, is shown only once. Store it on your server, for example in an environment variable. Never put it in browser or mobile app code.
```bash
export CASHPAYMENT_API_KEY=cp_live_xxx
```
## 2. Add a webhook endpoint [#2-add-a-webhook-endpoint]
Open **Webhook** in the merchant console, add your HTTPS endpoint, and subscribe to `order.paid` and `order.expired`. Copy the signing secret (`whsec_…`); you need it to [verify signatures](/en/webhooks/signatures).
Use **发送测试事件** (Send test event) to check that your endpoint receives a `webhook.test` event.
## 3. Create an order [#3-create-an-order]
Call [Create an order](/en/api-reference/create-order) when the customer checks out. Use a new idempotency key for each order, and reuse it if you retry the same request.
```bash
curl -X POST https://api.cashpayment.co/v1/orders \
-H "Authorization: Bearer $CASHPAYMENT_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"slug": "onne",
"amountUsdCents": 1500,
"reference": "WC-10234",
"successUrl": "https://shop.example.com/thanks",
"cancelUrl": "https://shop.example.com/cart"
}'
```
```js
const response = await fetch("https://api.cashpayment.co/v1/orders", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CASHPAYMENT_API_KEY}`,
"Idempotency-Key": crypto.randomUUID(),
"Content-Type": "application/json",
},
body: JSON.stringify({
slug: "onne",
amountUsdCents: 1500,
reference: "WC-10234",
successUrl: "https://shop.example.com/thanks",
cancelUrl: "https://shop.example.com/cart",
}),
});
const order = await response.json();
if (!response.ok) throw new Error(order.code);
console.log(order.checkoutUrl);
```
```go
body, _ := json.Marshal(map[string]any{
"slug": "onne",
"amountUsdCents": 1500,
"reference": "WC-10234",
"successUrl": "https://shop.example.com/thanks",
"cancelUrl": "https://shop.example.com/cart",
})
req, _ := http.NewRequest("POST", "https://api.cashpayment.co/v1/orders", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("CASHPAYMENT_API_KEY"))
req.Header.Set("Idempotency-Key", uuid.NewString())
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
var order struct {
ID string `json:"id"`
CheckoutURL string `json:"checkoutUrl"`
Code string `json:"code"`
}
json.NewDecoder(res.Body).Decode(&order)
if res.StatusCode != http.StatusCreated {
return fmt.Errorf("cashpayment: %s", order.Code)
}
fmt.Println(order.CheckoutURL)
```
```python
import os
import uuid
import requests
response = requests.post(
"https://api.cashpayment.co/v1/orders",
headers={
"Authorization": f"Bearer {os.environ['CASHPAYMENT_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"slug": "onne",
"amountUsdCents": 1500,
"reference": "WC-10234",
"successUrl": "https://shop.example.com/thanks",
"cancelUrl": "https://shop.example.com/cart",
},
timeout=30,
)
order = response.json()
if response.status_code != 201:
raise RuntimeError(order["code"])
print(order["checkoutUrl"])
```
`slug` is one of your pay links; the order is booked under it. The response is the new [order](/en/api-reference/create-order) with `status: "pending"`.
## 4. Send the customer to checkout [#4-send-the-customer-to-checkout]
Redirect the customer to `checkoutUrl`. The checkout page shows the amount, a QR code and the invoice, and counts down to `expiresAt`, one hour after creation.
After payment the page returns the customer to `successUrl`. While the order is unpaid, a **Return to store** link leads to `cancelUrl`. See [Checkout & redirects](/en/concepts/checkout).
## 5. Fulfil on the webhook [#5-fulfil-on-the-webhook]
When the invoice is paid, your endpoint receives `order.paid`:
```json
{
"id": "0b6a3c52-7f0e-4c4e-9d43-5a0f1f4c2e9b",
"type": "order.paid",
"timestamp": "2026-11-17T12:03:42.000Z",
"data": {
"id": "12345678-1234-4234-8234-123456789abc",
"reference": "WC-10234",
"status": "paid",
"amountUsdCents": 1500,
"amountSat": 15000,
"paidAt": "2026-11-17T12:03:41.000Z"
}
}
```
[Verify the signature](/en/webhooks/signatures), find your order by `data.reference` or `data.id`, mark it paid, and respond with any 2xx status. The payload above is shortened; see [Payload](/en/webhooks/payload) for every field.
Fulfil orders from the webhook or from [Retrieve an order](/en/api-reference/retrieve-order), not
from the customer reaching `successUrl`. Anyone can open that URL.
# Event types
The events CashPayment sends.
| Type | Sent when | `data.status` |
| --------------- | ------------------------------------------------------------------------------ | ------------- |
| `order.paid` | The invoice is paid. Also sent when a payment arrives after the order expired. | `paid` |
| `order.expired` | An unpaid order passes `expiresAt`. | `expired` |
| `webhook.test` | You click **发送测试事件** (Send test event) in the merchant console. | — |
## `order.paid` [#orderpaid]
Fulfil the order. Each order sends `order.paid` at most once.
An order can receive `order.expired` and later `order.paid`, when the customer pays just before the invoice expires and the payment settles afterwards. Treat `order.paid` as final.
## `order.expired` [#orderexpired]
Release stock or mark the checkout abandoned. It is sent within about a minute after `expiresAt`, and only for orders that expire while your endpoint is enabled.
## `webhook.test` [#webhooktest]
Sent only when you ask for it, whatever events the endpoint subscribes to. `data` is an empty object:
```json
{
"id": "evt_test_9b2c1d0e4f5a4b6c8d7e0f1a2b3c4d5e",
"type": "webhook.test",
"timestamp": "2026-11-17T12:00:00.000Z",
"data": {}
}
```
Respond with a 2xx status. Ignore event types you don't handle, so new types never break your endpoint.
# Overview
Get notified when orders are paid or expire.
Webhooks tell your server when something happens to an order created through the API. CashPayment sends an HTTPS `POST` with a JSON body to your endpoint for each event.
Delivery, signing and retries are handled by [Svix](https://www.svix.com). Requests follow the [Standard Webhooks](https://www.standardwebhooks.com) format, so you can verify them with the official Svix libraries.
## Set up an endpoint [#set-up-an-endpoint]
In the [merchant console](https://merchant.cashpayment.co), open **Webhook** and add an endpoint:
- **URL**: an HTTPS URL on your server, reachable from the internet.
- **Events**: `order.paid`, `order.expired`, or both. See [Event types](/en/webhooks/events).
Each merchant has one endpoint. On the endpoint's page you can:
- reveal and copy the signing secret, or rotate it;
- send a test event;
- disable, edit or delete the endpoint;
- see every event sent, with its attempts and your responses, and resend any of them.
## Handle an event [#handle-an-event]
Read the raw request body and [verify the signature](/en/webhooks/signatures). Reject the request if verification fails.
Skip events you have already processed, using the event `id`. The same event can arrive more than once.
Update your order, then respond with any 2xx status within 30 seconds. Do slow work, such as sending emails, after responding.
Only orders created through the API send webhooks. Payments made on your pay-link pages don't.
# Payload
The request CashPayment sends to your endpoint.
```json
{
"webhooks": {
"order.paid": {
"post": {
"operationId": "webhooks.order.paid",
"summary": "Order paid",
"description": "Sent when an API order is paid, including a payment that arrives after the order expired.",
"parameters": [
{
"name": "svix-id",
"in": "header",
"required": true,
"description": "Message ID. Stays the same when a message is retried.",
"schema": {
"type": "string"
},
"example": "msg_2pLqV7sM1hYk3fNb0aXcRw9dT4e"
},
{
"name": "svix-timestamp",
"in": "header",
"required": true,
"description": "Unix timestamp in seconds when the message was signed.",
"schema": {
"type": "string"
},
"example": "1763380982"
},
{
"name": "svix-signature",
"in": "header",
"required": true,
"description": "Space-separated list of signatures, each `v1,` followed by a Base64 HMAC-SHA256.",
"schema": {
"type": "string"
},
"example": "v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE="
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WebhookEvent"
},
"example": {
"id": "0b6a3c52-7f0e-4c4e-9d43-5a0f1f4c2e9b",
"type": "order.paid",
"timestamp": "2026-11-17T12:03:42.000Z",
"data": {
"id": "12345678-1234-4234-8234-123456789abc",
"slug": "onne",
"reference": "WC-10234",
"amountUsdCents": 1500,
"amountSat": 15000,
"status": "paid",
"createdAt": "2026-11-17T12:00:00.000Z",
"expiresAt": "2026-11-17T13:00:00.000Z",
"paidAt": "2026-11-17T12:03:41.000Z"
}
}
}
}
},
"responses": {
"200": {
"description": "Return any 2xx status within 30 seconds. Any other result is retried."
}
}
}
},
"order.expired": {
"post": {
"operationId": "webhooks.order.expired",
"summary": "Order expired",
"description": "Sent when an unpaid API order passes `expiresAt`.",
"parameters": [
{
"name": "svix-id",
"in": "header",
"required": true,
"description": "Message ID. Stays the same when a message is retried.",
"schema": {
"type": "string"
},
"example": "msg_2pLqV7sM1hYk3fNb0aXcRw9dT4e"
},
{
"name": "svix-timestamp",
"in": "header",
"required": true,
"description": "Unix timestamp in seconds when the message was signed.",
"schema": {
"type": "string"
},
"example": "1763380982"
},
{
"name": "svix-signature",
"in": "header",
"required": true,
"description": "Space-separated list of signatures, each `v1,` followed by a Base64 HMAC-SHA256.",
"schema": {
"type": "string"
},
"example": "v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE="
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WebhookEvent"
},
"example": {
"id": "0b6a3c52-7f0e-4c4e-9d43-5a0f1f4c2e9b",
"type": "order.expired",
"timestamp": "2026-11-17T13:00:31.000Z",
"data": {
"id": "12345678-1234-4234-8234-123456789abc",
"slug": "onne",
"reference": "WC-10234",
"amountUsdCents": 1500,
"amountSat": 15000,
"status": "expired",
"createdAt": "2026-11-17T12:00:00.000Z",
"expiresAt": "2026-11-17T13:00:00.000Z",
"paidAt": null
}
}
}
}
},
"responses": {
"200": {
"description": "Return any 2xx status within 30 seconds. Any other result is retried."
}
}
}
}
},
"components": {
"schemas": {
"Order": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Order ID, a UUID.",
"examples": [
"12345678-1234-4234-8234-123456789abc"
]
},
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"reference": {
"type": "string",
"description": "The reference you sent.",
"examples": [
"WC-10234"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"amountSat": {
"type": "integer",
"minimum": 1,
"maximum": 9007199254740,
"description": "Amount in satoshis, quoted when the order was created. The invoice is for exactly this amount.",
"examples": [
15000
]
},
"status": {
"type": "string",
"enum": [
"pending",
"paid",
"expired"
],
"description": "`pending` until the invoice is paid or expires. `paid` is final. An `expired` order can still become `paid` if a late payment arrives.",
"examples": [
"pending"
]
},
"invoice": {
"type": "string",
"description": "BOLT11 Lightning invoice. Show it yourself or send the customer to `checkoutUrl`.",
"examples": [
"lnbc150u1p5..."
]
},
"checkoutUrl": {
"type": "string",
"description": "Hosted checkout page for this order.",
"examples": [
"https://www.cashpayment.co/invoice/12345678-1234-4234-8234-123456789abc"
]
},
"successUrl": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "The success URL you sent, or null.",
"examples": [
"https://shop.example.com/thanks"
]
},
"cancelUrl": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "The cancel URL you sent, or null.",
"examples": [
"https://shop.example.com/cart"
]
},
"createdAt": {
"type": "string",
"description": "When the order was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:00:00.000Z"
]
},
"expiresAt": {
"type": "string",
"description": "When the invoice expires, one hour after creation. ISO 8601, UTC.",
"examples": [
"2026-11-17T13:00:00.000Z"
]
},
"paidAt": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "When the payment arrived, or null. ISO 8601, UTC.",
"examples": [
null
]
}
},
"required": [
"id",
"slug",
"reference",
"amountUsdCents",
"amountSat",
"status",
"invoice",
"checkoutUrl",
"successUrl",
"cancelUrl",
"createdAt",
"expiresAt",
"paidAt"
],
"additionalProperties": false
},
"NewOrder": {
"type": "object",
"properties": {
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"reference": {
"type": "string",
"maxLength": 128,
"description": "Your own order number, up to 128 characters. It is returned as is and does not need to be unique.",
"examples": [
"WC-10234"
]
},
"successUrl": {
"type": "string",
"maxLength": 2048,
"format": "uri",
"pattern": "^https://",
"description": "HTTPS URL the checkout page sends the customer to after payment.",
"examples": [
"https://shop.example.com/thanks"
]
},
"cancelUrl": {
"type": "string",
"maxLength": 2048,
"format": "uri",
"pattern": "^https://",
"description": "HTTPS URL behind the checkout page's “Return to store” link while the order is unpaid.",
"examples": [
"https://shop.example.com/cart"
]
}
},
"required": [
"slug",
"amountUsdCents",
"reference"
],
"additionalProperties": false
},
"WebhookEvent": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Event ID. Retries and manual resends carry the same ID, so use it to skip duplicates.",
"examples": [
"0b6a3c52-7f0e-4c4e-9d43-5a0f1f4c2e9b"
]
},
"type": {
"type": "string",
"enum": [
"order.paid",
"order.expired"
],
"description": "Event type.",
"examples": [
"order.paid"
]
},
"timestamp": {
"type": "string",
"description": "When the event was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:03:42.000Z"
]
},
"data": {
"$ref": "#/components/schemas/WebhookOrder"
}
},
"required": [
"id",
"type",
"timestamp",
"data"
],
"additionalProperties": false
},
"WebhookOrder": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Order ID, a UUID.",
"examples": [
"12345678-1234-4234-8234-123456789abc"
]
},
"slug": {
"type": "string",
"description": "Pay link the order belongs to. It must be one of your pay links.",
"examples": [
"onne"
]
},
"reference": {
"type": "string",
"description": "The reference you sent.",
"examples": [
"WC-10234"
]
},
"amountUsdCents": {
"type": "integer",
"minimum": 100,
"maximum": 1000000,
"description": "Amount in US cents, from 100 ($1.00) to 1000000 ($10,000.00).",
"examples": [
1500
]
},
"amountSat": {
"type": "integer",
"minimum": 1,
"maximum": 9007199254740,
"description": "Amount in satoshis, quoted when the order was created. The invoice is for exactly this amount.",
"examples": [
15000
]
},
"status": {
"type": "string",
"enum": [
"pending",
"paid",
"expired"
],
"description": "Order status when the event was created: `paid` for `order.paid`, `expired` for `order.expired`.",
"examples": [
"paid"
]
},
"createdAt": {
"type": "string",
"description": "When the order was created. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:00:00.000Z"
]
},
"expiresAt": {
"type": "string",
"description": "When the invoice expires. ISO 8601, UTC.",
"examples": [
"2026-11-17T13:00:00.000Z"
]
},
"paidAt": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "When the payment arrived, or null. ISO 8601, UTC.",
"examples": [
"2026-11-17T12:03:41.000Z"
]
}
},
"required": [
"id",
"slug",
"reference",
"amountUsdCents",
"amountSat",
"status",
"createdAt",
"expiresAt",
"paidAt"
],
"additionalProperties": false
}
},
"securitySchemes": {
"bearer": {
"description": "Your secret API key, `cp_live_…`, created in the merchant console.",
"type": "http",
"scheme": "Bearer"
}
}
}
}
```
# Retries & replay
What happens when your endpoint fails, and how to resend events.
A delivery succeeds when your endpoint responds with a 2xx status within 30 seconds. Any other status, a redirect, a timeout or a connection error is a failure.
## Retry schedule [#retry-schedule]
Failed deliveries are retried automatically. Each delay starts after the previous attempt fails:
| Attempt | Delay |
| ------- | ----------- |
| 1 | Immediately |
| 2 | 5 seconds |
| 3 | 5 minutes |
| 4 | 30 minutes |
| 5 | 2 hours |
| 6 | 5 hours |
| 7 | 10 hours |
| 8 | 10 hours |
After the last attempt fails, the event is marked failed. Every attempt keeps the same event `id` and `svix-id`.
## Order and duplicates [#order-and-duplicates]
Events can arrive out of order and more than once. For example, a retried `order.expired` can arrive after `order.paid` for the same order. Make your handler:
- **idempotent**: record each event `id` you have processed and skip repeats;
- **order-independent**: never move an order from paid back to unpaid because of `order.expired`.
When in doubt, read the current state with [Retrieve an order](/en/api-reference/retrieve-order).
## Resending events [#resending-events]
The endpoint's page in the merchant console lists every event with its attempts, response status and response body. Select an event and click **重新发送** (Resend) to deliver it again, for example after fixing a bug. A resent event keeps its `id`.
## Disabled endpoints [#disabled-endpoints]
While an endpoint is disabled, new events for it are not created and are not sent later. When you enable it again, you only receive events from that moment on. Use [Retrieve an order](/en/api-reference/retrieve-order) to catch up on orders that changed in between.
# Verifying signatures
Check that a webhook came from CashPayment and was not changed.
Every webhook is signed with your endpoint's signing secret, so you can reject forged or modified requests. Each request carries three headers:
| Header | Content |
| ---------------- | ------------------------------------------------- |
| `svix-id` | Message ID. The same on every retry of a message. |
| `svix-timestamp` | Unix time in seconds when the message was signed. |
| `svix-signature` | One or more signatures, separated by spaces. |
Get the signing secret (`whsec_…`) from the endpoint's page in the merchant console. Keep it secret, like an API key.
Verify the raw request body exactly as received. If your framework parses JSON and you serialize
it again, the bytes change and verification fails.
## With the Svix libraries [#with-the-svix-libraries]
The official Svix libraries check the signature and reject timestamps more than 5 minutes off.
```bash
npm install svix
```
```js
import express from "express";
import { Webhook } from "svix";
const webhook = new Webhook(process.env.CASHPAYMENT_WEBHOOK_SECRET);
const app = express();
app.post("/webhooks/cashpayment", express.raw({ type: "application/json" }), (req, res) => {
let event;
try {
event = webhook.verify(req.body, {
"svix-id": req.header("svix-id"),
"svix-timestamp": req.header("svix-timestamp"),
"svix-signature": req.header("svix-signature"),
});
} catch {
return res.status(400).end();
}
if (event.type === "order.paid") {
markPaid(event.data.reference);
}
res.status(204).end();
});
```
```bash
go get github.com/svix/svix-webhooks/go
```
```go
import (
"encoding/json"
"io"
"net/http"
"os"
svix "github.com/svix/svix-webhooks/go"
)
func handleWebhook(w http.ResponseWriter, r *http.Request) {
wh, err := svix.NewWebhook(os.Getenv("CASHPAYMENT_WEBHOOK_SECRET"))
if err != nil {
http.Error(w, "server error", http.StatusInternalServerError)
return
}
payload, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
if err := wh.Verify(payload, r.Header); err != nil {
http.Error(w, "invalid signature", http.StatusBadRequest)
return
}
var event struct {
ID string `json:"id"`
Type string `json:"type"`
Data struct {
Reference string `json:"reference"`
} `json:"data"`
}
json.Unmarshal(payload, &event)
if event.Type == "order.paid" {
markPaid(event.Data.Reference)
}
w.WriteHeader(http.StatusNoContent)
}
```
```bash
pip install svix
```
```python
import os
from flask import Flask, request
from svix.webhooks import Webhook, WebhookVerificationError
app = Flask(__name__)
webhook = Webhook(os.environ["CASHPAYMENT_WEBHOOK_SECRET"])
@app.post("/webhooks/cashpayment")
def cashpayment_webhook():
try:
event = webhook.verify(request.get_data(), request.headers)
except WebhookVerificationError:
return "", 400
if event["type"] == "order.paid":
mark_paid(event["data"]["reference"])
return "", 204
```
## Verifying manually [#verifying-manually]
If you can't use a library, follow the [Standard Webhooks](https://www.standardwebhooks.com) algorithm:
Build the signed content: `svix-id`, `svix-timestamp` and the raw body, joined with dots.
```txt
msg_2pLqV7sM1hYk3fNb0aXcRw9dT4e.1763380982.{"id":"0b6a3c52-…","type":"order.paid",…}
```
Take the signing secret without its `whsec_` prefix and Base64-decode it. Use the bytes as the key.
Compute HMAC-SHA256 of the signed content with that key and Base64-encode the result.
`svix-signature` holds space-separated entries such as `v1,g0hM9S…`. Remove the `v1,` prefix from each and compare it to your signature in constant time. One match is enough.
Reject the request if `svix-timestamp` is more than 5 minutes away from your current time, to prevent replay attacks.
```js
import { createHmac, timingSafeEqual } from "node:crypto";
export function verify(secret, headers, rawBody) {
const id = headers["svix-id"];
const timestamp = headers["svix-timestamp"];
const signatures = headers["svix-signature"];
if (!id || !timestamp || !signatures) return false;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${rawBody}`).digest();
return signatures.split(" ").some((entry) => {
const [version, signature] = entry.split(",");
if (version !== "v1" || !signature) return false;
const received = Buffer.from(signature, "base64");
return received.length === expected.length && timingSafeEqual(received, expected);
});
}
```
```go
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"math"
"net/http"
"strconv"
"strings"
"time"
)
func verify(secret string, header http.Header, rawBody []byte) bool {
id := header.Get("svix-id")
timestamp := header.Get("svix-timestamp")
signatures := header.Get("svix-signature")
seconds, err := strconv.ParseInt(timestamp, 10, 64)
if id == "" || signatures == "" || err != nil {
return false
}
if math.Abs(float64(time.Now().Unix()-seconds)) > 300 {
return false
}
key, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(secret, "whsec_"))
if err != nil {
return false
}
mac := hmac.New(sha256.New, key)
mac.Write([]byte(id + "." + timestamp + "."))
mac.Write(rawBody)
expected := mac.Sum(nil)
for _, entry := range strings.Split(signatures, " ") {
version, signature, found := strings.Cut(entry, ",")
if !found || version != "v1" {
continue
}
received, err := base64.StdEncoding.DecodeString(signature)
if err == nil && hmac.Equal(received, expected) {
return true
}
}
return false
}
```
```python
import base64
import hashlib
import hmac
import time
def verify(secret: str, headers, raw_body: bytes) -> bool:
msg_id = headers.get("svix-id")
timestamp = headers.get("svix-timestamp")
signatures = headers.get("svix-signature")
if not msg_id or not timestamp or not signatures:
return False
if abs(time.time() - int(timestamp)) > 300:
return False
key = base64.b64decode(secret.removeprefix("whsec_"))
signed = f"{msg_id}.{timestamp}.".encode() + raw_body
expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
for entry in signatures.split(" "):
version, _, signature = entry.partition(",")
if version == "v1" and hmac.compare_digest(signature, expected):
return True
return False
```
## Rotating the secret [#rotating-the-secret]
Rotate the secret from the endpoint's menu in the merchant console. For the next 24 hours, each message is signed with both the old and the new secret, so `svix-signature` carries two entries. Switch your server to the new secret within that window; after it, only the new secret works.