【问题标题】:Telegram sendInvoice method is failing电报 sendInvoice 方法失败
【发布时间】:2022-08-15 02:09:04
【问题描述】:

你好堆栈溢出,所以当我用测试信用卡测试条带交易时。我收到“机器人预检超时”错误,并且无法成功执行测试的事务。条纹支付后我想看看成功的方法。这是我的源代码。

require(\"dotenv\").config();
const express = require(\"express\");
const axios = require(\"axios\");
const bodyParser = require(\"body-parser\");
const invoiceDescription = require(\'./constants\');

const { TOKEN, SERVER_URL, BOTTOKEN } = process.env;
const TELEGRAM_API = `https://api.telegram.org/bot${TOKEN}`;
const URI = `/webhook/${TOKEN}`;
const WEBHOOK_URL = SERVER_URL + URI;

const app = express();
app.use(bodyParser.json());

const init = async () => {
  const res = await axios.get(`${TELEGRAM_API}/setWebhook?url=${WEBHOOK_URL}`);
  console.log(res.data);
};

app.post(URI, async (req, res) => {
    console.log(req.body)
  let text = \"\", chatId = \"\", userObjectForTable = {}; 
  if(req.body.message?.chat?.id && req.body.message?.text){
        chatId = req.body.message.chat.id;
        text = req.body.message.text;
        await axios.post(`${TELEGRAM_API}/sendMessage`, {
            chat_id: chatId,
            text: text,
        });
    }
  if (text === \"/pay\") {
    const message = await axios.post(`${TELEGRAM_API}/sendInvoice`, {
      chat_id: chatId,
      title: `FinnessinPips`,
      description: invoiceDescription,
      payload: \"Invoice for payment\",
      provider_token: BOTTOKEN,
      currency: \"USD\",
      prices: [{ label: \"tax\", amount: 4000 }],
    });
    userObjectForTable = {
        date: new Date(message.data.result.date),
        username: message.data.result.from.username
    }
  }
  if(req.body.pre_checkout_query?.id){
    //save to sqlite
    console.log(\"saving to sqlite\", req.body)
    await axios.post(`${TELEGRAM_API}/sendMessage`, {
        chat_id: req.body.pre_checkout_query?.from.id,
        text: \"Successfully Payed private url is\",
    });
}
  return res.send();
});

app.listen(process.env.PORT || 5050, async () => {
  console.log(\"???? app running on port\", process.env.PORT || 5050);
  await init();
});

    标签: telegram


    【解决方案1】:

    在此处查看支付 API 中的“7. Pre-Checkout”部分:https://core.telegram.org/bots/payments#7-pre-checkout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-04
      • 2020-06-27
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 2010-10-06
      相关资源
      最近更新 更多