Onerway
API Reference

Webhook description

Understand Embedded Finance webhook headers, payload structure, acknowledgement, and HMAC-SHA256 signature verification.

Read these common rules before handling Embedded Finance webhooks. Each event has its own data fields and example payload; see, for example, Deposit notification.

Request headers

HeaderTypeRequiredDescription
Content-TypeStringYesFixed to application/json;charset=UTF-8.
x-timestampStringYesUnix timestamp in seconds.
x-signatureStringYesGenerate the HMAC-SHA256 signature from webhook_secret and x-timestamp + "." + raw_body. See Signature and verification.

Payload structure

FieldDescription
request_idUnique notification ID. Use it to deduplicate deliveries.
event_typeEvent type identifier. See the individual webhook page for its fixed value.
created_atNotification creation time in ISO 8601 format.
versionWebhook payload version.
dataEvent-specific business data. Read the corresponding webhook page for its fields and handling rules.

Merchant response requirements

After accepting a notification, the merchant callback must return HTTP 200 with a JSON response. Onerway uses this response to decide whether the notification was received successfully.

FieldTypeDescription
respCodeStringReturn 20000 to confirm receipt.
respMsgStringResponse message.

If the response code is not 20000, Onerway retries.

Signature and verification

Onerway signs Embedded Finance webhook notifications with HMAC-SHA256. You must verify the signature before processing an event.

Generate and verify the signature as follows:

  1. Read x-timestamp and x-signature from the request headers.
  2. Read the raw request body without parsing or re-serializing it.
  3. Concatenate x-timestamp, a period (.), and raw_body to build the signed content:
x-timestamp + "." + raw_body
  1. Use the UTF-8 bytes of webhook_secret directly as the HMAC key. Do not Base64-decode webhook_secret.
  2. Apply HMAC-SHA256 to the signed content and encode the result as a lowercase hexadecimal string.
  3. To verify the notification, calculate the signature using the same rules and compare it securely with x-signature, ignoring hexadecimal letter case.
Calculate the signature from the raw request body exactly as received. Parsing and re-serializing the JSON can change whitespace, field order, or escape sequences and cause verification to fail.
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public final class RHSecureUtil {
    private RHSecureUtil() {
    }

    public static String signHmacSHA256(String webhookSecret, String content) throws Exception {
        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(webhookSecret.getBytes(), "HmacSHA256"));
        byte[] result = mac.doFinal(content.getBytes());
        return HexUtil.encodeHexStr(result);
    }

    public static boolean verifyHmacSHA256(String webhookSecret, String content, String signed) throws Exception {
        String hmacSHA256Str = signHmacSHA256(webhookSecret, content);
        return StrUtil.equalsAnyIgnoreCase(hmacSHA256Str, signed);
    }
}