当有人当前注册服务器时,他们点击一个计划,弹出一个带有条纹签出弹出窗口的弹出窗口(要求提供信用卡信息等)
如果有人正在更新他们的计划,我不需要显示条带检出弹出窗口 . 我如何确定客户不仅存在条纹,而且他们在条带系统中有信用卡,因此我可以更新/更改他们的计划,而无需要求他们重新输入他们的信用卡详细信息 .
我建议创建一个Stripe Customer并将Stripe客户ID存储在users表中 . 在这里,我假设您的客户/用户是 User 模型的一部分,并在数据库的 users 表中进行跟踪 .
User
users
Stripe文档有recipe用于创建Stripe客户 . 我们将在此处借鉴 .
首先,您需要将Stripe gem添加到Gemfile中 .
接下来,您需要运行迁移以将字符串列添加到名为 stripe_customer_id 的 users 表中 .
stripe_customer_id
接下来将以下内容添加到您的用户模型:
def get_or_create_stripe_customer!(stripe_token, stripe_email = nil) return self.stripe_customer_id if self.stripe_customer_id.present? stripe_email = self.email if stripe_email.nil? customer = customer = Stripe::Customer.create( :email => stripe_email, :source => stripe_token, ) self.update_attribute(:stripe_customer_id, customer.id) return customer.id end
从处理付款的控制器,您可以拨打电话
current_user.get_or_create_stripe_customer! params[:stripe_token], params[:stripe_email]
这将创建一个新的Stripe客户或检索Stripe客户ID . 注意:在此代码示例中, current_user 是表示登录用户的变量 .
current_user
您只需查询 current_user.stripe_customer_id.present? 即可确定客户是否有信用卡存档 . 您还可以使用 stripe_customer_id 创建未来费用 .
current_user.stripe_customer_id.present?
Stripe Charges documentation可以向您介绍有关创建Stripe客户的更多详细信息(即保留信用卡信息)以及使用Stripe客户ID创建新费用 .
您可以向customers表添加一个值为true或false的列,并且在创建客户时,它可以创建默认值false . 当确认客户卡存档时,该值可以更改为true .
2 回答
我建议创建一个Stripe Customer并将Stripe客户ID存储在users表中 . 在这里,我假设您的客户/用户是
User
模型的一部分,并在数据库的users
表中进行跟踪 .Stripe文档有recipe用于创建Stripe客户 . 我们将在此处借鉴 .
首先,您需要将Stripe gem添加到Gemfile中 .
接下来,您需要运行迁移以将字符串列添加到名为
stripe_customer_id
的users
表中 .接下来将以下内容添加到您的用户模型:
从处理付款的控制器,您可以拨打电话
这将创建一个新的Stripe客户或检索Stripe客户ID . 注意:在此代码示例中,
current_user
是表示登录用户的变量 .您只需查询
current_user.stripe_customer_id.present?
即可确定客户是否有信用卡存档 . 您还可以使用stripe_customer_id
创建未来费用 .Stripe Charges documentation可以向您介绍有关创建Stripe客户的更多详细信息(即保留信用卡信息)以及使用Stripe客户ID创建新费用 .
您可以向customers表添加一个值为true或false的列,并且在创建客户时,它可以创建默认值false . 当确认客户卡存档时,该值可以更改为true .