Firebase函数未被调用

尼亚姆·弗林(Niamh Flynn)

我正在尝试使用Firebase在我的Web应用程序中集成Stripe付款。我已从以下存储库中克隆了代码:https : //github.com/firebase/functions-samples/tree/master/stripe,并遵循了以下文档:https : //firebase.google.com/docs/use-案件/付款

通过阅读文档,我假设当客户通过Firebase身份验证登录时,其详细信息将添加到Firestore中的stripe_customer集合中。我意识到情况并非如此,因此手动添加了一个用户来测试保存卡功能。然后,我收到以下错误:“ stripe.confirmCardSetup目的秘密的值无效:值应为client_secret字符串。您指定了:未定义”

我对firebase有一个出色的计划,并进行了配置。通过遵循文档中的步骤,我认为这是可行的。抱歉,这个问题如此含糊,但似乎在每个角落我都遇到了另一个问题。是否有一些我很想念的东西正在阻止此代码正常工作?我正在尝试为朋友生意实现这一目标,并将其与Firebase混淆了。我在Angularjs中编码。非常感谢任何帮助!

这是创建客户功能的代码

exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => {
        const customer = await stripe.customers.create({ email: user.email });
        const intent = await stripe.setupIntents.create({
        customer: customer.id,
  });
  await admin.firestore().collection('stripe_customers').doc(user.uid).set({
    customer_id: customer.id,
    setup_secret: intent.client_secret,
  });
  return;
});

这是在控制器中被调用的代码:

const firebaseUI = new firebaseui.auth.AuthUI(firebase.auth());
const firebaseUiConfig = {
  callbacks: {
    signInSuccessWithAuthResult: function (authResult, redirectUrl) {
      // User successfully signed in.
      // Return type determines whether we continue the redirect automatically
      // or whether we leave that to developer to handle.
      return true;
    },
    uiShown: () => {
      document.getElementById('loader').style.display = 'none';
    },
  },
  signInFlow: 'popup',
  signInSuccessUrl: '/checkout.html',
  signInOptions: [
    firebase.auth.GoogleAuthProvider.PROVIDER_ID,
    firebase.auth.EmailAuthProvider.PROVIDER_ID,
  ],
  credentialHelper: firebaseui.auth.CredentialHelper.NONE,
  // Your terms of service url.
  tosUrl: 'https://example.com/terms',
  // Your privacy policy url.
  privacyPolicyUrl: 'https://example.com/privacy',
};
firebase.auth().onAuthStateChanged((firebaseUser) => {
  if (firebaseUser) {
    currentUser = firebaseUser;
    firebase
      .firestore()
      .collection('stripe_customers')
      .doc(currentUser.uid)
      .onSnapshot((snapshot) => {
        if (snapshot.data()) {
          customerData = snapshot.data();
          startDataListeners();
          document.getElementById('loader').style.display = 'none';
          document.getElementById('content').style.display = 'block';
        } else {
            console.warn(
              `No Stripe customer found in Firestore for user: ${currentUser.uid}`
            );
        }
      });
  } else {
    document.getElementById('content').style.display = 'none';
    firebaseUI.start('#firebaseui-auth-container', firebaseUiConfig);
  }
});
清洁豆

您提供的错误(如下所示)表明配置中的密钥没有被拉入代码中。如果您是在本地运行此程序,则在更改function:config值时,都需要运行以下命令。

 firebase functions:config:get > .runtimeconfig.json

查看有关如何在本地运行函数文档

错误

“ stripe.confirmCardSetup目的秘密的无效值:值应为client_secret字符串。您指定了:未定义”

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章