Ios 如何使用firebase云功能创建条带客户
大家好,我是Stripe新手,所以我有一个关于如何通过firebase云功能创建Stripe客户的问题。我已经阅读了stripe标准集成和一些教程。问题在于,无论何时处理费用或输入金额,该示例都会创建customer。Stripe文档说,创建没有付款信息的客户用户是可以的。所以我的想法是,每当我为firebase创建user时,我都会触发cloud函数,同时创建stripe customer。有人能教我如何准确地做到这一点,并告诉我如何更新绑定到该客户的付款信息吗。非常感谢。这实际上是一个由两部分组成的问题,但我认为这比你想象的要容易得多。下面是关于如何解决typescript中的问题的一些指导 创建客户 要创建客户,请通过create auth触发器执行以下操作: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。有人能教我如何准确地做到这一点,并告诉我如何更新绑定到该客户的付款信息吗。非常感谢。这实际上是一个由两部
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函数配置环境来帮助实现这一点