Skip to content
OneSay Developers

Security

Merchant Webhooks

Not open yet. Merchant payments and these notices are not running in any environment yet, Production included. This page describes the contract, so that you can prepare your receiver ahead of time.

Not open yet. Merchant payments and these notices are not running in any environment yet, Production included. This page describes the contract, so that you can prepare your receiver ahead of time.

When a customer pays an order, OneSay sends a paid notice to your system: an HTTPS POST to the endpoint you registered, signed with your own signing secret. Each notice follows the open Standard Webhooks specification, so you verify it with an official Standard Webhooks library instead of writing signature code yourself.

What you receive

One request for each paid order:

PartValue
MethodPOST, content-type: application/json
webhook-idThe notice's id. A notice that is sent again keeps its id.
webhook-timestampWhen this attempt was signed, in Unix seconds.
webhook-signatureOne or more v1,<signature> values separated by spaces (two during a secret rotation).
webhook-topicpay.order.paid
BodyThe event as JSON, shown below.
JSON
{
  "order_id": "pyo_01JD0000000000000000000000",
  "merchant_order_ref": "table-12-0042",
  "amount_fen": 12800,
  "currency": "CNY",
  "paid_at": "2026-11-19T12:34:56Z"
}
  • order_id is OneSay's order id; merchant_order_ref is the reference your system gave the order.
  • amount_fen is the amount as an integer in the smallest unit of currency. The channel's currency today is CNY, whose smallest unit is the fen (1/100 yuan): 12800 is 128.00 CNY. Never parse it as a decimal.
  • paid_at is an RFC 3339 time in UTC.
  • The notice carries no payment-provider data and no data about the customer.

Set up your endpoint and your signing secret

  1. Run an HTTPS endpoint on a public host name, for example https://orders.example.com/onesay/paid. Plain HTTP, IP addresses in private ranges and localhost are refused.
  2. Give the URL to the OneSay team. OneSay registers it and gives you your signing secret once. It starts with whsec_.
  3. Store the secret as you store other credentials: in your secret store or an environment variable, never in source control or logs. If you lose it, ask for a rotation (see below); OneSay does not show it again.

Notices for orders that were paid before your endpoint was registered are sent once it is registered, with their own ids.

Verify every request

Verify the signature over the raw request body, exactly as received, before you parse the JSON. The library checks the signature with your secret, comparing signatures in constant time as the official libraries do, and refuses a request whose webhook-timestamp is more than five minutes from your clock. Answer 401 when verification fails, and do nothing else with the request.

JavaScript (Node.js, standardwebhooks 1.3.0):

JavaScript
import express from "express";
import { Webhook } from "standardwebhooks";

const webhook = new Webhook(process.env.ONESAY_WEBHOOK_SECRET);
const app = express();

app.post("/onesay/paid", express.raw({ type: "application/json" }), (req, res) => {
  let event;
  try {
    event = webhook.verify(req.body, req.headers);
  } catch {
    return res.sendStatus(401);
  }
  res.sendStatus(204);
  handlePaidOrder(req.headers["webhook-id"], event);
});

Python (standardwebhooks 1.3.0):

python
import os
from flask import Flask, request
from standardwebhooks.webhooks import Webhook

webhook = Webhook(os.environ["ONESAY_WEBHOOK_SECRET"])
app = Flask(__name__)

@app.post("/onesay/paid")
def paid():
    try:
        event = webhook.verify(request.get_data(), dict(request.headers))
    except Exception:
        return "", 401
    handle_paid_order(request.headers["webhook-id"], event)
    return "", 204

Standard Webhooks also publishes libraries for Go, Java, PHP, Ruby, Rust and other languages; they work the same way.

Answer quickly, and expect retries

  • Answer with any 2xx status within a few seconds. Do slow work after you answer, or in a queue.
  • A notice that gets no 2xx answer (an error status, a timeout or no connection) is sent again later, more than once. A retry has the same webhook-id, a new webhook-timestamp and a new signature.
  • Retries stop after a limited time. If your endpoint is down for longer than that, ask the OneSay team to send the missed notices again; they keep their ids.
  • The same notice can therefore arrive more than once. Process each webhook-id only once: store the ids you have handled, for at least a week, and answer 2xx to a repeat without doing the work again.
  • Notices of different orders can arrive in any order.
  • Before you mark an order paid, check amount_fen and currency against your own order for merchant_order_ref.

Rotate the signing secret

Ask the OneSay team for a rotation when you change your secret on a schedule, or at once if it may have leaked.

  • Planned rotation: you get a new secret, shown once. For the next 24 hours each notice carries two signatures, one for the new secret and one for the old one, so a receiver with either secret accepts it. Switch your configuration to the new secret within those 24 hours; after them only the new secret signs.
  • Leaked secret: you get a new secret, and the old one stops signing at once. Switch to the new secret immediately; until you do, your endpoint refuses the notices, and they are sent again later.

When your endpoint is paused

OneSay can pause delivery to your endpoint, for example while you move it. Notices of orders paid while delivery is paused wait, and are sent with their own ids once delivery resumes. A notice that was still being retried to your endpoint when delivery was paused is not retried again by itself: if your endpoint missed notices around a pause, ask the OneSay team to send them again; they keep their ids.

Test your receiver

You do not need a live notice to test verification. The library can sign a request for your unit tests:

JavaScript
import { Webhook } from "standardwebhooks";

const secret = "whsec_" + Buffer.from("a test secret of 32 bytes length").toString("base64");
const webhook = new Webhook(secret);
const id = "msg_test_1";
const timestamp = new Date();
const body = JSON.stringify({ order_id: "pyo_test", merchant_order_ref: "t-1", amount_fen: 100, currency: "CNY",
  paid_at: timestamp.toISOString() });
const headers = { "webhook-id": id, "webhook-timestamp": String(Math.floor(timestamp.getTime() / 1000)),
  "webhook-signature": webhook.sign(id, timestamp, body) };
webhook.verify(body, headers); // returns the parsed event

Troubleshooting

SymptomCause
Every request fails verificationYour framework parsed or re-serialized the body before you verified it. Verify the raw bytes.
Verification fails with a timestamp errorYour server's clock is wrong; synchronize it with NTP.
Failures right after a rotationYour receiver still uses the old secret after a leaked-secret rotation, or after the 24 hours of a planned one.
The same order arrives twiceA retry. De-duplicate by webhook-id.