简体   繁体   English

Firebase 功能未触发

[英]Firebase function is not triggering

I am using expo-payments-stripe API for the payment of an android app.我正在使用 expo-payments-stripe API 来支付一个 android 应用程序。 And Stripe payment API is getting called from the following firebase function:并且从以下 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);
        });

});

Here is the code for the client-side that calls the firebase functions:这是调用 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);
  };

Everything works fine in the test mode.在测试模式下一切正常。 But after deploying the app to the Play store Firebase function is not triggered.但是在将应用部署到 Play 商店后,Firebase 功能不会被触发。 Any suggestions on why this might be happening?关于为什么会发生这种情况的任何建议? Also without ejecting expo what other options do I have to make payments from expo react native app for android?另外,如果没有弹出 expo,我还有什么其他选择可以从 expo react native app for android 付款?

Can you check adding await to the fetch or removing async from the payment function?您可以检查在 fetch 中添加 await 或从支付功能中删除 async 吗? Also why did you add setTimeout to the payment function call?另外,您为什么将 setTimeout 添加到支付函数调用中?

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

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