Pay-in Callback
The merchant server is called only after a pay-in completes successfully; the callback status is always completed.
Only final payment results are sent. Any HTTP 2xx response stops delivery immediately. After the first failure, the platform retries in 1 minute; after another failure, it makes a final retry in 5 minutes, for up to 3 attempts total. Callback business times use Beijing time in YYYY/MM/DD HH:mm:ss format.
Request Headers
| Field | Type | Required | Description |
|---|---|---|---|
| content-type | application/json | Yes | Always application/json. |
| x-callback-timestamp | string | Yes | Callback timestamp in milliseconds. |
| x-callback-nonce | string | Yes | Callback nonce. |
| x-callback-signature | string | Yes | HMAC-SHA256(apiKey, timestamp + "." + nonce + "." + rawBody)。 |
| x-callback-signature-algorithm | string | Yes | Always HMAC-SHA256. |
| x-callback-signature-version | string | Yes | Always v1. |
Request Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| merchantUid | string | Yes | Merchant UID. |
| orderNo | string | Yes | Platform order number. |
| merchantOrderNo | string | null | Yes | Merchant order number. |
| bindKey | string | null | Yes | Binding key for member recharge. Usually empty for shared pay-in orders. |
| chainCode | string | null | Yes | The network for this order. |
| tokenSymbol | string | null | Yes | The token for this order. |
| txHash | string | null | Yes | Matched transaction hash; null before detection. |
| expectedAmount | string | null | Yes | Order amount. |
| paidAmount | string | Yes | Actual paid amount. |
| fromAddress | string | null | Yes | Sender address. |
| status | string | Yes | Final successful pay-in status; always completed. |
| mode | string | Yes | Order mode: shared or exclusive. |
| businessType | string | Yes | Order business type. |
| serviceFeeUsd | string | No | Service fee for this pay-in. |
| feeBalanceAfterUsd | string | No | Fee account balance after charging. |
| payerRiskStatus | string | Yes | Payer risk assessment status. |
| payerRiskLabel | string | null | Yes | Payer risk assessment label. |
Request Example
{
"merchantUid": "880001",
"orderNo": "PI1776193200123ABCD1234",
"merchantOrderNo": "M202604150001",
"bindKey": null,
"expectedAmount": "100.000000",
"paidAmount": "100.000000",
"chainCode": "TRON",
"tokenSymbol": "USDT",
"txHash": "f7f17891f52c35d0c93170f0d12bb347ac16ab34853b4bc8dcf7fd0a8c9aa321",
"fromAddress": "TS7b7iD8G2PaPqK1TqSmLJ9nrrYH4oKX1S",
"status": "completed",
"mode": "shared",
"businessType": "fixed",
"serviceFeeUsd": "0.000000",
"feeBalanceAfterUsd": "10.000000",
"payerRiskStatus": "low_risk",
"payerRiskLabel": "低风险"
}Response Fields
| Field | Type | Required | Description |
|---|---|---|---|
| HTTP Status | 200-299 | Yes | Any 2xx response is treated as success. |
| Response Body | string | json | No | The response body can be customized. |
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"ok": true
}Code Examples
Run: save Java as UUGateExample.java (UUGateCallback.java for callbacks) and use java filename; PHP: php example.php; Go: go run example.go; Node.js: node example.mjs. Callback verifiers read the raw body from standard input.
import { createHmac, timingSafeEqual } from 'node:crypto';
function required(name) {
const value = process.env[name]?.trim();
if (!value) throw new Error(name + ' is required');
return value;
}
const key = required('UUGATE_API_KEY');
const timestamp = required('UUGATE_CALLBACK_TIMESTAMP'), nonce = required('UUGATE_CALLBACK_NONCE');
const signature = required('UUGATE_CALLBACK_SIGNATURE');
const chunks = [];
for await (const chunk of process.stdin) chunks.push(chunk);
const rawBody = Buffer.concat(chunks);
const expected = createHmac('sha256', key).update(timestamp + '.' + nonce + '.', 'utf8').update(rawBody).digest();
const actual = Buffer.from(signature, 'hex');
if (!/^[a-fA-F0-9]{64}$/.test(signature) || actual.length !== expected.length || !timingSafeEqual(expected, actual))
throw new Error('Invalid callback signature');
console.log('VERIFIED');import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.HexFormat;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class UUGateCallback {
static String required(String name) {
String value = System.getenv(name);
if (value == null || value.isBlank()) throw new IllegalArgumentException(name + " is required");
return value.trim();
}
public static void main(String[] args) throws Exception {
String key = required("UUGATE_API_KEY");
String timestamp = required("UUGATE_CALLBACK_TIMESTAMP"), nonce = required("UUGATE_CALLBACK_NONCE");
String signature = required("UUGATE_CALLBACK_SIGNATURE");
byte[] rawBody = System.in.readAllBytes();
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
mac.update((timestamp + "." + nonce + ".").getBytes(StandardCharsets.UTF_8));
byte[] expected = mac.doFinal(rawBody);
if (!signature.matches("[a-fA-F0-9]{64}") ||
!MessageDigest.isEqual(expected, HexFormat.of().parseHex(signature)))
throw new IllegalArgumentException("Invalid callback signature");
System.out.println("VERIFIED");
}
}<?php
function required(string $name): string {
$value = trim((string) getenv($name));
if ($value === '') throw new RuntimeException($name . ' is required');
return $value;
}
$key = required('UUGATE_API_KEY');
$timestamp = required('UUGATE_CALLBACK_TIMESTAMP'); $nonce = required('UUGATE_CALLBACK_NONCE');
$signature = required('UUGATE_CALLBACK_SIGNATURE');
$rawBody = file_get_contents('php://stdin');
if ($rawBody === false) throw new RuntimeException('Cannot read raw body');
$expected = hash_hmac('sha256', $timestamp . '.' . $nonce . '.' . $rawBody, $key);
if (!preg_match('/^[a-fA-F0-9]{64}$/D', $signature) || !hash_equals($expected, strtolower($signature)))
throw new RuntimeException('Invalid callback signature');
echo 'VERIFIED', PHP_EOL;package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"os"
"strings"
)
func required(name string) string {
value := strings.TrimSpace(os.Getenv(name))
if value == "" { panic(name + " is required") }
return value
}
func main() {
key := required("UUGATE_API_KEY")
timestamp, nonce := required("UUGATE_CALLBACK_TIMESTAMP"), required("UUGATE_CALLBACK_NONCE")
signature := required("UUGATE_CALLBACK_SIGNATURE")
rawBody, err := io.ReadAll(os.Stdin); if err != nil { panic(err) }
mac := hmac.New(sha256.New, []byte(key))
mac.Write([]byte(timestamp + "." + nonce + ".")); mac.Write(rawBody)
actual, err := hex.DecodeString(signature)
if err != nil || !hmac.Equal(mac.Sum(nil), actual) { panic("Invalid callback signature") }
fmt.Println("VERIFIED")
}Notes
- Callback verification uses apiKey, not the OpenAPI x-signature request header.
- After verification, match the merchant, order, asset, network and amount. Persist payment and business results transactionally and idempotently by platform order number before returning 2xx; repeated notifications must not duplicate credits or fulfillment.
- For member recharge, use bindKey directly as the member identifier so you do not need an extra orderNo-to-member mapping table.
- This code only verifies callbacks. Pass the raw request body to standard input and map callback headers to UUGATE_CALLBACK_TIMESTAMP, UUGATE_CALLBACK_NONCE and UUGATE_CALLBACK_SIGNATURE. UUGATE_API_KEY must be the key used to create the order. Then validate the order and persist it idempotently in a transaction before returning HTTP 2xx.