yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.17k stars 1.5k forks source link

[Question] Invoice and Payments #1050

Closed KoldaN1 closed 1 year ago

KoldaN1 commented 1 year ago

Hello everyone. I need an example of working with payments in a bot. I've seen an example here, but it's 2018, and therefore, most likely, is no longer relevant, and therefore I need to know how to work with them now. I can send the payment, but I have no idea how to process and receive it. I will be grateful for your help

INVISIBLE5130 commented 1 year ago

Hi!

First of all, I created the invoice(async):

await bot.sendInvoice( chatId, title, "InvoiceDescription", ${chatId}_${Number(new Date())}, process.env.LIQPAY_TEST, currency, [ { label: title, amount: amount, }, ] );

After I am listening pre_checkout_query and getting invoice id and putting it inside answerPreCheckoutQuery:

bot.on("pre_checkout_query", (msg) => { bot.answerPreCheckoutQuery(msg.id, true); });

And finally, I am listening successful_payment and getting there all data from payment, for example:

bot.on("successful_payment", async (msg) => { const receiptId = msg.successful_payment.provider_payment_charge_id; *you can do smth with this receiptId });

Mubashir-19 commented 1 year ago

Hi!

First of all, I created the invoice(async):

await bot.sendInvoice( chatId, title, "InvoiceDescription", ${chatId}_${Number(new Date())}, process.env.LIQPAY_TEST, currency, [ { label: title, amount: amount, }, ] );

After I am listening pre_checkout_query and getting invoice id and putting it inside answerPreCheckoutQuery:

bot.on("pre_checkout_query", (msg) => { bot.answerPreCheckoutQuery(msg.id, true); });

And finally, I am listening successful_payment and getting there all data from payment, for example:

bot.on("successful_payment", async (msg) => { const receiptId = msg.successful_payment.provider_payment_charge_id; *you can do smth with this receiptId });

I am trying to do the same with Stripe test secret key, but its not working.