API reference
Record a refund
Marks a completed payment refunded after you sent the money back from your wallet.
POST
https://api.takaelo.com/v1/payments/{id}/refundNeeds Idempotency-Key; no body. TakaElo doesn't move money — send it back from your wallet app, then call this. Returns the payment with status refunded, and payment.refunded fires.
# Record that you sent the money back (TakaElo never holds or moves money).
curl -X POST https://api.takaelo.com/v1/payments/pay_3kT9xQm2LrV8nB4cW7yZ1aPd/refund \
-H "Authorization: Bearer $TAKAELO_SECRET_KEY" \
-H "Idempotency-Key: refund-pay_3kT9xQm2LrV8nB4cW7yZ1aPd"<?php
$id = 'pay_3kT9xQm2LrV8nB4cW7yZ1aPd';
$ch = curl_init("https://api.takaelo.com/v1/payments/$id/refund");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('TAKAELO_SECRET_KEY'),
"Idempotency-Key: refund-$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; // "refunded"const id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd";
const res = await fetch(`https://api.takaelo.com/v1/payments/${id}/refund`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.TAKAELO_SECRET_KEY}`,
"Idempotency-Key": `refund-${id}`,
},
});
const body = await res.json();
if (!body.success) throw new Error(`${body.code}: ${body.message}`);
console.log(body.data.status); // "refunded"import json
import os
import urllib.error
import urllib.request
payment_id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd"
request = urllib.request.Request(
f"https://api.takaelo.com/v1/payments/{payment_id}/refund",
method="POST",
headers={
"Authorization": "Bearer " + os.environ["TAKAELO_SECRET_KEY"],
"Idempotency-Key": f"refund-{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"]) # "refunded"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/payments/"+id+"/refund", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("TAKAELO_SECRET_KEY"))
req.Header.Set("Idempotency-Key", "refund-"+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) // "refunded"
}require "json"
require "net/http"
id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd"
uri = URI("https://api.takaelo.com/v1/payments/#{id}/refund")
request = Net::HTTP::Post.new(uri,
"Authorization" => "Bearer #{ENV.fetch("TAKAELO_SECRET_KEY")}",
"Idempotency-Key" => "refund-#{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"] # "refunded"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 RefundPayment {
public static void main(String[] args) throws Exception {
String id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd";
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.takaelo.com/v1/payments/" + id + "/refund"))
.header("Authorization", "Bearer " + System.getenv("TAKAELO_SECRET_KEY"))
.header("Idempotency-Key", "refund-" + 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()); // "refunded"
}
}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 id = "pay_3kT9xQm2LrV8nB4cW7yZ1aPd";
var request = new HttpRequestMessage(HttpMethod.Post, $"https://api.takaelo.com/v1/payments/{id}/refund");
request.Headers.Add("Idempotency-Key", $"refund-{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")); // "refunded"{
"success": false,
"message": "Only completed payments can be refunded",
"code": "PAYMENT_STATE",
"request_id": "EBu-Sqo2royOTpPQi93clbgy37ka7RepIMMGPOpW6sY"
}