59

尝试使用PayPal-node-SDK向 Paypal 的 API 发出请求

exports.requestPayment = functions.https.onRequest((req, res) => {
    return new Promise(function (fullfilled, rejected) {
        paypal.payment.create(create_payment_json, {}, function (error, payment) {
            if (error) {
                rejected(error);
            } else {
                console.log("Create Payment Response");
                console.log(payment);
                res.status(200).send(JSON.stringify({
                    paymentID: payment.id
                })).end();
                fullfilled(payment);
            }
        });
     });
});

但我不断收到错误:

Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

我尝试过的事情:

  1. 向完全不同的主机发出请求,仍然ENOTFOUND
  2. 包装请求cors(req,res, ()=>{...})
  3. 预置https://到主机

问题是什么?

4

5 回答 5

126

You'll need to be on a paid plan to make external API requests.

Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/

于 2017-03-14T00:29:28.607 回答
3

在我的情况下,我不得不等待,让发生的任何滞后都过去。现在又好了。

于 2019-10-22T19:47:34.857 回答
1

切换到 Firebase“Blaze”计划,其中包括Spark 计划的免费使用层,然后再产生任何费用。使用Blaze 定价计算器查看给定使用的费用。

前 5GB 的出站(出口)网络是免费的,这与“本机”Google Cloud Functions为您提供的相同。

于 2019-10-27T16:44:53.003 回答
1

您需要在管理员初始化中包含服务帐户。这为我解决了同样的问题

于 2019-08-27T23:36:29.260 回答
1

由于互联网较弱,我遇到了这个问题,请更改互联网连接。

于 2021-05-16T10:25:51.920 回答