const body = JSON.stringify({
  reference: 'ORDER-20261021-0001',
  amount: 100.50,
  currency: 'CNY',
  customer: { name: 'Zhang San' },
});

const ts = Math.floor(Date.now() / 1000);
const nonce = crypto.randomBytes(8).toString('hex');
const hash = crypto.createHash('sha256')
  .update(body).digest('hex');

const sign = crypto.createHmac('sha256', API_SECRET)
  .update(['POST', '/v1/payin/create', ts, nonce, hash]
    .join('\n'))
  .digest('hex');

const res = await fetch(BASE_URL + '/v1/payin/create', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    'x-fx-key': API_KEY,
    'x-fx-timestamp': String(ts),
    'x-fx-nonce': nonce,
    'x-fx-sign': sign,
  },
  body,
});

const { data } = await res.json();
// data.checkout_url -> 把客户送到这个地址