Ios 如何使用firebase云功能创建条带客户

Ios 如何使用firebase云功能创建条带客户,ios,firebase,stripe-payments,google-cloud-functions,Ios,Firebase,Stripe Payments,Google Cloud Functions,大家好,我是Stripe新手,所以我有一个关于如何通过firebase云功能创建Stripe客户的问题。我已经阅读了stripe标准集成和一些教程。问题在于,无论何时处理费用或输入金额,该示例都会创建customer。Stripe文档说,创建没有付款信息的客户用户是可以的。所以我的想法是,每当我为firebase创建user时,我都会触发cloud函数,同时创建stripe customer。有人能教我如何准确地做到这一点,并告诉我如何更新绑定到该客户的付款信息吗。非常感谢。这实际上是一个由两部

大家好,我是Stripe新手,所以我有一个关于如何通过firebase云功能创建Stripe客户的问题。我已经阅读了stripe标准集成和一些教程。问题在于,无论何时处理费用或输入金额,该示例都会创建customer。Stripe文档说,创建没有付款信息的客户用户是可以的。所以我的想法是,每当我为firebase创建user时,我都会触发cloud函数,同时创建stripe customer。有人能教我如何准确地做到这一点,并告诉我如何更新绑定到该客户的付款信息吗。非常感谢。

这实际上是一个由两部分组成的问题,但我认为这比你想象的要容易得多。下面是关于如何解决typescript中的问题的一些指导

创建客户

要创建客户,请通过create auth触发器执行以下操作:

export const syncUserToStripe = functions.auth.user().onCreate(async (data, context) => 
  const stripe = new Stripe(<stripe-token>); // Initialize the stripe SDK
  const stripeCustomer = await stripe.customers.create({
        email: data.email
  }); // Now you have the stripe customer. Maybe you would like to save the stripeCustomer Id to database/firestore
  console.log(`Done syncing firestore user with id: ${data.uid} to Stripe. The stripe id is ${stripeCustomer.id}`);
);
一般注意事项

  • 考虑您希望在后端存储哪些信息
  • <> LI>更新支付信息时,考虑使用Express与中间件相结合来验证/提取相关信息(这样就可以重用代码)
  • 对代码使用
    try catch
    ,以捕获意外错误
  • 请记住使用条带测试密钥执行所有操作。您可以在后端使用firebase函数配置环境来帮助实现这一点

    • 这实际上是一个由两部分组成的问题,但我认为这比你想象的要容易得多。下面是关于如何解决typescript中的问题的一些指导

      创建客户

      要创建客户,请通过create auth触发器执行以下操作:

      export const syncUserToStripe = functions.auth.user().onCreate(async (data, context) => 
        const stripe = new Stripe(<stripe-token>); // Initialize the stripe SDK
        const stripeCustomer = await stripe.customers.create({
              email: data.email
        }); // Now you have the stripe customer. Maybe you would like to save the stripeCustomer Id to database/firestore
        console.log(`Done syncing firestore user with id: ${data.uid} to Stripe. The stripe id is ${stripeCustomer.id}`);
      );
      
      一般注意事项

      • 考虑您希望在后端存储哪些信息
      • <> LI>更新支付信息时,考虑使用Express与中间件相结合来验证/提取相关信息(这样就可以重用代码)
      • 对代码使用
        try catch
        ,以捕获意外错误
      • 请记住使用条带测试密钥执行所有操作。您可以在后端使用firebase函数配置环境来帮助实现这一点

      感谢您的回复。但是,是否有可能制作一个只存储支付信息给该客户的功能呢。我不想做的付款尚未,但让用户选择存储卡供将来使用没有任何相关的付款在上述。您只需将支付信息(即信用卡)存储在sripe客户上,但这也是updatePaymentRight的一部分,这是我最困惑的部分。因为我不知道文档哦paymentTextDelete、addCardController或PaymentMethodController是否应该以这种方式使用。存储信用卡信息以备将来使用。@MaoLi我在“更新支付信息”部分向您展示的内容实际上存储了信用卡信息以备将来使用。谢谢您的回复。但是,是否有可能制作一个只存储支付信息给该客户的功能呢。我不想做的付款尚未,但让用户选择存储卡供将来使用没有任何相关的付款在上述。您只需将支付信息(即信用卡)存储在sripe客户上,但这也是updatePaymentRight的一部分,这是我最困惑的部分。因为我不知道文档哦paymentTextDelete、addCardController或PaymentMethodController是否应该以这种方式使用。存储信用卡信息以备将来使用。@MaoLi我在“更新支付信息”一节中向您展示的内容实际上存储了信用卡信息以备将来使用。