加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 02:23:15 所属栏目:百科 来源:网络整理
导读:所以条纹文档说: Once you’ve created a customer,you should store its id in your own database so you can refer to it later when communicating with stripe. 好的,够容易的.我的问题是:如何通过他们的ID找到客户? 更新如下: customer = Stripe::C
所以条纹文档说:

Once you’ve created a customer,you should store its id in your own database so you can refer to it later when communicating with stripe.

好的,够容易的.我的问题是:如何通过他们的ID找到客户?
更新如下:

customer = Stripe::Customer.retrieve(id)

当我为我的某项服务注册新客户时,我创建了一个新的Stripe客户,但如果他们是现有客户,我想使用他们现有的帐户,只需添加一个计划.我如何找到它们并添加新计划?我查看了文档和ruby的宝石,但无法弄明白.请帮忙?这是有问题的方法.

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

解决方法

找客户:

customer = Stripe::Customer.retrieve(current_vendor.stripe_id) # pass in the persisted ID

创建计划的新订阅:

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

文档非常详尽,只需挖掘并找到具体细节.顺便提一下,为单个客户添加多个订阅是Stripe added in February of this year的一项功能.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读