【问题标题】:Where to put Stripe Plan Creation in Sinatra Backend将 Stripe Plan Creation 放在 Sinatra 后端的什么位置
【发布时间】:2016-06-14 18:08:32
【问题描述】:

我正在使用 example provided 为使用 Stripe 进行支付的 iOS 应用程序实现我的后端,唯一的区别是我的应用程序只使用计划,而不是收费。我只是想知道plan creation codeweb.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


    【解决方案1】:

    所以我认为您实际上想要做的只是创建一个计划,然后创建一个订阅。订阅是附加到客户的计划。它们自己的计划实际上并没有做任何事情,但是一旦它们用于创建订阅,它们就可以开始自动向您的用户收费。这有意义吗?

    您可以通过仪表板 [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

    【讨论】:

    • 是的,我有点错过了说您可以在仪表板中制定计划的部分。现在更有意义了。
    猜你喜欢
    • 1970-01-01
    • 2011-07-08
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 2015-04-21
    • 2013-11-16
    • 2012-11-25
    相关资源
    最近更新 更多