Pembayaran bot Telegram - Pembayaran 2.0 - Sberbank + Telegraf + Node.js

Pembayaran 2.0 - Messenger Telegram sekarang memiliki kemampuan untuk menerima pembayaran dalam obrolan apa pun, termasuk grup dan saluran. Anda dapat menghubungkan toko Anda ke platform Anda sendiri, tanpa perjanjian dengan Telegram.









Dan dalam tutorial ini, kita akan membuat bot sederhana dengan Node.js pada framework Telegraf.js yang dapat menerima uang dari klien dan mengirimkannya ke akun Anda melalui Sberbank.







Pembayaran 2.0







Pembayaran 2.0



Telegram 2017 . , .







8- , .







200 :







Pembayaran 2.0







Telegram . , . Telegram, .







โ€“ Telegram . , , .







Telegram



Telegram @BotFather. /newbot



, , , . , Telegram



sber_pay_test_bot



.







newbot







, , BotFather โ€” ยซยป .







! .







Node.js



. .







:







mkdir sber_pay_test_bot && cd sber_pay_test_bot
      
      





:







npm init 
      
      





package.json



, , , , . enter









index.js



.







touch index.js    
      
      





Telegraf.js



C telegraf.js โ€” .







npm install telegraf@3.38 
      
      





dotenv



โ€” , .env



process.env.



, nodemon



โ€” , node.js node



.







npm install dotenv nodemon
      
      





package.json









"scripts": {
    "start": "nodemon index"
}
      
      





telegraf.js, .







const { Telegraf } = require('telegraf')
require('dotenv').config()

const bot = new Telegraf(process.env.BOT_TOKEN) //  ,   botFather

bot.start((ctx) => ctx.reply('Welcome')) //    /start
bot.help((ctx) => ctx.reply('Send me a sticker')) //    /help
bot.on('sticker', (ctx) => ctx.reply('')) //bot.on     ,      ,       
bot.hears('hi', (ctx) => ctx.reply('Hey there')) // bot.hears    ,    - "hi"
bot.launch() //  
      
      





.env



BOT_TOKEN



, @BotFather







BOT_TOKEN=''
      
      











npm run start
      
      











periksa bot







PROVIDER_TOKEN @SberbankPaymentBot



PROVIDER_TOKEN



merchantLogin



. -.







@BotFather /mybots



, .







Payments









Pembayaran













Pembayaran







Connect Live









Pembayaran







@SberbankPaymentBot



, merchantLogin



, -api



-operator



. : P71XXXXXXX21



.







SberbankPaymentBot







@BotFather , PROVIDER_TOKEN



.env









PROVIDER_TOKEN='41018XXXX:LIVE:XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
      
      





SberbankPaymentBot









index.js



:







const { Telegraf } = require('telegraf')
require('dotenv').config()

const bot = new Telegraf(process.env.BOT_TOKEN) //  ,   botFather

const getInvoice = (id) => {
  const invoice = {
    chat_id: id, //         
    provider_token: process.env.PROVIDER_TOKEN, //     @SberbankPaymentBot 
    start_parameter: 'get_access', //   .    ,        ยซยป,         ,      .   ,        URL      (  )  ,     .
    title: 'InvoiceTitle', //  , 1-32 
    description: 'InvoiceDescription', //  , 1-255 
    currency: 'RUB', //    ISO 4217
    prices: [{ label: 'Invoice Title', amount: 100 * 100 }], //  ,      JSON 100  * 100 = 100 
    photo_url: 'https://s3.eu-central-1.wasabisys.com/ghashtag/JavaScriptBot/Unlock.png', // URL    -.         .   ,   ,   .
    photo_width: 500, //  
    photo_height: 281, //  
    payload: { //   -,  , 1โ€“128 .     ,      .
      unique_id: `${id}_${Number(new Date())}`,
      provider_token: process.env.PROVIDER_TOKEN 
    }
  }

  return invoice
}

bot.use(Telegraf.log())

bot.hears('pay', (ctx) => { . //    ,    - "pay"
  return ctx.replyWithInvoice(getInvoice(ctx.from.id)) //   replyWithInvoice     
})

bot.on('pre_checkout_query', (ctx) => ctx.answerPreCheckoutQuery(true)) //      

bot.on('successful_payment', async (ctx, next) => { //     
  await ctx.reply('SuccessfulPayment')
})

bot.launch()
      
      





Telegraf replyWithInvoice telegram.sendInvoice.







. .







yarn start



.







pay



.







JavaScript Bot โ€” JavaScript, React Native, TypeScript.







:







faktur







invoiceDetail







Englishmoji







invoiceDetail







?



Telegraf







.







Kamp JavaScript








All Articles