SDK

Add gourde payments to your website

A copy-ready JavaScript client, request examples for every endpoint, and the exact steps to go from a test key to real payments in Gourdes. Server-side only — your secret key never reaches the browser.

API reference

Integration steps

Eight steps from an empty website to a working gourde checkout. Nothing to install — the client is a file you copy.

1

Open a merchant account

Sign in, complete identity verification, and wait for approval. Test keys work before approval; live keys need it.

2

Register your website

Add the HTTPS domain customers will pay from. Return and cancel URLs must belong to that domain.

3

Create an API key

In Merchant → API keys, create a test key first. Copy the secret immediately — it is shown only once.

4

Store the key server-side

Put the key and the base URL in your server's environment. It must never reach the browser or a repository.

5

Create the payment

POST /payments with amount_minor (integer centimes of gourdes), the order reference and your website id.

6

Send the customer to checkout

Redirect to the checkout_url you received. The hosted page collects the payment in gourdes.

7

Confirm before you deliver

Fulfil only when a signed webhook says payment.succeeded, or a GET /payments/{id} check returns succeeded.

8

Switch to live

Once your account is approved, create a live key and enable live mode. Same code, different key.

SDK

Test and live, same contract

There is nothing to install: the snippets below are complete server-side clients for the REST contract. Use a test key while you build and a live key only once your merchant account is approved.

// ayiti.js — server-side only (Node 18+, Bun, Deno). Never ship this to a browser.
// Your secret key lives in a server environment variable, never in the code itself:
//   AYITI_API_BASE_URL=https://api.example.com/v1
//   AYITI_SECRET_KEY=sk_test_…     (sk_live_… once your merchant is approved)
export class AyitiClient {
  constructor({ baseUrl, secretKey }) {
    if (!baseUrl || !secretKey) throw new Error("baseUrl and secretKey are required");
    const url = String(baseUrl);
    this.baseUrl = url.endsWith("/") ? url.slice(0, -1) : url;
    this.secretKey = secretKey;
  }

  async request(path, { method = "GET", body, idempotencyKey, auth = true } = {}) {
    const res = await fetch(`${this.baseUrl}${path}`, {
      method,
      headers: {
        ...(auth ? { Authorization: `Bearer ${this.secretKey}` } : {}),
        ...(body ? { "Content-Type": "application/json" } : {}),
        ...(idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}),
      },
      body: body ? JSON.stringify(body) : undefined,
    });
    const data = await res.json().catch(() => ({}));
    if (!res.ok) throw new Error(`Ayiti API ${res.status}: ${data?.error?.code ?? "unknown"}`);
    return data;
  }

  // POST /payments → returns the hosted checkout_url
  createPayment({ amountMinor, orderReference, description, websiteId, returnUrl, cancelUrl, customerReference, metadata }) {
    return this.request("/payments", {
      method: "POST",
      idempotencyKey: `order-${orderReference}-1`,
      body: {
        amount_minor: amountMinor,     // integer centimes: G.2500.00 = 250000
        currency: "HTG",
        order_reference: orderReference,
        description,
        website_id: websiteId,
        return_url: returnUrl,
        cancel_url: cancelUrl,
        customer_reference: customerReference,
        metadata,
      },
    });
  }

  // GET /payments/{payment_id}
  getPayment(paymentId) {
    return this.request(`/payments/${paymentId}`);
  }

  // POST /payments/{payment_id}/cancel
  cancelPayment(paymentId) {
    return this.request(`/payments/${paymentId}/cancel`, { method: "POST" });
  }

  // GET /transactions
  listTransactions({ status, from, to, limit = 50, cursor } = {}) {
    const query = new URLSearchParams({
      ...(status ? { status } : {}),
      ...(from ? { from } : {}),
      ...(to ? { to } : {}),
      limit: String(limit),
      ...(cursor ? { cursor } : {}),
    });
    return this.request(`/transactions?${query}`);
  }

  // POST /refunds
  createRefund({ paymentId, amountMinor, reason }) {
    return this.request("/refunds", {
      method: "POST",
      idempotencyKey: `refund-${paymentId}-${amountMinor}`,
      body: { payment_id: paymentId, amount_minor: amountMinor, reason },
    });
  }

  // GET /refunds/{refund_id}
  getRefund(refundId) {
    return this.request(`/refunds/${refundId}`);
  }

  // GET /balance
  getBalance() {
    return this.request("/balance");
  }

  // GET /health — the only endpoint that needs no key
  health() {
    return this.request("/health", { auth: false });
  }
}

// Verify a webhook before you fulfil anything.
export async function verifyAyitiSignature(rawBody, header, secret) {
  const parts = Object.fromEntries(String(header ?? "").split(",").map((p) => p.split("=")));
  if (!parts.t || !parts.v1) return false;
  const key = await crypto.subtle.importKey(
    "raw", new TextEncoder().encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"],
  );
  const mac = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${parts.t}.${rawBody}`));
  const expected = [...new Uint8Array(mac)].map((b) => b.toString(16).padStart(2, "0")).join("");
  return expected === parts.v1;
}

// Usage — the secret key is read from the environment, never written in code.
const ayiti = new AyitiClient({
  baseUrl: process.env.AYITI_API_BASE_URL,   // https://ayiti-api-connect.base44.app
  secretKey: process.env.AYITI_SECRET_KEY,   // sk_test_… or sk_live_…
});

const payment = await ayiti.createPayment({
  amountMinor: 250000,                       // G.2500.00
  orderReference: "LY-4471",
  description: "Baskèt ayisyen — 2 atik",
  websiteId: process.env.AYITI_WEBSITE_ID,
  returnUrl: "https://boutiquelakay.ht/merci",
  cancelUrl: "https://boutiquelakay.ht/panier",
});

return payment.checkout_url; // redirect the customer there

Test vs live

TestLive
Keysk_test_…sk_live_…
Moves moneyNoYes
RequiresA merchant accountApproved verification
Where to createMerchant → API keys

Environment variables

AYITI_API_BASE_URL
AYITI_SECRET_KEY
AYITI_WEBHOOK_SECRET
AYITI_WEBSITE_ID

Store them on your server, never in the browser bundle or a public repository. A secret key is shown once when you create it in Merchant → API keys — save it immediately.

The rules that keep you safe

  • Create and confirm payments only on your server.
  • Never mark an order paid because the customer reached a success page.
  • Always reuse the same idempotency key when retrying a creation.
  • Verify the webhook signature and the amount before delivering.

Building with an AI tool?

Paste the ready-made prompt into your builder. It describes the same server-side flow, the secrets to ask you for, and what never to trust.

AI integration prompt