Reference
Code examples
Copy these onto your server. Keep the JWT in an env var — never in the storefront JavaScript.
cURL
create invoice
export TOKEN=$(curl -s https://pay.brainicsoft.com/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"admin@takapay.local","password":"takapay123"}' \
| python3 -c 'import sys,json; print(json.load(sys.stdin)["token"])')
curl -s https://pay.brainicsoft.com/api/payments \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"amount":1490,"note":"Order #2041"}'Node.js
server.mjs
const API = process.env.TAKAPAY_API || "https://pay.brainicsoft.com/api";
const token = process.env.TAKAPAY_TOKEN;
export async function createInvoice(amount, note) {
const res = await fetch(`${API}/payments`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ amount, note, expiresInHours: 24 }),
});
if (!res.ok) throw new Error(await res.text());
const invoice = await res.json();
return {
id: invoice.id,
payUrl: `${process.env.CHECKOUT_ORIGIN}/pay/${invoice.id}`,
};
}
// "confirmed" = money received (not yet confirmed by you).
// "verified" = you have confirmed fulfillment.
export async function isPaid(id) {
const invoice = await fetch(`${API}/payments/${id}`, {
headers: { Authorization: `Bearer ${token}` },
}).then((r) => r.json());
return invoice.status === "confirmed" || invoice.status === "verified";
}
// Call after you've fulfilled the order (API-key auth, by payment id).
export async function confirm(id) {
await fetch(`${API}/v1/payments/${id}/confirm`, {
method: "POST",
headers: { "X-Api-Key": process.env.TAKAPAY_API_KEY },
});
}PHP
takapay.php
<?php
$api = getenv("TAKAPAY_API") ?: "https://pay.brainicsoft.com/api";
$token = getenv("TAKAPAY_TOKEN");
function takapay_create(float $amount, string $note): array {
global $api, $token;
$ch = curl_init("$api/payments");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer $token",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"amount" => $amount,
"note" => $note,
]),
]);
$json = json_decode(curl_exec($ch), true);
curl_close($ch);
return $json;
}
$invoice = takapay_create(1490, "Order #2041");
header("Location: https://yoursite.com/pay/" . $invoice["id"]);WooCommerce / any store
fulfil when paid, then confirm
// After the customer returns from the checkout page, or via a cron:
if (await isPaid(order.takapay_id)) { // status: confirmed | verified
$order->payment_complete();
$order->update_status("processing");
await confirm(order.takapay_id); // confirmed → verified (final)
}