2014-10-01 50 views
3

所以條紋文檔說:條紋紅寶石 - 查找現有客戶的ID,並添加一個計劃

一旦你創建了一個客戶,你應該保存它的ID在自己的數據庫中,以便您可以參考一下吧稍後與條紋進行通信時。

好的,很簡單。我的問題是:我如何通過ID找到客戶? UPDATE這樣的:

customer = Stripe::Customer.retrieve(id) 

當我註冊爲我服務的一個新客戶創建一個新的條紋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 

回答

2

尋找客戶:

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的一項功能。

0

我相信這是如何創建一個計劃,現在你有你的客戶。

Stripe::Customer.create({ 
    :card => customer.id, 
    :plan => your_plan, 
    }, access_token 
) 
+0

仍然在'Stripe :: Customer'上調用create,很遺憾地創建一個新客戶。我找到了答案,下面檢查。此外,':card'應該鍵入由'Stripe.js'創建的標記,而不是客戶ID。 – settheline 2014-10-01 22:49:04