【发布时间】:2023-03-26 07:04:02
【问题描述】:
所以 Stripe 文档说:
一旦您创建了一个客户,您应该将其 id 存储在您自己的数据库中,以便您以后与 stripe 通信时可以参考它。
好的,很简单。我的问题是:如何通过 ID 找到客户? 像这样更新:
customer = Stripe::Customer.retrieve(id)
当我为我的一项服务注册新客户时,我会创建一个新的 Stripe Customer,但如果他们是现有客户,我想使用他们现有的帐户并简单地添加一个计划。如何找到它们并添加新计划?我查看了文档和红宝石宝石,但无法弄清楚。请帮忙?这是有问题的方法。
def social_signup
token = params[:stripe_token]
if current_vendor.stripe_id == nil
customer = Stripe::Customer.create(
:card => token,
:plan => 'social',
:email => current_vendor.email
)
current_vendor.update_attributes(stripe_id: customer.id)
else
customer = Stripe::Customer.retrieve(current_vendor.stripe_id)
# bill the customer's existing account for the added subscription
end
redirect_to :somewhere
end
【问题讨论】:
标签: ruby-on-rails ruby stripe-payments