Documentación

Ejemplos de código

32 recetas de plataforma · una API REST coherente

Node.js

Server only. Read the amount from your saved order; never trust a browser amount. Verify signed webhooks and GET /transactions/{transaction_id} before fulfilling once per transaction. Payment amounts are allocated on Start payment; handle transaction.reassigned corrections.

create-invoice.mjs
// Server only. Pass an order loaded from your database after authorization.
export async function createGatewayInvoice(order) {
  const response = await fetch(process.env.SMETA_API_URL + '/api/v1/invoices', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json',
      Authorization: 'Bearer ' + process.env.SMETA_API_KEY,
      'Idempotency-Key': 'checkout:' + order.id },
    body: JSON.stringify({ merchant_order_id: order.id, amount: order.totalUsdt, wallet_id: process.env.SMETA_WALLET_ID })
  });
  if (!response.ok) throw new Error('Gateway rejected invoice: ' + response.status);
  const { invoice } = await response.json();
  return invoice;
}
// Caller saves invoice.id, base_amount, wallet_address and merchant_order_id,
// then returns { checkout_url: invoice.checkout_url } to its authenticated user.

Guarda las claves API en tu servidor. Entrega pedidos solo tras verificar el pago en el servidor.