2016-06-14 52 views
1

我爲我的iOS應用使用Stripe進行支付,使用example provided實施我的後端,唯一的區別是我的應用只使用計劃,而不是收費。我只是想知道plan creation codeweb.rb在Sinatra後端放置條紋計劃的地方

是這樣的:

post '/charge' do 

    # Get the credit card details submitted by the form 
    source = params[:source] || params[:stripe_token] || params[:stripeToken] 
    customer = params[:customer] 

    # Create the charge on Stripe's servers - this will charge the user's card 
    begin 
    Stripe::Plan.create(
     :amount => 2000, 
     :interval => 'month', 
     :name => 'Amazing Gold Plan', 
     :currency => 'usd', 
     :id => 'gold' 
    ) 
    rescue Stripe::StripeError => e 
    status 402 
    return "Error creating charge: #{e.message}" 
    end 

    status 200 
    return "Charge successfully created" 

end 

還是應該在計劃中的方法之外定義?我的意思是,這個問題是否會在每次調用post /charge時定義一個名爲「令人驚歎的黃金計劃」的新計劃,還是隻會將新客戶綁定到現有計劃?

回答

2

所以我認爲你實際想要做的只是創建一次計劃,然後創建一個訂閱。訂閱是附加到客戶的計劃。他們自己的計劃實際上並沒有做任何事情,但一旦他們用於創建訂閱,他們就可以開始自動向用戶收費。那有意義嗎?

您可以通過儀表板[1]或通過API [2]創建您想要的計劃。當您準備好使用它時,您可以在查看客戶記錄或通過API [3]時從儀表板內部創建訂閱。

在你的情況,你可能會做的是保存計劃ID(如:gold)在當地的地方,並創建使用該計劃的ID,而不是計劃本身認購。

希望有幫助!


[1] https://dashboard.stripe.com/plans

[2] https://stripe.com/docs/api#create_plan

[3] https://stripe.com/docs/api#create_subscription

+1

是的,我有點想念,說你可以在儀表板上的計劃的一部分。現在變得更有意義了。 – rigdonmr