curl req进入firebase函数req

时间:2018-04-27 12:59:38

标签: node.js firebase curl google-cloud-functions

您好我按照说明从Adyen实施加密付款。我使用Firebase作为我的后端。现在Dokumentation希望我像这样做一个后端req:

 curl -u "ws@Company.SomeCompany":"SomePassword" \ 
   -H "Content-Type: application/json" \
    -X POST \ 
   --data \ 
   '{
           "additionalData": {
               "card.encrypted.json":"adyenjs_0_1_4p1$..."
           },

           "amount" : {
               "value" : 10000,
               "currency" : "EUR"
           },

           "reference" : "Your Reference Here",
           "merchantAccount" : "TestMerchant"    }'\
    https://pal-test.adyen.com/pal/servlet/Payment/v30/authorise

有人可以帮助我将此curl请求转换为firebase函数请求吗?例如:

exports.helloWorld = (req, res) => {

  if (req.body.message === undefined) {
    // This is an error case, as "message" is required
    res.status(400).send('No message defined!');
  } else {
    // Everything is ok
    console.log(req.body.message);
    res.status(200).end();
  }
};

1 个答案:

答案 0 :(得分:1)

您需要将您的Adyen凭据作为http post请求中的数据传递。在Authroization令牌中添加firebase用户令牌作为Bearer令牌。所以现在你的功能将是:

 exports.helloWorld = (req, res) => {
       // check authorization of firebase.
   if (!req.headers.authorization || !req.headers.authorization.startsWith('Bearer ')) {
            res.status(403).send('Unauthorized');
            return;
   }
   const idToken = req.headers.authorization.split('Bearer ')[1];
   this.admin.auth().verifyIdToken(idToken).then(decodedIdToken => {
     // new read the data like below
    //  req.body.username , req.body.additionalData
  })

};