Exemplos de código

Exemplos prontos para copiar e colar dos fluxos mais comuns, em cURL, Node e Python.

Ainda não está no ar — api.baynoy.com não resolve, então os exemplos abaixo não vão funcionar hoje. Eles descrevem o contrato que estamos construindo, e os formatos desta página ainda podem mudar.

Create a payment link

The same call in three shapes — plain HTTPS, no library.

cURL
curl https://api.baynoy.com/v1/catalog/links \
  -H "Authorization: Bearer bk_test_..." \
  -H "Content-Type: application/json" \
  -d '{"title": "Design retainer", "amountMinor": "4900", "assetKey": "fiat:EUR"}'

# -> {"id": "lnk_...", "slug": "k3x9q2"}  — the page is https://baynoy.com/pay/k3x9q2
Node
// Node 18+, no package needed
const res = await fetch("https://api.baynoy.com/v1/catalog/links", {
  method: "POST",
  headers: {
    authorization: `Bearer ${process.env.BAYNOY_SECRET_KEY}`,
    "content-type": "application/json",
  },
  // amounts are strings of integer minor units — never floats
  body: JSON.stringify({ title: "Design retainer", amountMinor: "4900", assetKey: "fiat:EUR" }),
});
const { slug } = await res.json();
console.log(`https://baynoy.com/pay/${slug}`);
Python
import os, requests

r = requests.post(
    "https://api.baynoy.com/v1/catalog/links",
    headers={"Authorization": f"Bearer {os.environ['BAYNOY_SECRET_KEY']}"},
    json={"title": "Design retainer", "amountMinor": "4900", "assetKey": "fiat:EUR"},
)
print("https://baynoy.com/pay/" + r.json()["slug"])