【问题标题】:Unable to create order id in firebase cloud functions for razorpay [firebase_functions/internal] internal无法在 razorpay [firebase_functions/internal] 内部的 firebase 云函数中创建订单 ID
【发布时间】:2021-11-03 06:36:43
【问题描述】:

我正在使用 node.js 在 firebase 中编写云函数,但我收到错误 [firebase_functions/internal] internal

我在 index.js 中的代码:-

const cors = require('cors')({origin: true});
const Razorpay = require('razorpay')
const instance = new Razorpay({
    key_id: 'my id',
    key_secret: 'my key'
})

exports.razorpayOrderId = functions.https.onCall(async(req, res) => {
    var options = {
      amount: 10000,
      currency: "INR",
    };
    try{
            instance.orders.create(options).then(order => console.log(order));
    }catch(e){
            console.log(e);
            res.status(403).send({error: 'error'});
    }
});

我在flutter中触发该功能的代码:-

HttpsCallable callable = FirebaseFunctions.instance.httpsCallable(
      'razorpayOrderId',
      options: HttpsCallableOptions(timeout: Duration(seconds: 5)),
    );
    try {
      final HttpsCallableResult result = await callable.call(
        <String, dynamic>{
          'message': 10000,
        },
      );
      print(result.data['response']);
    } catch (e) {
      print(e);
    }

【问题讨论】:

    标签: node.js firebase google-cloud-functions flutter-web razorpay


    【解决方案1】:

    您使用的是onCall() 函数而不是onRequest(),因此您必须通过返回数据/承诺而不是响应来终止该函数。 onCall() 有 2 个参数,通常命名为 datacontext,它们与 Express 中的 requestresponse 不同:

    exports.razorpayOrderId = functions.https.onCall(async (data, context) => {
    
      var options = {
        amount: 10000,
        currency: "INR",
      };
      
      try {
        const order = await instance.orders.create(options)
        return {data: order}
      } catch(e) {
        console.log(e);
        return { error: "Something went wrong" }
      }
    });
    

    你可以阅读更多关于documentation的区别

    【讨论】:

    • @DeepakLohmod 尝试重新安装节点模块并使用以下命令进行部署:firebase deploy --only functions --debug。然后分享调试日志。
    • 上传调试安全吗?喜欢它包含我的项目 ID、电子邮件等
    • @DeepakLohmod 您可以删除这些详细信息。只是不要删除任何错误,如日志
    猜你喜欢
    • 2022-07-25
    • 1970-01-01
    • 2018-03-16
    • 2021-07-09
    • 2020-04-09
    • 2019-09-03
    • 2019-11-26
    • 1970-01-01
    相关资源
    最近更新 更多