TakaElo

Search the docs

Pages, sections and error codes

API reference

Pay a test checkout

Test helper: pays a test checkout as if the customer sent the money, so your code can test itself end to end.

POSThttps://api.takaelo.com/v1/test_helpers/payments/{id}/pay

The Simulate payment button, by API: the same matching and the same webhooks as real money, with a TEST… TrxID. Needs a test key (sk_test_…) and Idempotency-Key. Without a body it pays what is due; send amount to pay part of it (payment.partially_paid, then pay the rest), and wallet to choose the wallet (bkash by default). Returns the payment. Above ৳20,000 a payment waits for review, as real money would.

Body (optional)

amountinteger
Whole taka, 1–1,000,000. Leave out to pay everything still due.
walletstring
bkash (default), nagad, rocket or upay, if the checkout hasn't picked one yet.
# Pay a TEST checkout as if the customer sent the money (sk_test_ keys only).
curl -X POST https://api.takaelo.com/v1/test_helpers/payments/pay_3kT9xQm2LrV8nB4cW7yZ1aPd/pay \
  -H "Authorization: Bearer $TAKAELO_SECRET_KEY" \
  -H "Idempotency-Key: testpay-pay_3kT9xQm2LrV8nB4cW7yZ1aPd"
<?php
$id = 'pay_3kT9xQm2LrV8nB4cW7yZ1aPd';
$ch = curl_init("https://api.takaelo.com/v1/test_helpers/payments/$id/pay");
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => [
        'Authorization: Bearer ' . getenv('TAKAELO_SECRET_KEY'), // a sk_test_ key
        "Idempotency-Key: testpay-$id",
    ],
]);
$body = json_decode(curl_exec($ch), true);
if (empty($body['success'])) {
    throw new RuntimeException($body['code'] . ': ' . $body['message']);
}
echo $body['data']['status'] . PHP_EOL; // "completed"
const id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd";
const res = await fetch(`https://api.takaelo.com/v1/test_helpers/payments/${id}/pay`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.TAKAELO_SECRET_KEY}`, // a sk_test_ key
    "Idempotency-Key": `testpay-${id}`,
  },
});
const body = await res.json();
if (!body.success) throw new Error(`${body.code}: ${body.message}`);

console.log(body.data.status); // "completed"
import json
import os
import urllib.error
import urllib.request

payment_id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd"
request = urllib.request.Request(
    f"https://api.takaelo.com/v1/test_helpers/payments/{payment_id}/pay",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["TAKAELO_SECRET_KEY"],  # a sk_test_ key
        "Idempotency-Key": f"testpay-{payment_id}",
    },
)
try:
    with urllib.request.urlopen(request) as response:
        payment = json.load(response)["data"]
except urllib.error.HTTPError as e:
    error = json.load(e)
    raise SystemExit(f"{error['code']}: {error['message']}")

print(payment["status"])  # "completed"
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
)

func main() {
	id := "pay_3kT9xQm2LrV8nB4cW7yZ1aPd"
	req, _ := http.NewRequest(http.MethodPost, "https://api.takaelo.com/v1/test_helpers/payments/"+id+"/pay", nil)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("TAKAELO_SECRET_KEY")) // a sk_test_ key
	req.Header.Set("Idempotency-Key", "testpay-"+id)

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var body struct {
		Success bool   `json:"success"`
		Code    string `json:"code"`
		Message string `json:"message"`
		Data    struct {
			Status string `json:"status"`
		} `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.Status) // "completed"
}
require "json"
require "net/http"

id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd"
uri = URI("https://api.takaelo.com/v1/test_helpers/payments/#{id}/pay")
request = Net::HTTP::Post.new(uri,
  "Authorization" => "Bearer #{ENV.fetch("TAKAELO_SECRET_KEY")}", # a sk_test_ key
  "Idempotency-Key" => "testpay-#{id}")
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"]

puts body["data"]["status"] # "completed"
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;

public class PayTestCheckout {
    public static void main(String[] args) throws Exception {
        String id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd";
        HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.takaelo.com/v1/test_helpers/payments/" + id + "/pay"))
            .header("Authorization", "Bearer " + System.getenv("TAKAELO_SECRET_KEY")) // a sk_test_ key
            .header("Idempotency-Key", "testpay-" + id)
            .POST(HttpRequest.BodyPublishers.noBody())
            .build();
        HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());

        JsonNode body = new ObjectMapper().readTree(response.body());
        if (!body.path("success").asBoolean()) {
            throw new IllegalStateException(body.path("code").asText() + ": " + body.path("message").asText());
        }
        System.out.println(body.get("data").get("status").asText()); // "completed"
    }
}
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")); // a sk_test_ key

var id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd";
var request = new HttpRequestMessage(HttpMethod.Post, $"https://api.takaelo.com/v1/test_helpers/payments/{id}/pay");
request.Headers.Add("Idempotency-Key", $"testpay-{id}");

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")}");

Console.WriteLine(body.GetProperty("data").GetProperty("status")); // "completed"
403 Forbidden — a live key
{
  "success": false,
  "message": "Test helpers work with a test key (sk_test_…) only",
  "code": "SIMULATOR_TEST_ONLY",
  "request_id": "Qm4XrT9wKd2Lp7Vb3Zn8Hc6Fs1Gy5Ja0Ue4Ri7Ot2Pw"
}
409 Conflict — already paid
{
  "success": false,
  "message": "This payment isn't waiting for money",
  "code": "PAYMENT_STATE",
  "request_id": "Zt7Kc2Nw9Lq4Xb8Rv3Hm6Pd1Fs5Gy0Ja4Ue7Ri2Ot9W"
}