【问题标题】:Paystack Subscription with Google Cloud Functions使用 Google Cloud Functions 订阅 Paystack
【发布时间】:2023-04-03 03:32:01
【问题描述】:

我正在尝试将基于 Paystack 订阅的支付集成到使用 firebase 和谷歌云功能的反应应用程序中。我将节点、paystack 文档中的代码添加到我的云函数中。一旦我运行代码,我就会收到错误 ReferenceError: resp is not defined.

Paystack 文档供参考https://paystack.com/docs/payments/subscriptions/#create-a-subscription

exports.payment = functions.https.onCall((data) => {
    const params = JSON.stringify({
      "email": "customer@email.com",
      "plan": "PLN_xxxxxxxxx"
    })
    const options = {
      hostname: 'api.paystack.co',
      port: 443,
      path: '/transaction/initialize',
      method: 'POST',
      headers: {
        Authorization: 'Bearer SECRET_KEY',
        'Content-Type': 'application/json'
      }
    }
    const req = https.request(options, res => {
      let data = ''
      resp.on('data', (chunk) => {
        data += chunk
      });
      resp.on('end', () => {
        console.log(JSON.parse(data))
      })
    }).on('error', error => {
      console.error(error)
    })
    req.write(params)
    req.end()
})

谢谢

【问题讨论】:

    标签: node.js reactjs firebase


    【解决方案1】:

    在这一行:

    const req = https.request(options, res => {
    

    该参数称为res。然而,在随后的几行中,它似乎被误写为resp

    所以尝试将resp 换成res(反之亦然)。比如:

    const req = https.request(options, res => {
      let data = ''
      res.on('data', (chunk) => {
        data += chunk
      });
      res.on('end', () => {
        console.log(JSON.parse(data))
      })
    }).on('error', error => {
      console.error(error)
    })
    

    【讨论】:

    • 我的第一个想法就是这样,但官方文档另有说明,示例是从文档中复制的,这让我有点困惑......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-21
    • 2018-12-18
    • 2021-12-26
    • 2020-03-15
    • 2017-10-03
    • 2016-06-12
    • 2020-04-23
    相关资源
    最近更新 更多