forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment.js
55 lines (41 loc) · 1.27 KB
/
payment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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}
],
replyMarkup: 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();