REST API:請求書の作成
認証
すべてのリクエストに、次の3つのヘッダーを付けます:
x-api-key:ストアの公開鍵(pk_で始まります)。x-timestamp:現在のUnix時間(秒)。当社の時計との差が5分以内である必要があります。x-signature:ストアのAPIシークレットで署名した、timestamp.bodyのHMAC-SHA256(16進数)。
Content-Type: application/jsonも送信してください。署名付きリクエストはそれぞれ1回しか受け付けられないため、同じリクエストを再送する場合は1秒以上待ち、署名し直してください。ダッシュボードでAPIシークレットを表示するには、認証アプリによる2要素ログインが必要です。
請求書を作成
amountとcurrencyを付けてPOST /api/v1/invoicesを送信します。任意のフィールドには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
}