1

我正在研究支付网关集成,不得不调用订单 api。但我不断收到错误

{"error":{"code":"BAD_REQUEST_ERROR","description":"Please provide your api key for authentication purposes."}}

我的整个代码段

const functions = require('firebase-functions');
    var express = require('express');
    var cors = require('cors');
    var request = require('request');
    const crypto = require('crypto');
    var app = express();
    app.use(cors({origin:true}));

    app.post("/",(req,res)=>{
      const amount = req.body.amount;

    const key = '----insert your key here----';
    const key_secret = '----- insert key secret here ----';

      var options = { method: 'POST',
        url: 'https://api.razorpay.com/v1/orders',
        headers: 
        {
            Authorization: 'Basic' + new Buffer(key + ":" + key_secret).toString("base64")},     
        form: 
        { amount: amount,
          currency: 'INR',
          receipt: "Receipt #20",
          payment_capture : 1
        } 
        };

      request(options,  (error, response, body)=> {
          if (error) throw new Error(error);
          res.send(body);

        });
    })



    exports.razorpaymentApi = functions.region('asia-east2').https.onRequest(app);

我已经 用我原来的 api 密钥和秘密替换了keykey_secret 。你能告诉我哪里出错了。谢谢

4

2 回答 2

1

我将标题修改为

headers: 
    {
        "authorization" : "Basic xxxxMyEncodedString"
    },

这对我有用。

于 2019-09-25T09:12:13.343 回答
0

试试这个

"授权" = (new Buffer(key + ":" + key_secret, 'base64')).toString('utf8');

我参考了这个 https://www.dotnetcurry.com/nodejs/1231/basic-authentication-using-nodejs

于 2019-09-25T09:36:04.443 回答