【问题标题】:Firebase function is not triggeringFirebase 功能未触发
【发布时间】: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


【解决方案1】:

您能否检查在 fetch 中添加 await 或从支付功能中删除 async ?还有为什么要在支付函数调用中添加 setTimeout?

【讨论】:

  • 详细信息、语言、上下文和代码的 sn-p 包含在原始帖子@Haider Malik 中
  • 我尝试按照您的建议在 fetch 上添加 await 。它仍然不起作用。现在我正在考虑创建一个网页来进行付款并将应用程序中的网页与 Webview 链接。 @斯科特
猜你喜欢
  • 1970-01-01
  • 2021-11-27
  • 2020-10-20
  • 1970-01-01
  • 1970-01-01
  • 2018-08-28
  • 2023-03-03
相关资源
最近更新 更多