This tutorial shows how to connect your PHP website or software to a recharge API. We use plain PHP and cURL — no framework needed — so it works on any shared hosting or VPS.
By the end you will be able to send a recharge, read the result, and handle slow (pending) transactions safely.
Before you start
- A ClubApi account with completed KYC (create one here)
- Your API token from Account → API
- Your server's public IP added in IP whitelist
- PHP 7.4 or newer with the cURL extension enabled
- The operator ID list from the API docs
Step 1: Create a table for your orders
Always save the order in your own database before calling the API. If something goes wrong, you will still know what you sent.
CREATE TABLE recharges (
id INT AUTO_INCREMENT PRIMARY KEY,
urid VARCHAR(40) NOT NULL UNIQUE,
mobile VARCHAR(15) NOT NULL,
operator_id INT NOT NULL,
amount DECIMAL(10,2) NOT NULL,
status VARCHAR(10) DEFAULT 'PENDING',
order_id VARCHAR(40) NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
The urid column is UNIQUE. This stops the same order from being saved twice.
Step 2: Send the recharge request
Create a file recharge.php:
<?php
// ----- settings -----
$token = "YOUR_TOKEN"; // from Account > API
$apiUrl = "https://api.clubapi.in/transaction.php";
// ----- order details (from your form) -----
$mobile = "9876543210";
$operatorId = "1";
$amount = "199";
$urid = "TXN" . time() . rand(100, 999); // your unique id
// TODO: save $urid, $mobile, $operatorId, $amount in your database here
// ----- call the API -----
$data = array(
"token" => $token,
"urid" => $urid,
"operatorId" => $operatorId,
"mobile" => $mobile,
"amount" => $amount
);
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$response = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
$result = json_decode($response, true);
Step 3: Handle the result
The response tells you the status. Handle all three cases:
if ($error != "" || $result == null) {
// network problem or timeout: we do NOT know what happened
$status = "PENDING";
} else {
$status = $result["status"]; // SUCCESS / PENDING / FAILED
}
if ($status == "SUCCESS") {
echo "Recharge successful";
} elseif ($status == "FAILED") {
echo "Recharge failed, amount not deducted";
} else {
echo "Recharge is being processed. You will get the final status soon.";
}
// TODO: update status (and orderId) in your database using $urid
Step 4: Receive the final status by callback
When a recharge is PENDING, ClubApi sends the final status to your callback URL as soon as the operator replies. Set the URL in Account → API → Callback, then update the order in your database when it arrives. Our recharge API callback guide has a complete, safe example.
Step 5: Test before going live
- Do a few small recharges on your own numbers.
- Check the result in your database and in Transaction History in your account.
- Turn off your internet in the middle of a request (or set a 1 second timeout) to test the PENDING path.
- Check that the callback updates the order.
Security checklist
- Keep the token on the server only — never put it in JavaScript or a mobile app.
- Whitelist only your own server IPs.
- Validate the mobile number (10 digits) and amount before calling the API.
- Use HTTPS for your website and callback URL.
- Regenerate the token immediately if you think it has leaked.
That is all you need for a working recharge integration. For all operators, error codes and other services, see the developer documentation.