【发布时间】:2020-02-12 23:43:37
【问题描述】:
在 firebase 功能上,我需要从 Paypal 获取数据并做 4 件事:
1. returns an empty HTTP 200 to them.
2. send the complete message back to PayPal using `HTTPS POST`.
3. get back "VERIFIED" message from Paypal.
4. *** write something to my Firebase database only here.
我现在所做的有效,但我遇到了 (4) 的问题。
exports.contentServer = functions.https.onRequest((request, response) => {
....
let options = {
method: 'POST',
uri: "https://ipnpb.sandbox.paypal.com/cgi-bin/webscr",
body: verificationBody
};
// ** say 200 to paypal
response.status(200).end();
// ** send POST to paypal back using npm request-promise
return rp(options).then(body => {
if (body === "VERIFIED") {
//*** problem is here!
return admin.firestore().collection('Users').add({request.body}).then(writeResult => {return console.log("Request completed");});
}
return console.log("Request completed");
})
.catch(error => {
return console.log(error);
})
正如您所见,当我从 Paypal 获得最终 VERIFIED 时,我尝试使用 admin.firestore().collection('Users').. 写入数据库
我在编译时收到警告:
Avoid nesting promises
write 行。
在承诺的那个阶段我应该如何以及在哪里放置这个write?
【问题讨论】:
标签: node.js firebase google-cloud-functions