Telegram make invoice PHP script - AARON SMITH TECH

Latest

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

sponsor

Sunday, May 28, 2017

Telegram make invoice PHP script


Telegram make invoice PHP script

You can make payments only from mobile devices.
How to make telegram invoice for Telegram bot payments. With this script you can send invoice to telegram user with simple request. To make invoice you have to make Bot and get Stripe Toke for telegram bot.
Instruction how to get Telegram provider token for Stripe: http://aaronsmith-tech.blogspot.com/2017/05/payments-provider-token-for-telegram.html

Telegram bot payments

numbers for telegram verification: https://www.facebook.com/chakabiz/posts/848623458622948

$botid = "********"; telegram bot id
$chat_id = "********"; // telegram chat id
$stripe_id = "********"; // stripe token for telegram bot, example for test 784643563:TEST:ZWI5ZDsdfUyNzM2

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

$LabeledPrice = json_encode(array(array('label' => "33", 'amount' => 11000)));

$postfields = array(
'chat_id' => "$chat_id",
'title' => "nike shoes",
'description' => "The best running shoes 2017",
'payload' => "telebot-test-invoice",
'provider_token' => "$stripe_id",
'start_parameter' => "pay",
'currency' => "EUR",
'prices' => $LabeledPrice
);

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);




Enter test Stripe card number, example 4242 4242 4242 4242 (with any date, name and country)


Press Done button, then Pay.

If you not set-up answerPreCheckoutQuery you will receive this message : An error occurred while processing your payments. Your card has not been billed.
How to resolve this? Simple just complete this function
With 1 method you will generate you will generate Temporal pre_checkout_query ID in your telegram webhook.

https://api.telegram.org/botID/getUpdates
https://api.telegram.org/botID/answerPreCheckoutQuery?pre_checkout_query_id=$pre_checkout_query&ok=true
Copy this pre_checkout_query ID and complete payment automatically.

or take pre_checkout_query from Json webhook


$pre_checkout_query = "********"; telegram Pre Checkout Query id
$botid = "********"; // telegram bot id

$url = "https://api.telegram.org/$botid/answerPreCheckoutQuery";

$postfields = array(
'pre_checkout_query_id' => "$chat_id",
'ok' => "True"
);

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);

Done. Now you will see complete message * You have just successfully transferred €11,00 to Telegram_bot for nike shoes with Receipt.



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

1 comment:

  1. Помогите пожалуйста со второй частью кода с PreCheckoutQuery
    $pre_checkout_query = $update["update_id"]["pre_checkout_query"]["from"]["id"];
    Правильный ли это способ получить id через Webhook

    ReplyDelete