将 Stripe Plan Creation 放在 Sinatra 后端的什么位置
Where to put Stripe Plan Creation in Sinatra Backend
我正在为使用 Stripe 进行支付的 iOS 应用程序实施后端,使用 example provided, the only difference is my app uses only plans, not charges. I was just wondering where the plan creation code goes in web.rb。
是这样的吗:
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
时都会定义一个名为 'Amazing Gold Plan' 的新计划,还是只会将新客户绑定到现有计划?
所以我认为您真正想要做的只是创建一次计划,然后创建订阅。订阅是附加到客户的计划。计划本身实际上并没有做任何事情,但是一旦它们被用来创建订阅,它们就可以开始自动向您的用户收费。这有意义吗?
您可以通过仪表板 [1] 或 API [2] 创建您想要的计划。当您准备好使用它时,您可以在查看客户记录时或通过 API [3].
从仪表板内部创建订阅
在您的情况下,您可能会做的是将计划 ID(例如 gold
)存储在本地某处并使用该计划 ID 创建订阅,而不是计划本身。
希望对您有所帮助!
[1] https://dashboard.stripe.com/plans
我正在为使用 Stripe 进行支付的 iOS 应用程序实施后端,使用 example provided, the only difference is my app uses only plans, not charges. I was just wondering where the plan creation code goes in web.rb。
是这样的吗:
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
时都会定义一个名为 'Amazing Gold Plan' 的新计划,还是只会将新客户绑定到现有计划?
所以我认为您真正想要做的只是创建一次计划,然后创建订阅。订阅是附加到客户的计划。计划本身实际上并没有做任何事情,但是一旦它们被用来创建订阅,它们就可以开始自动向您的用户收费。这有意义吗?
您可以通过仪表板 [1] 或 API [2] 创建您想要的计划。当您准备好使用它时,您可以在查看客户记录时或通过 API [3].
从仪表板内部创建订阅在您的情况下,您可能会做的是将计划 ID(例如 gold
)存储在本地某处并使用该计划 ID 创建订阅,而不是计划本身。
希望对您有所帮助!
[1] https://dashboard.stripe.com/plans