繁体   English   中英

Firebase 功能未触发

[英]Firebase function is not triggering

我正在使用 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,我还有什么其他选择可以从 expo react native app for android 付款?

您可以检查在 fetch 中添加 await 或从支付功能中删除 async 吗? 另外,您为什么将 setTimeout 添加到支付函数调用中?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM