Firebase功能未触发

时间:2020-09-09 15:02:17

标签: android firebase react-native google-cloud-functions expo

我正在使用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进行付款的其他哪些方法,反应Android的本机应用程序?

1 个答案:

答案 0 :(得分:0)

您可以检查是否将等待添加到提取中或从付款功能中删除了异步功能?为什么还要将setTimeout添加到支付函数调用中?