Custom Pay button for Telegram bot - AARON SMITH TECH

Latest

Programming PHP tutorials for beginners. Technology and product reviews. Aaron Smith video tutorials for beginners.

sponsor

Friday, June 9, 2017

Custom Pay button for Telegram bot

telegram bot

Custom Pay button for Telegram bot

How to make custom pay button for Telegram bot invoice. You can type another text except Pay word. You can also add more button for Telegram bot invoice. 1 button must me button with pay function, another buttons can be links to web-site or start_parameter buttons. If you are not using pay button with custom name, under invoice will be showing button with Pay name.

telegram bot

You must include Pay => true to activate pay function, then you can rename button, just change TEXT field.
Telegram Bot PHP example

$chat_id = "*****"; // telegram chat id
$bot_id = "*****"; // telegram bot id
$stripe_token = "***"; // stripe token

$url = "https://api.telegram.org/$bot_id/sendInvoice";

$LabeledPrice = array(array('label' => "Nike Shoes", 'amount' => 1100));

$keyboard = array("inline_keyboard" => array(array(array("pay" => True,"text" => "Make A Payment"))));


$postfields = array(
'chat_id' => "$chat_id",
'title' => "NIKE SHOES",
'description' => "The best running shoes 2017",
'photo_url' => "https://2.bp.blogspot.com/-4EWBP3UEBDs/WTrJTwLVmMI/AAAAAAAAAk8/ZpbJ4c2WoocDpGtWL20n6TbcFYVq2pxZwCLcB/s320/1.png",
'photo_width' => 90,
'photo_height' => 50,
'payload' => "telebot-test-invoice",
'provider_token' => "$stripe_token",
'start_parameter' => "pay",
'currency' => "EUR",
'prices' => json_encode($LabeledPrice),
'reply_markup' => json_encode($keyboard)
);

print_r($postfields);

if (!$curld = curl_init()) {
exit;
}

curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curld, CURLOPT_URL,$url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec($curld);

curl_close ($curld);

How to make 2 or 3 buttons?

Repeat inline_keyboard Array of Array for each next button. 1 button must be pay button, 2 and other buttons can be links.
PHP example Telegram bot

$chat_id = "*****"; // telegram chat id
$bot_id = "*****"; // telegram bot id
$stripe_token = "***"; // stripe token

$url = "https://api.telegram.org/$bot_id/sendInvoice";

$LabeledPrice = array(array('label' => "Nike Shoes", 'amount' => 1100));

$keyboard = array("inline_keyboard" => array(array(array("pay" => True,"text" => "Make A Payment"),array("text" => "Go to web-site","url" => "www.google.com"))));


$postfields = array(
'chat_id' => "$chat_id",
'title' => "NIKE SHOES",
'description' => "The best running shoes 2017",
'photo_url' => "https://2.bp.blogspot.com/-4EWBP3UEBDs/WTrJTwLVmMI/AAAAAAAAAk8/ZpbJ4c2WoocDpGtWL20n6TbcFYVq2pxZwCLcB/s320/1.png",
'photo_width' => 90,
'photo_height' => 50,
'payload' => "telebot-test-invoice",
'provider_token' => "$stripe_token",
'start_parameter' => "pay",
'currency' => "EUR",
'prices' => json_encode($LabeledPrice),
'reply_markup' => json_encode($keyboard)
);

print_r($postfields);

if (!$curld = curl_init()) {
exit;
}

curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curld, CURLOPT_URL,$url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec($curld);

curl_close ($curld);

telegram bot telegram bot

https://www.facebook.com/chakabiz
https://www.youtube.com/channel/UCYuMRNb_SRZ4FMsZjnHRZUA

1 comment:

  1. Hello,
    If I have webhooked my Telegram Bot to API.AI, any idea what should the json format and content be for initiating the payment process ?
    I have been trying various combination without much success. I have even posted my query on Stackoverflow forum without any solution.
    if you could, can you please check my query over at stackoverflow (https://stackoverflow.com/questions/46128538/telegram-api-ai-payment-integration) and make any suggestion ?

    ReplyDelete