Skip to content

Commit

Permalink
Payment example
Browse files Browse the repository at this point in the history
  • Loading branch information
mullwar committed May 19, 2017
1 parent a89f15b commit 2d41311
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/payment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const TeleBot = require('../');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');

bot.on('/start', (msg) => {

const inlineKeyboard = bot.inlineKeyboard([
[
bot.inlineButton('Take all my money!', {pay: true})
]
]);

return bot.sendInvoice(msg.from.id, {
title: 'My Test Invoice',
description: 'TeleBot loves payments!',
payload: 'telebot-test-invoice',
providerToken: 'PAYMENT_PROVIDER_TOKEN',
startParameter: 'pay',
currency: 'EUR',
prices: [
{label: 'Tea', amount: 125},
{label: 'For testing!', amount: 1250},
{label: 'Discount', amount: -120}
],
markup: inlineKeyboard
}).then(data => {
console.log('OK', data);
}).catch(error => {
console.log('ERROR', error);
});

});


bot.on('shippingQuery', (msg) => {
console.log('shippingQuery', msg);
});

bot.on('preShippingQuery', (msg) => {
console.log('preShippingQuery', msg);

const id = msg.id;
const isOk = true;

return bot.answerPreCheckoutQuery(id, isOk);

});

bot.on('successfulPayment', (msg) => {
console.log('successfulPayment', msg);

return bot.sendMessage(msg.from.id, `Thank you, ${msg.from.first_name}!`);

});

bot.connect();

0 comments on commit 2d41311

Please sign in to comment.