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
| Header | Type | Required | Description |
|---|---|---|---|
Content-Type | String | Yes | Fixed to application/json;charset=UTF-8. |
x-timestamp | String | Yes | Unix timestamp in seconds. |
x-signature | String | Yes | Generate the HMAC-SHA256 signature from webhook_secret and x-timestamp + "." + raw_body. See Signature and verification. |
Payload structure
| Field | Description |
|---|---|
request_id | Unique notification ID. Use it to deduplicate deliveries. |
event_type | Event type identifier. See the individual webhook page for its fixed value. |
created_at | Notification creation time in ISO 8601 format. |
version | Webhook payload version. |
data | Event-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.
| Field | Type | Description |
|---|---|---|
respCode | String | Return 20000 to confirm receipt. |
respMsg | String | Response 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:
- Read
x-timestampandx-signaturefrom the request headers. - Read the raw request body without parsing or re-serializing it.
- Concatenate
x-timestamp, a period (.), andraw_bodyto build the signed content:
x-timestamp + "." + raw_body
- Use the UTF-8 bytes of
webhook_secretdirectly as the HMAC key. Do not Base64-decodewebhook_secret. - Apply HMAC-SHA256 to the signed content and encode the result as a lowercase hexadecimal string.
- 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);
}
}
import hashlib
import hmac
def sign_hmac_sha256(webhook_secret: str, content: str) -> str:
return hmac.new(
webhook_secret.encode("utf-8"),
content.encode("utf-8"),
hashlib.sha256,
).hexdigest()
def verify_hmac_sha256(webhook_secret: str, content: str, signed: str) -> bool:
expected = sign_hmac_sha256(webhook_secret, content)
return hmac.compare_digest(expected.lower(), signed.lower())
<?php
final class HmacSHA256Util
{
public static function signHmacSHA256(string $webhookSecret, string $content): string
{
return hash_hmac('sha256', $content, $webhookSecret);
}
public static function verifyHmacSHA256(string $webhookSecret, string $content, string $signed): bool
{
$expected = self::signHmacSHA256($webhookSecret, $content);
return hash_equals(strtolower($expected), strtolower($signed));
}
}