Payments & top-up
The platform provides WeChat Pay Native (QR code) payments. Funds go to the platform's merchant account. The platform creates the order, receives WeChat Pay's notification, and notifies your server with a signed callback.
Flow
Create an order
Content-Type: application/json, signed.
Request
| Field | Required | Description |
|---|---|---|
appId / timestamp / nonce / sign | Yes | Common signing parameters |
merchantOrderNo | Yes | Your order number, unique per appId; used as the idempotency key |
priceMode | No | custom (default) or product |
subject | Required for custom | Item description, truncated beyond 127 bytes |
totalAmount | Required for custom | Amount in CNY as a string, e.g. "9.90"; must be greater than 0 |
productId | Required for product | Product ID configured in the console |
suk | Required for multi-variant products | Variant (SKU) value; omit for single-variant products |
currency | No | Default CNY |
extra | No | Pass-through string (may hold JSON), returned unchanged in the callback |
Pricing modes
custom: you pass the amount. The platform only checks the format and that it is above zero; your server is responsible for the amount being correct.product: amount and name come from the product configured in the console;subjectandtotalAmountare ignored. A missing, delisted or ambiguous product returns商品不存在、已下架,或suk未指定/不唯一.
Response
{
"code": 200,
"msg": "操作成功",
"type": "SUCCESS",
"data": {
"outTradeNo": "213e33af20cb4a5cb0b2cd754eef7b69",
"merchantOrderNo": "p12-a1b2c3d4e5f6",
"status": "待支付",
"code_url": "weixin://wxpay/bizpayurl?pr=XXXXXXX"
}
}
| Field | Description |
|---|---|
outTradeNo | Platform order number (32 hex characters). Store it as-is |
merchantOrderNo | Your order number |
status | Order status (待支付 = awaiting payment) |
code_url | WeChat Pay QR content; render it as a QR image yourself. Note the snake_case name |
- The QR code is valid for about 3 minutes. After it expires, create a new order with a new
merchantOrderNo. - If the response has no
code_url, treat it as a failed order and contact the platform to check the payment configuration.
Idempotency
Repeating a call with the same appId + merchantOrderNo never creates a second order:
- Unpaid: returns the same
outTradeNo, and the same QR code while it is valid. After the QR code expires, a repeat call may return微信下单失败:…; create a new order with a newmerchantOrderNo. - Paid: returns
{outTradeNo, merchantOrderNo, status: "支付成功", paid: true}withoutcode_url.
Errors
Besides signature errors, possible code=300 messages: merchantOrderNo不能为空, subject不能为空, totalAmount不能为空, totalAmount必须大于0, priceMode=product时productId不能为空, priceMode非法,仅支持custom或product, 微信下单失败:… (WeChat order failed), 微信下单未返回code_url (no code_url returned).
Example
BODY=$(python3 -c '
import json, footoo_sign
print(json.dumps(footoo_sign.signed({
"merchantOrderNo": "p12-a1b2c3d4e5f6",
"subject": "Credits top-up CNY 10",
"totalAmount": "10.00",
"extra": json.dumps({"companyId": 12}),
}, "ak_xxx", "<appSecret>"), ensure_ascii=False))')
curl -s -X POST https://cloud.ifootoo.com/client/open/pay/v1/create \
-H 'Content-Type: application/json' -d "$BODY"
Query an order
Parameters go in the query string; signing works the same way.
| Parameter | Required | Description |
|---|---|---|
appId / timestamp / nonce / sign | Yes | Common signing parameters |
merchantOrderNo | One of the two | Your order number |
outTradeNo | One of the two | Platform order number; takes precedence if both are sent |
Only the parameters above are used for verification. Do not add other query parameters, or you will get 签名校验失败 (signature mismatch). Sign the raw values; URL encoding is only for transport.
Response data: {outTradeNo, merchantOrderNo, status, paid}. status is one of 待支付 (awaiting payment), 支付成功 (paid), 已关闭 (closed), 已退款 (refunded).
If the order is still unpaid on the platform, the platform checks WeChat Pay for the latest status. If it has been paid, the platform updates the order and re-sends the callback. So polling this endpoint always reaches the final result, even if callbacks are lost.
Errors: merchantOrderNo和outTradeNo不能同时为空 (one of the two is required), 订单不存在 (order not found).
QS=$(python3 -c '
import urllib.parse, footoo_sign
print(urllib.parse.urlencode(footoo_sign.signed({"merchantOrderNo": "p12-a1b2c3d4e5f6"}, "ak_xxx", "<appSecret>")))')
curl -s "https://cloud.ifootoo.com/client/open/pay/v1/query?$QS"
Payment callback
When an order is paid, the platform sends a POST with Content-Type: application/json to your configured notifyUrl.
The callback URL is fixed when the order is created. Changing it later does not affect existing orders.
Fields
| Field | Type | Description |
|---|---|---|
appId | string | App ID |
merchantOrderNo | string | Your order number |
outTradeNo | string | Platform order number |
transactionId | string | WeChat Pay transaction ID |
amount | string | Amount paid in CNY, always two decimals, e.g. "10.00" |
status | string | Always SUCCESS |
payTime | string | Payment time, yyyy-MM-dd HH:mm:ss |
extra | string | The extra you sent when creating the order |
timestamp | number | Time the callback was generated (seconds) |
nonce | string | Random string |
sign | string | Signature computed with notifySecret using the signing algorithm |
Empty fields are omitted. Verify using the fields you actually receive.
{
"appId": "ak_xxx",
"merchantOrderNo": "p12-a1b2c3d4e5f6",
"outTradeNo": "213e33af20cb4a5cb0b2cd754eef7b69",
"transactionId": "4200002xxxxxxxxxxxxxxxxxxxxxx",
"amount": "10.00",
"status": "SUCCESS",
"payTime": "2026-10-04 12:00:00",
"extra": "{\"companyId\": 12}",
"timestamp": 1791000000,
"nonce": "9b2f0c1d7e3a4b5c8d6e7f8091a2b3c4",
"sign": "…"
}
What your server must do
- Verify the signature. Parse every field of the body except
sign, compute the signature withnotifySecretand compare in constant time. Keep numbers as their original text when parsing (in Python:json.loads(raw, parse_float=str, parse_int=str)). - Do not check freshness. Retries resend the original body, so
timestampmay be hours old. Rely on order-level idempotency against replays. - Credit once. The same order can be notified several times. De-duplicate by
merchantOrderNo. - Check the amount. Confirm
amountmatches what the order should cost before crediting. - Return 2xx. Any HTTP status from 200 to 299 counts as delivered; the body does not matter. Other statuses, timeouts and connection errors trigger a retry.
Retry schedule
The callback is sent within 30 seconds of payment. After a failure, it is retried after:
| Failures so far | 1 | 2 | 3 | 4 | 5–9 |
|---|---|---|---|---|---|
| Next retry after | 30 s | 2 min | 10 min | 30 min | 1 h |
At most 10 attempts (about 5.7 hours). After that, no more callbacks are sent; reconcile with Query an order.
Verification example
import hmac
import json
from fastapi import FastAPI, Request, Response
from footoo_sign import sign
NOTIFY_SECRET = "<notifySecret>"
app = FastAPI()
@app.post("/api/footoo/notify")
async def footoo_notify(request: Request):
raw = await request.body()
body = json.loads(raw, parse_float=str, parse_int=str)
given = body.get("sign", "")
if not given or not hmac.compare_digest(sign(body, NOTIFY_SECRET), given):
return Response(status_code=401) # non-2xx: the platform will retry
if body.get("fapiaoApplyId"):
handle_invoice(body) # invoice callback, see "E-invoices"
elif body.get("status") == "SUCCESS":
credit_order_once(body["merchantOrderNo"], body["outTradeNo"], body["amount"])
return {"ok": True}
Top-up best practices
- Encode ownership in
merchantOrderNo, e.g.p{companyId}-{uuid12}, to simplify reconciliation. - After showing the QR code, have the frontend poll your own order-status endpoint every ~2 seconds. Your server credits on callback, and falls back to the query endpoint if no callback arrives.
- Use the same idempotent crediting function for both the callback and the query path.
- Refund and close-order endpoints are not available yet. Contact the platform for refunds.