API Online
support@rechapi.com
Developers

Recharge API Callback (Webhook) Guide: Handle Pending Transactions Safely

What a recharge API callback is, why pending recharges need it, how to set your callback URL and a safe PHP example to update orders without double refunds.

Most recharges finish in a few seconds. But sometimes the operator is slow and the API returns PENDING. A few minutes later the recharge becomes SUCCESS or FAILED. How does your system find out? Through a callback.

What is a callback?

A callback (also called a webhook) is a request that the API provider sends to your server when something changes. Instead of you asking again and again “is it done yet?”, the provider tells you as soon as the final status is known.

With ClubApi, the final status of every transaction is sent to the callback URL you set in your account.

Why callbacks are important

  • No lost money: you refund customers only when a recharge has really FAILED.
  • Happy customers: they see the final result automatically.
  • Less manual work: no need to check pending recharges one by one.

Step 1: Set your callback URL

  1. Log in and open API → Callback.
  2. Add a public HTTPS URL on your server, for example https://yourdomain.com/clubapi-callback.php.
  3. Choose the method (POST or GET).

The URL must be reachable from the internet. localhost addresses will not work for callbacks.

Step 2: Write the callback receiver

The callback contains your urid (the unique ID you sent), the provider's order ID and the final status. Check the exact parameter names in the API docs and adjust the names below if needed.

<?php
// clubapi-callback.php

// 1) read data (works for POST and GET)
$urid   = $_REQUEST["urid"] ?? "";
$status = strtoupper($_REQUEST["status"] ?? "");

// 2) keep a log of every callback (very useful for support)
file_put_contents(__DIR__ . "/callback-log.txt",
    date("Y-m-d H:i:s") . " " . json_encode($_REQUEST) . "\n", FILE_APPEND);

// 3) basic checks
if ($urid == "" || !in_array($status, array("SUCCESS", "FAILED", "PENDING"))) {
    echo "invalid";
    exit;
}

// 4) find the order in your database
$db = new mysqli("localhost", "db_user", "db_pass", "db_name");
$stmt = $db->prepare("SELECT status FROM recharges WHERE urid = ?");
$stmt->bind_param("s", $urid);
$stmt->execute();
$order = $stmt->get_result()->fetch_assoc();

if (!$order) {
    echo "not found";
    exit;
}

// 5) update only if the order is still PENDING (no double refund)
if ($order["status"] == "PENDING" && $status != "PENDING") {
    $up = $db->prepare("UPDATE recharges SET status = ? WHERE urid = ? AND status = 'PENDING'");
    $up->bind_param("ss", $status, $urid);
    $up->execute();

    if ($status == "FAILED") {
        // refund your customer here (only once)
    }
}

echo "OK";

Best practices

  • Update only once: the AND status = 'PENDING' condition makes sure the same callback received twice does not refund twice.
  • Reply quickly: do heavy work (SMS, emails) after saving the status.
  • Log everything: keep the raw callback data for at least a few months.
  • Use prepared statements as shown, never put request data directly into SQL.
  • Have a backup: if a callback is missed, check the transaction in your account or with the status check API.

Testing your callback

Open your callback URL in a browser with test values, for example clubapi-callback.php?urid=TEST1&status=SUCCESS, and check that it logs the request. Then do a real recharge and watch the log. You can also see callback hits in your account under API → Callback.

New to the API? Start with our PHP integration guide.

Frequently asked questions

What is a callback in recharge API?

It is a request the provider sends to your server with the final status of a transaction, so you do not have to keep checking pending recharges.

Can I use localhost as a callback URL?

No. The callback URL must be a public URL that the provider can reach over the internet.

What if I receive the same callback twice?

Update the order only if it is still PENDING. Then a repeated callback changes nothing.

Share this article
ClubApi Team

We build recharge, bill payment, AEPS and KYC APIs at Rechapi Private Limited and help businesses across India launch their own services.

Related articles