Integration

Start with one request.

Initialize a payment with your public key. The API returns a hosted checkout URL; redirect your customer there, then confirm payment by verifying its status or validating the signed webhook on your server.

Browser SDK (CDN)

Load the hosted checkout SDK and call TJGateway.open from a customer action, such as a button click. The customer leaves your site and is redirected to the gateway’s full-page secure checkout; card or bank details never pass through your page.

<script src="https://nmafort.site/tjgateway.js"></script>
<button id="pay-button" type="button">Pay now</button>
<script>
  document.getElementById("pay-button").addEventListener("click", () => {
    try {
      TJGateway.open({
        key: "YOUR_TEST_PUBLIC_KEY",
        email: "customer@example.com",
        name: "Ada Okafor",
        phone: "08000000000",
        amount: 2500,
        reference: "order_2026_0001",
        callback_url: "https://shop.example.com/payment/return",
        meta: { order_id: "order_2026_0001" },
      });
    } catch (error) {
      if (error.name === "ValidationError") {
        console.error("Invalid payment fields:", error.errors);
        return;
      }
      console.error("Could not start checkout:", error);
    }
  });
</script>

Replace the test key with your live public key when ready. The amount is an integer in naira (minimum NGN 100). Set callback_url to return the customer to your site after checkout. Verify the transaction on your server or validate its signed webhook before fulfilling an order.

The SDK throws a ValidationError with field-specific errors for invalid client input. Server-side validation failures return HTTP 422 with a JSON errors object keyed by field.

1. curl

Use your test public key while building. The request body requires the payer’s name, email, phone number, and an integer amount in naira (not kobo) of at least NGN 100.

curl -X POST "https://nmafort.site/api/v1/transaction/initialize" \
  -H "Authorization: Bearer YOUR_TEST_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "customer@example.com",
    "name": "Ada Okafor",
    "phone": "08000000000",
    "amount": 2500,
    "currency": "NGN",
    "reference": "order_2026_0001",
    "callback_url": "https://shop.example.com/payment/return",
    "meta": { "order_id": "order_2026_0001" }
  }'

On success, the API responds with HTTP 201 and JSON containing status, reference, environment, and checkout_url. Redirect the customer to that checkout URL.

2. Node.js

Use the public key for initialization (for example, TJ_GATEWAY_PUBLIC_KEY). Public keys are safe to expose in browser applications; keep secret keys private for webhook signature verification.

const response = await fetch(
  "https://nmafort.site/api/v1/transaction/initialize",
  {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.TJ_GATEWAY_PUBLIC_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      email: "customer@example.com",
      name: "Ada Okafor",
      phone: "08000000000",
      amount: 2500,
      currency: "NGN",
      reference: "order_2026_0001",
      callback_url: "https://shop.example.com/payment/return",
      meta: { order_id: "order_2026_0001" },
    }),
  },
);

const result = await response.json();
if (!response.ok || result.status !== "success") {
  throw new Error(result.error ?? result.message ?? "Payment initialization failed");
}

// Send the customer to the hosted checkout from your server response.
return Response.redirect(result.checkout_url, 303);

3. PHP

This example uses PHP’s cURL extension and returns the hosted checkout URL to your application for a server-side redirect.

$payload = [
    'email' => 'customer@example.com',
    'name' => 'Ada Okafor',
    'phone' => '08000000000',
    'amount' => 2500,
    'currency' => 'NGN',
    'reference' => 'order_2026_0001',
    'callback_url' => 'https://shop.example.com/payment/return',
    'meta' => ['order_id' => 'order_2026_0001'],
];

$curl = curl_init('https://nmafort.site/api/v1/transaction/initialize');
curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('TJ_GATEWAY_PUBLIC_KEY'),
        'Content-Type: application/json',
        'Accept: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode($payload, JSON_THROW_ON_ERROR),
]);

$body = curl_exec($curl);
if ($body === false) {
    throw new RuntimeException('Payment request failed: ' . curl_error($curl));
}
$httpStatus = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);

$result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
if ($httpStatus !== 201 || ($result['status'] ?? null) !== 'success') {
    throw new RuntimeException($result['error'] ?? $result['message'] ?? 'Payment initialization failed');
}

header('Location: ' . $result['checkout_url'], true, 303);
exit;