REST API:创建账单
身份验证
每个请求都带有三个请求头:
x-api-key:您店铺的公钥(以pk_开头)。x-timestamp:当前的 Unix 时间(秒)。与我们服务器时钟的误差必须在 5 分钟以内。x-signature:用您店铺的 API 密钥对timestamp.body签名得到的十六进制 HMAC-SHA256。
同时发送 Content-Type: application/json。每个签名请求只会被接受一次,因此再次发送相同请求前,请至少等待一秒,并重新签名。在控制台中显示 API 密钥需要使用验证器应用进行双重验证登录。
创建账单
发送 POST /api/v1/invoices,并附上 amount 和 currency。可选字段包括 orderId、allowedAssets、expiresMin(5 至 1440)、successUrl、cancelUrl 和 metadata。响应中包含 invoice_url:请将客户引导到该地址。
设置 test: true 即可创建无法用真钱支付的测试账单。完整参考请见 API 文档。
// Node.js 18+
const crypto = require('crypto');
async function createInvoice() {
const body = JSON.stringify({
amount: '49.00',
currency: 'USD',
orderId: 'ORD-1042',
allowedAssets: ['USDT_TRC20', 'BTC'],
successUrl: 'https://northwind-coffee.example/thanks',
});
const ts = Math.floor(Date.now() / 1000);
const signature = crypto
.createHmac('sha256', process.env.ARIONPAY_API_SECRET)
.update(`${ts}.${body}`)
.digest('hex');
// ARIONPAY_BASE_URL: the API address from the docs
const res = await fetch(`${process.env.ARIONPAY_BASE_URL}/api/v1/invoices`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': process.env.ARIONPAY_API_KEY, // pk_...
'x-timestamp': String(ts),
'x-signature': signature,
},
body,
});
const data = await res.json();
if (!res.ok) throw new Error(`${res.status}: ${data.error}`);
return data.invoice_url; // save data.id with the order, then send your customer here
}