Quickstart

import { createHmac } from 'node:crypto';


// PRIVATE_KEY and SECRET_KEY hold the key's privateKey and secretKey.
const apiOrigin = 'https://dev-app.tedr.com';
const pathPrefix = '/api';


const signedFetch = async (path, method, payload) => {
  // Sign the path exactly as it goes out, prefix and query string included.
  const url = pathPrefix + path;
  const timestamp = String(Date.now());
  // Serialize once: sign this exact string and send this exact string.
  const body = payload === undefined ? '' : JSON.stringify(payload);


  const signature = createHmac('sha256', SECRET_KEY)
    .update(timestamp + url + body)
    .digest('hex');


  return await fetch(apiOrigin + url, {
    method,
    headers: {
      'Content-Type': 'application/json',
      KeyId: PRIVATE_KEY,
      Timestamp: timestamp,
      Algorithm: 'sha256',
      'X-Signature': signature,
    },
    body: body || undefined,
  });
};
const response = await signedFetch('/invoices', 'POST', {
  type: 'PAYME',
  amount: '150.00',
  description: 'Order 2041',
});


const { invoice } = await response.json();
{
  "invoice": {
    "businessInvoiceId": "6f1c1e2c-9b4c-4a2e-9f8b-0d5a1b2c3d4e",
    "type": "PAYME",
    "status": "ACTIVE",
    "businessInvoiceUrl": "https://pay.tedr.com/pay/PbQ7x...",
    "createdAt": "2026-07-30T10:15:00.000Z",
    "expiresAt": "2026-08-29T10:15:00.000Z"
  }
}
const id = invoice.businessInvoiceId;


const detail = await (await signedFetch(`/invoices/${id}`, 'GET')).json();
const payments = await (
  await signedFetch(`/invoices/${id}/payments?limit=20`, 'GET')
).json();