API reference
Create a checkout
Creates a payment page for one order and returns the payment, with the url to send the customer to.
POST
https://api.takaelo.com/v1/checkoutsNeeds Idempotency-Key. Returns 201 with the payment object, status initiated.
Body
amountintegerrequired- Whole taka, 1–1,000,000.
referencestring- Your order number, ≤ 120 characters.
success_urlstring- https on your websites (or
http://localhostwith a test key), ≤ 500 characters.{PAYMENT_ID}is filled in. cancel_urlstring- Same rules as
success_url. customerobjectname(≤ 80),phone(≤ 20),email(valid, ≤ 120). All optional.metadataobject- ≤ 20 keys; string keys ≤ 40, string values ≤ 500.
curl https://api.takaelo.com/v1/checkouts \
-H "Authorization: Bearer $TAKAELO_SECRET_KEY" \
-H "Idempotency-Key: order-4821-1" \
-H "Content-Type: application/json" \
-d '{
"amount": 1250,
"reference": "ORD-4821",
"success_url": "https://yourshop.com/orders/4821/thanks",
"cancel_url": "https://yourshop.com/cart",
"customer": { "name": "Rahim Uddin", "phone": "01712345678" },
"metadata": { "order_id": "4821" }
}'<?php
$ch = curl_init('https://api.takaelo.com/v1/checkouts');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('TAKAELO_SECRET_KEY'),
'Idempotency-Key: order-4821-1',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'amount' => 1250,
'reference' => 'ORD-4821',
'success_url' => 'https://yourshop.com/orders/4821/thanks',
'cancel_url' => 'https://yourshop.com/cart',
'customer' => ['name' => 'Rahim Uddin', 'phone' => '01712345678'],
'metadata' => ['order_id' => '4821'],
]),
]);
$body = json_decode(curl_exec($ch), true);
if (empty($body['success'])) {
throw new RuntimeException($body['code'] . ': ' . $body['message']);
}
$checkout = $body['data'];
echo $checkout['id'] . ' ' . $checkout['url'] . PHP_EOL;
// In a web request, send the customer to pay:
// header('Location: ' . $checkout['url'], true, 303);// Node 18+ (built-in fetch). Save as checkout.mjs and run: node checkout.mjs
const res = await fetch("https://api.takaelo.com/v1/checkouts", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.TAKAELO_SECRET_KEY}`,
"Idempotency-Key": "order-4821-1",
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 1250,
reference: "ORD-4821",
success_url: "https://yourshop.com/orders/4821/thanks",
cancel_url: "https://yourshop.com/cart",
customer: { name: "Rahim Uddin", phone: "01712345678" },
metadata: { order_id: "4821" },
}),
});
const body = await res.json();
if (!body.success) throw new Error(`${body.code}: ${body.message}`);
const checkout = body.data;
console.log(checkout.id, checkout.url);
// In Express: res.redirect(303, checkout.url);import json
import os
import urllib.error
import urllib.request
payload = {
"amount": 1250,
"reference": "ORD-4821",
"success_url": "https://yourshop.com/orders/4821/thanks",
"cancel_url": "https://yourshop.com/cart",
"customer": {"name": "Rahim Uddin", "phone": "01712345678"},
"metadata": {"order_id": "4821"},
}
request = urllib.request.Request(
"https://api.takaelo.com/v1/checkouts",
method="POST",
data=json.dumps(payload).encode(),
headers={
"Authorization": "Bearer " + os.environ["TAKAELO_SECRET_KEY"],
"Idempotency-Key": "order-4821-1",
"Content-Type": "application/json",
},
)
try:
with urllib.request.urlopen(request) as response:
checkout = json.load(response)["data"]
except urllib.error.HTTPError as e:
error = json.load(e)
raise SystemExit(f"{error['code']}: {error['message']}")
print(checkout["id"], checkout["url"])
# In Django / Flask: return redirect(checkout["url"])package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
)
func main() {
payload, _ := json.Marshal(map[string]any{
"amount": 1250,
"reference": "ORD-4821",
"success_url": "https://yourshop.com/orders/4821/thanks",
"cancel_url": "https://yourshop.com/cart",
"customer": map[string]string{"name": "Rahim Uddin", "phone": "01712345678"},
"metadata": map[string]string{"order_id": "4821"},
})
req, _ := http.NewRequest(http.MethodPost, "https://api.takaelo.com/v1/checkouts", bytes.NewReader(payload))
req.Header.Set("Authorization", "Bearer "+os.Getenv("TAKAELO_SECRET_KEY"))
req.Header.Set("Idempotency-Key", "order-4821-1")
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
var body struct {
Success bool `json:"success"`
Message string `json:"message"`
Code string `json:"code"`
Data struct {
ID string `json:"id"`
URL string `json:"url"`
} `json:"data"`
}
if err := json.NewDecoder(res.Body).Decode(&body); err != nil {
log.Fatal(err)
}
if !body.Success {
log.Fatalf("%s: %s", body.Code, body.Message)
}
fmt.Println(body.Data.ID, body.Data.URL)
// In a handler: http.Redirect(w, r, body.Data.URL, http.StatusSeeOther)
}require "json"
require "net/http"
uri = URI("https://api.takaelo.com/v1/checkouts")
request = Net::HTTP::Post.new(uri,
"Authorization" => "Bearer #{ENV.fetch("TAKAELO_SECRET_KEY")}",
"Idempotency-Key" => "order-4821-1",
"Content-Type" => "application/json")
request.body = {
amount: 1250,
reference: "ORD-4821",
success_url: "https://yourshop.com/orders/4821/thanks",
cancel_url: "https://yourshop.com/cart",
customer: { name: "Rahim Uddin", phone: "01712345678" },
metadata: { order_id: "4821" }
}.to_json
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
body = JSON.parse(response.body)
raise "#{body["code"]}: #{body["message"]}" unless body["success"]
checkout = body["data"]
puts "#{checkout["id"]} #{checkout["url"]}"
# In Rails: redirect_to checkout["url"], allow_other_host: true// Java 11+ HttpClient; JSON with Jackson (com.fasterxml.jackson.core:jackson-databind).
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Map;
public class CreateCheckout {
public static void main(String[] args) throws Exception {
ObjectMapper json = new ObjectMapper();
String payload = json.writeValueAsString(Map.of(
"amount", 1250,
"reference", "ORD-4821",
"success_url", "https://yourshop.com/orders/4821/thanks",
"cancel_url", "https://yourshop.com/cart",
"customer", Map.of("name", "Rahim Uddin", "phone", "01712345678"),
"metadata", Map.of("order_id", "4821")));
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.takaelo.com/v1/checkouts"))
.header("Authorization", "Bearer " + System.getenv("TAKAELO_SECRET_KEY"))
.header("Idempotency-Key", "order-4821-1")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
JsonNode body = json.readTree(response.body());
if (!body.path("success").asBoolean()) {
throw new IllegalStateException(body.path("code").asText() + ": " + body.path("message").asText());
}
JsonNode checkout = body.get("data");
System.out.println(checkout.get("id").asText() + " " + checkout.get("url").asText());
// In Spring: return "redirect:" + checkout.get("url").asText();
}
}// .NET 6+ top-level program: dotnet new console, paste into Program.cs, dotnet run
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("TAKAELO_SECRET_KEY"));
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.takaelo.com/v1/checkouts")
{
Content = JsonContent.Create(new
{
amount = 1250,
reference = "ORD-4821",
success_url = "https://yourshop.com/orders/4821/thanks",
cancel_url = "https://yourshop.com/cart",
customer = new { name = "Rahim Uddin", phone = "01712345678" },
metadata = new Dictionary<string, string> { ["order_id"] = "4821" },
}),
};
request.Headers.Add("Idempotency-Key", "order-4821-1");
using var response = await http.SendAsync(request);
var body = await response.Content.ReadFromJsonAsync<JsonElement>();
if (!body.GetProperty("success").GetBoolean())
throw new Exception($"{body.GetProperty("code")}: {body.GetProperty("message")}");
var checkout = body.GetProperty("data");
Console.WriteLine($"{checkout.GetProperty("id")} {checkout.GetProperty("url")}");
// In ASP.NET Core: return Results.Redirect(checkout.GetProperty("url").GetString()!);{
"success": true,
"message": "Checkout created",
"data": {
"id": "pay_3kT9xQm2LrV8nB4cW7yZ1aPd",
"object": "payment",
"livemode": true,
"status": "initiated",
"failure_reason": null,
"review_reason": null,
"amount": 1250,
"amount_received": null,
"amount_due": 1250,
"refund_due": 0,
"currency": "BDT",
"wallet": null,
"sender": "",
"trx_id": null,
"reference": "ORD-4821",
"source": "api",
"link_id": null,
"invoice_id": null,
"customer": { "name": "Rahim Uddin", "phone": "01712345678", "email": "" },
"metadata": { "order_id": "4821" },
"url": "https://yourshop.takaelo.com/pay/pay_3kT9xQm2LrV8nB4cW7yZ1aPd",
"created": 1791641454,
"expires_at": 1791643254,
"completed_at": null,
"refunded_at": null
}
}| Errors | |
|---|---|
400 RETURN_URL_NOT_ALLOWED | A return URL isn't on your websites. |
402 PLAN_LIMIT / SHOP_PAUSED | Live keys only. |
422 VALIDATION_FAILED | See error_sources. |