Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Stripe Ruby-按ID查找现有客户并添加计划_Ruby On Rails_Ruby_Stripe Payments - Fatal编程技术网

Ruby on rails Stripe Ruby-按ID查找现有客户并添加计划

Ruby on rails Stripe Ruby-按ID查找现有客户并添加计划,ruby-on-rails,ruby,stripe-payments,Ruby On Rails,Ruby,Stripe Payments,所以医生说: 创建客户后,应将其id存储在自己的数据库中,以便以后与stripe通信时可以引用 好的,很简单。我的问题是:如何通过客户ID找到客户? 更新如下所示: customer = Stripe::Customer.retrieve(id) 当我为我的一项服务注册新客户时,我会创建一个新的条带客户,但如果他们是现有客户,我想使用他们的现有帐户,只需添加一个计划。如何找到它们并添加新计划?我查看了文档和ruby gem,但没有找到答案。请帮忙?这里是有问题的方法 def social_si

所以医生说:

创建客户后,应将其id存储在自己的数据库中,以便以后与stripe通信时可以引用

好的,很简单。我的问题是:如何通过客户ID找到客户? 更新如下所示:

customer = Stripe::Customer.retrieve(id)
当我为我的一项服务注册新客户时,我会创建一个新的条带
客户
,但如果他们是现有客户,我想使用他们的现有帐户,只需添加一个计划。如何找到它们并添加新计划?我查看了文档和ruby gem,但没有找到答案。请帮忙?这里是有问题的方法

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

我相信这就是你如何创建一个计划,现在你有了你的客户

Stripe::Customer.create({
    :card => customer.id,
    :plan => your_plan,
    }, access_token
  )
查找客户:

customer = Stripe::Customer.retrieve(current_vendor.stripe_id) # pass in the persisted ID
创建计划的新订阅:

customer.subscriptions.create(plan: "social")

这些文件非常详尽,只是需要仔细研究并找到细节。顺便说一句,为一个客户添加多个订阅是Stripe.

的一个功能,它仍然调用create on
Stripe::customer
,不幸地创建了一个新客户。我找到了这个问题的答案,请在下面检查。另外,
:卡
应键入由
Stripe.js
创建的令牌,而不是客户id。在我的情况下,我使用
当前用户.Stripe\u id
,它可以工作。Rails不了解当前供应商是什么。@qyle是的,您应该使用存储条带id的对象/字段
current_vendor
是我正在开发的应用程序中的一个例子——您的应用程序可能会有所不同。