【发布时间】:2016-06-14 18:08:32
【问题描述】:
我正在使用 example provided 为使用 Stripe 进行支付的 iOS 应用程序实现我的后端,唯一的区别是我的应用程序只使用计划,而不是收费。我只是想知道plan creation code 在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”的新计划,还是只是将新客户绑定到现有计划?
【问题讨论】:
标签: ruby sinatra stripe-payments