Get your API key from the Telegram bot: @ROYALBHARATPAYGATEWAYbot β π API Key.
Send your key in the X-API-KEY header (or an api_key field).
POST https://bharat.paycure.live/api/create.php β fields: amount (required), order_id, remark, redirect_url
curl -X POST https://bharat.paycure.live/api/create.php \ -H "X-API-KEY: YOUR_KEY" \ -d "amount=499" -d "order_id=ORD1001" \ -d "redirect_url=https://yoursite.com/thanks"
{
"success": true,
"token": "9f2c1a7b3d4e5f60",
"status": "pending",
"payment_url": "https://bharat.paycure.live/pay.php?t=9f2c1a7b3d4e5f60",
"amount": 499,
"pay_amount": 499,
"expires_at": 1790913728,
"upi_url": "upi://pay?pa=...",
"qr_url": "https://api.qrserver.com/..."
}Redirect your customer to payment_url. pay_amount may be a few paise higher than amount when another link for the same amount is open; the customer is shown the exact figure.
GET https://bharat.paycure.live/api/status.php?token=TOKEN or ?order_id=ORDER
Status is pending, success or failed.
Create returns qr_url (QR image) and upi_url. Your bot sends the QR; when the customer pays, we call your webhook and your bot confirms automatically. In our Telegram bot tap π€ Bot Integration β Get demo bot to download this file with your key and secret already filled in.
<?php
/**
* DEMO: Telegram bot that sells with automatic UPI payments (BharatPe Gateway).
*
* 1) Put your BOT_TOKEN (from @BotFather) below.
* 2) Upload this file to your hosting (HTTPS), e.g. https://yoursite.com/mybot/index.php
* 3) Open https://yoursite.com/mybot/index.php?setup=1 -> sets your Telegram webhook.
* 4) In the gateway bot: Webhook -> Set URL = https://yoursite.com/mybot/index.php
*
* Flow: customer taps a plan -> bot sends a QR -> customer pays -> the gateway calls this
* file (signed webhook) -> bot edits the QR message to "Paid" and delivers the product.
* "Check status" works as a fallback. Edit PLANS and deliver() to build your own bot.
*/
const BOT_TOKEN = 'PASTE_YOUR_BOT_TOKEN';
const FG_BASE = 'https://bharat.paycure.live';
const FG_KEY = 'YOUR_API_KEY';
const FG_SECRET = 'YOUR_WEBHOOK_SECRET';
const PLANS = ['Basic' => 49, 'Standard' => 99, 'Premium' => 199]; // name => price in INR
const TG_API = 'https://api.telegram.org';
const STORE = __DIR__ . '/orders_' . 'data.json'; // use a real database in production
function http($url, $opt = []) {
$ch = curl_init($url);
curl_setopt_array($ch, $opt + [CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 25]);
$r = curl_exec($ch); curl_close($ch);
return json_decode((string)$r, true) ?: [];
}
function tg($m, $p = []) {
return http(TG_API . '/bot' . BOT_TOKEN . '/' . $m, [CURLOPT_POST => 1, CURLOPT_POSTFIELDS => json_encode($p), CURLOPT_HTTPHEADER => ['Content-Type: application/json']]);
}
function fg($path, $post = null) {
$o = [CURLOPT_HTTPHEADER => ['X-API-KEY: ' . FG_KEY]];
if ($post !== null) { $o[CURLOPT_POST] = 1; $o[CURLOPT_POSTFIELDS] = http_build_query($post); }
return http(FG_BASE . $path, $o);
}
function orders() { return is_file(STORE) ? (json_decode(file_get_contents(STORE), true) ?: []) : []; }
function with_orders($fn) { // locked read-modify-write
$lock = fopen(STORE . '.lock', 'c'); flock($lock, LOCK_EX);
$d = orders(); $res = $fn($d); file_put_contents(STORE, json_encode($d), LOCK_EX);
flock($lock, LOCK_UN); return $res;
}
function deliver($o) { // <-- put your product / access delivery here
tg('sendMessage', ['chat_id' => $o['chat'], 'text' => "π Thank you! Your *{$o['label']}* is now active.\n(Replace this text with your link, key or file.)", 'parse_mode' => 'Markdown']);
}
function mark_paid($oid, $utr, $amount) {
$o = with_orders(function (&$d) use ($oid) {
if (!isset($d[$oid]) || !empty($d[$oid]['paid'])) return null; // unknown or already handled
$d[$oid]['paid'] = 1; return $d[$oid];
});
if (!$o) return false;
tg('editMessageCaption', ['chat_id' => $o['chat'], 'message_id' => $o['msg'], 'parse_mode' => 'Markdown',
'caption' => "β
*Payment received*\n\nAmount: βΉ{$amount}\nUTR: `{$utr}`\n\nYou have paid successfully.", 'reply_markup' => ['inline_keyboard' => []]]);
deliver($o);
return true;
}
function menu($chat) {
$rows = [];
foreach (PLANS as $n => $p) $rows[] = [['text' => "$n β βΉ$p", 'callback_data' => 'buy:' . $n]];
tg('sendMessage', ['chat_id' => $chat, 'text' => "π Welcome! Choose a plan to pay by UPI:\n(or send /pay 150 for a custom amount)", 'reply_markup' => ['inline_keyboard' => $rows]]);
}
function new_order($chat, $amount, $label) {
$oid = 'O' . $chat . '_' . time();
$r = fg('/api/create.php', ['amount' => $amount, 'order_id' => $oid, 'remark' => $label]);
if (empty($r['success'])) { tg('sendMessage', ['chat_id' => $chat, 'text' => 'β ' . ($r['message'] ?? 'Could not create payment, try again.')]); return; }
$res = tg('sendPhoto', ['chat_id' => $chat, 'photo' => $r['qr_url'], 'parse_mode' => 'Markdown',
'caption' => "π³ *$label*\nPay exactly *βΉ{$r['pay_amount']}* using any UPI app (scan this QR).\nβ± Valid for 15 minutes.\n\nβ‘ Payment is detected automatically.",
'reply_markup' => ['inline_keyboard' => [[['text' => 'π Check status', 'callback_data' => 'chk:' . $oid], ['text' => 'π Payment page', 'url' => $r['payment_url']]]]]]);
with_orders(function (&$d) use ($oid, $chat, $res, $r, $label) {
$d[$oid] = ['chat' => $chat, 'msg' => $res['result']['message_id'] ?? 0, 'token' => $r['token'], 'label' => $label, 'amount' => $r['pay_amount'], 'paid' => 0];
});
}
/* ---------- one-time setup ---------- */
if (isset($_GET['setup'])) {
$url = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . strtok($_SERVER['REQUEST_URI'], '?');
header('Content-Type: application/json'); echo json_encode(tg('setWebhook', ['url' => $url, 'allowed_updates' => ['message', 'callback_query']])); exit;
}
$raw = file_get_contents('php://input');
/* ---------- A) payment webhook from the gateway ---------- */
if (isset($_SERVER['HTTP_X_SIGNATURE'])) {
if (!hash_equals(hash_hmac('sha256', $raw, FG_SECRET), $_SERVER['HTTP_X_SIGNATURE'])) { http_response_code(401); exit('bad signature'); }
$ev = json_decode($raw, true);
if (($ev['event'] ?? '') === 'payment.success') mark_paid($ev['order_id'], $ev['utr'], $ev['paid_amount']);
echo 'ok'; exit;
}
/* ---------- B) Telegram updates ---------- */
$u = json_decode($raw, true);
if (!$u) exit('ok');
if (isset($u['message']['text'])) {
$chat = $u['message']['chat']['id']; $t = trim($u['message']['text']);
if (preg_match('#^/pay\s+(\d+(?:\.\d{1,2})?)#', $t, $m)) new_order($chat, $m[1], 'Custom payment');
else menu($chat);
} elseif (isset($u['callback_query'])) {
$cq = $u['callback_query']; $chat = $cq['message']['chat']['id']; $d = $cq['data']; $alert = null;
if (strpos($d, 'buy:') === 0 && isset(PLANS[substr($d, 4)])) { $n = substr($d, 4); new_order($chat, PLANS[$n], $n); }
elseif (strpos($d, 'chk:') === 0) {
$o = orders()[substr($d, 4)] ?? null;
if (!$o || $o['chat'] != $chat) $alert = 'Order not found';
elseif (!empty($o['paid'])) $alert = 'β
You have already paid for this order.';
else {
$r = fg('/api/status.php?token=' . $o['token']);
if (($r['status'] ?? '') === 'success') { mark_paid(substr($d, 4), $r['utr'], $r['paid_amount']); }
elseif (($r['status'] ?? '') === 'failed') $alert = 'β This payment link expired.';
else $alert = 'β³ Waiting for your paymentβ¦';
}
}
tg('answerCallbackQuery', ['callback_query_id' => $cq['id']] + ($alert ? ['text' => $alert, 'show_alert' => true] : []));
}
echo 'ok';
Set your URL in the bot (π Webhook). On success we POST JSON with header X-Signature = HMAC-SHA256 of the raw body using your webhook secret.
{
"event": "payment.success",
"token": "9f2c1a7b3d4e5f60",
"order_id": "ORD1001",
"amount": 499,
"paid_amount": 499,
"utr": "220796787681",
"remark": "",
"paid_at": 1790912828
}
$body = file_get_contents('php://input');
$sig = $_SERVER['HTTP_X_SIGNATURE'] ?? '';
$ok = hash_equals(hash_hmac('sha256', $body, 'YOUR_WEBHOOK_SECRET'), $sig);
if (!$ok) { http_response_code(401); exit; }
http_response_code(200);Reply with HTTP 2xx. Failed deliveries retry at 1m, 5m, 15m, 1h and 2h. For extra safety, confirm with the status endpoint before delivering goods.