Pago por bot de Telegram - Pagos 2.0 - Sberbank + Telegraf + Node.js

Pagos 2.0 : el mensajero de Telegram ahora tiene la capacidad de aceptar pagos en cualquier chat, incluidos grupos y canales. Puede conectar su tienda a la plataforma por su cuenta, sin acuerdo con Telegram.









Y en este tutorial, crearemos un bot simple con Node.js en el marco Telegraf.js que puede aceptar dinero de un cliente y enviarlo a su cuenta a través de Sberbank.







Pagos 2.0







Pagos 2.0



Telegram 2017 . , .







8- , .







200 :







Pagos 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
      
      











comprobar bot







PROVIDER_TOKEN @SberbankPaymentBot



PROVIDER_TOKEN



merchantLogin



. -.







@BotFather /mybots



, .







Payments









Pagos













Pagos







Connect Live









Pagos







@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.







:







factura







facturaDetalle







Englishmoji







facturaDetalle







?



Telegraf







.







Campamento de JavaScript








All Articles