TakaElo

Search the docs

Pages, sections and error codes

Guides

Checkouts

Create a payment page for an order, send the customer to it, and bring them back to your shop.

A checkout is a payment page for one order. You create it from your server, send the customer to its url, and TakaElo does the rest: wallet choice, your number, the exact amount, the countdown, and the confirmation.

Create one

Create a checkout
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()!);

The reply is the full payment object with status initiated. Store its id next to your order, then redirect the customer to url with a 303.

201 Created
{
  "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
  }
}

What you can send

amountintegerrequired
Whole taka, 1 to 1,000,000. 1250 is ৳1,250.
referencestring
Your order number (up to 120 characters). Shown to the customer and sent back in every webhook.
success_urlstring
Where the customer goes after paying. {PAYMENT_ID} in it is replaced with the payment's id.
cancel_urlstring
Where the customer goes if they leave before paying, or after the time runs out.
customer.namestring
Up to 80 characters. Fills the payment details in your dashboard.
customer.phonestring
Up to 20 characters. If it is a wallet number it is also used as the sender for test payments.
customer.emailstring
A valid email, up to 120 characters.
metadataobject
Up to 20 string keys (40 characters) and string values (500 characters). Stored as-is and returned everywhere.

Return URLs

success_url and cancel_url must be https addresses on one of your websites — the domains in Settings › Domains, or a subdomain of one. Anything else gets 400 RETURN_URL_NOT_ALLOWED with data.field naming the field. Test keys may also use http://localhost (any port), so you can build on your laptop.

  • After paying, the page shows "Payment received" with the TrxID, then takes the customer to success_url after four seconds (or at once, with the button).
  • Leaving: the checkout shows "Cancel and go back to the shop" while nothing has been paid. It cancels the checkout (you get payment.failed with failure_reason: "cancelled") and goes to cancel_url.
  • Time up: an expired checkout offers "Back to shop", to cancel_url.

How long a checkout stays open

StageTimeWhat happens
Choosing a wallet30 minutesThe customer picks bKash, Nagad, Rocket or Upay and types the number they'll pay from.
Paying15 minutes from choosing (a setting on each wallet number)Your number and the exact amount are shown. The page confirms itself when the money arrives.
Time up—The payment fails with failure_reason: "expired" (a 2-minute grace lets a message already on its way still land).
Money after time upup to 24 hoursIt is not lost: the payment goes to pending_review with review_reason: "late" for you to approve.

Your checkout address

Checkout pages live on your address: https://<your-handle>.takaelo.com/pay/<id>. Your own domain (https://pay.yourshop.com/pay/<id>) is coming soon. The url in every reply always uses the right address, so it will need no code change.

Idempotency

Send Idempotency-Key: order-<your order id>-<attempt> (e.g. order-4821-1). If your server times out and retries that attempt with the same key, the second call returns the same checkout instead of a new one. When the customer tries again after a failed payment, that is a new attempt: order-4821-2. See API keys and requests.