如何将一个对象从android应用程序传递到firebase云函数以完成Paypal支付功能?
我使用firebase云函数作为Paypal支付的服务器端。文档不易理解。 当我试图将一个对象从android应用程序发送到firebase云函数时,什么也没发生。我想我加错了。那么,我如何将一个对象从android应用程序传递到函数如何将一个对象从android应用程序传递到firebase云函数以完成Paypal支付功能?,android,firebase,paypal,google-cloud-functions,Android,Firebase,Paypal,Google Cloud Functions,我使用firebase云函数作为Paypal支付的服务器端。文档不易理解。 当我试图将一个对象从android应用程序发送到firebase云函数时,什么也没发生。我想我加错了。那么,我如何将一个对象从android应用程序传递到函数 public void payout(String PayerID,String paymentId) { // Create the arguments to the callable function. JSONObject postD
public void payout(String PayerID,String paymentId) {
// Create the arguments to the callable function.
JSONObject postData = new JSONObject();
try {
postData.put("PayerID", PayerID);
postData.put("paymentId",paymentId);
} catch (JSONException e) {
e.printStackTrace();
}
mFunctions
.getHttpsCallable("payout")
.call(postData)
.continueWith(new Continuation<HttpsCallableResult, Object>() {
@Override
public Object then(@NonNull Task<HttpsCallableResult> task)
throws Exception {
return null;
}
});
}
问题在于,在Android应用程序中,你调用了一个HTTPS可调用函数(通过
mFunctions.getHttpScalable(“payout”)
),但你的云函数不是HTTPS可调用函数,而是一个“简单”的HTTPS函数
HTTPS可调用函数的编写方式如下:
exports.payout = functions.https.onCall((data, context) => {
// ...
});
exports.payout = functions.https.onRequest((req,res)=> {
// ...
})
HTTPS函数的编写方式如下:
exports.payout = functions.https.onCall((data, context) => {
// ...
});
exports.payout = functions.https.onRequest((req,res)=> {
// ...
})
因此,您应该根据文档调整云功能的代码:
请注意,另一个选项可能是写入数据库(实时数据库或Firestore),并使用
onWrite
或onCreate
触发器触发云函数。这种方法的优点是您可以直接将付款信息保存在数据库中。但文档建议使用HTTP请求,而不是firstore或实时触发器。。查看此链接,它有PayPal集成文档是的,此示例使用HTTPS函数,但这只是执行代码的触发器。因此,您可以很好地使用任何其他云函数触发器,特别是HTTPS可调用函数触发器或后台触发器。您只需稍微修改代码即可读取从前端获取的数据。这条规则是否通用?即使对于paypal集成,您的最后一个问题实际上也太宽泛,无法正确回答。您应该根据需要选择云功能触发器。但可以肯定的是,使用不同的触发器,您可以在云功能中运行相同的业务逻辑。对于支付来说,唯一的限制是支付平台由托管环境(即,本例中的云功能服务)调用。