Firebase函数未触发



我使用expo-payments-st熟API支付安卓应用程序。Stripe支付API是从以下firebase函数调用的:

exports.payWithStripe = functions.https.onRequest((request, response) => {
stripe.charges.create({
amount: request.body.amount,
currency: request.body.currency,
source: request.body.token,
}).then((charge) => {
response.send(charge);
})
.catch(err =>{
console.log(err);
});
});

以下是调用firebase函数的客户端代码:

payment = async () => {
if (this.state.token) {
fetch(
"https://us-central1-<>.cloudfunctions.net/payWithStripe",
{
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: this.state.amount,
currency: "usd",
token: this.state.token.tokenId,
}),
}
)
.then((response) => response.json())
.then((responseJson) => {
if (
responseJson.status === "succeeded" &&
responseJson.paid == true
) {

this.setState({ status: "succeeded", loading: false });
}
console.log(responseJson);
})
.catch((error) => {
this.setState({ status: "failed", loading: false });
console.error(error);
});
}
};
doPayment = async () => {
const params = {
number: this.state.number,
expMonth: parseInt(this.state.expMonth),
expYear: parseInt(this.state.expYear),
cvc: this.state.cvc,
};
const token = await Stripe.createTokenWithCardAsync(params);
this.setState({ token: token, loading: true });
setTimeout(() => {
this.payment();
}, 5000);
console.log(token);
};

在测试模式下一切正常。但在将应用程序部署到Play商店后,不会触发Firebase功能。关于为什么会发生这种情况,有什么建议吗?同样,在不弹出expo的情况下,我还有什么其他选择可以从expo react android原生应用程序付款?

是否可以检查向fetch添加wait或从支付功能中删除async?为什么要在支付函数调用中添加setTimeout?

相关内容

  • 没有找到相关文章

最新更新