我的策略是:
我是如何尝试实现此目的的:
我创建了一个Users控制器并让它继承自RegistrationController:
devise_for :users, :controllers => { :registrations => 'users'}
我在保存用户后创建了一个回调:
after_save :set_stripe_customer_id
private
def set_stripe_customer_id
end
现在,我认为需要的是:
current_user.update_attribute(:stripe_id => ....
文档显示类似
的代码Stripe::Customer.create(
:description => "Customer for test@example.com",
:card => "tok_1046el4BfU4hLNTvxYcIz4rE"
)
事情是,我不希望我的顾客必须立即将他的卡片放入。虽然这不是什么大不了的事,但是我等到需要注册才能到达实际购买点。我的问题是,我需要让回调自动创建Stripe客户的最简单,最简单的代码是什么?
答案 0 :(得分:1)
Stripe::Customer.create
的所有参数都是可选的,因此您可以像以下几样做一些事情:
def set_stripe_customer_id
customer = Stripe::Customer.create
current_user.update_attributes :stripe_id => customer.id
end
然后再订购该客户,或根据需要更新各种详细信息。
虽然我会说这不是必要的。在您真正需要客户制作之前等待并没有真正的缺点(例如,因为他们正在订阅)。