【发布时间】:2020-09-09 15:02:17
【问题描述】:
我正在使用 expo-payments-stripe API 来支付 android 应用程序。并且从以下 firebase 函数调用 Stripe 支付 API:
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 react native app for android 付款?
【问题讨论】:
-
您没有收到任何错误信息吗?放置 crashlytics 消息或哨兵
-
如何触发你的云函数?您可以分享执行此操作的代码吗?另外,你怎么知道它没有被触发?您需要分享所有这些详细信息,以便我们了解您的问题。
-
我刚刚添加了触发firebase功能的客户端代码。另外,我知道 firebase 功能没有被触发,因为如果触发了该功能,那么它将显示在 firebase 功能日志控制台中。在测试模式下,firebase 函数日志控制台显示该函数已成功触发,但在实时模式下,它没有显示任何内容@Renaud Tarnec
-
不,我没有收到任何错误。调用 firebase 函数后,什么也没有发生。 @anthony willis muñoz
标签: android firebase react-native google-cloud-functions expo