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 http://localhost:4000/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 http://localhost:4000/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 || "http://localhost:4000/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}`,
};
}
export async function isPaid(id) {
const invoice = await fetch(`${API}/payments/${id}`, {
headers: { Authorization: `Bearer ${token}` },
}).then((r) => r.json());
return invoice.status === "verified";
}PHP
takapay.php
<?php
$api = getenv("TAKAPAY_API") ?: "http://localhost:4000/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 only after verified
// After the customer returns from /pay/{id}, or via a 15s cron:
if (await isPaid(order.takapay_id)) {
$order->payment_complete();
$order->update_status("processing");
}