【问题标题】:How do I implement different plans with Stripe on Rails如何使用 Stripe on Rails 实施不同的计划
【发布时间】:2016-04-06 14:18:18
【问题描述】:

我有这样的订阅控制器:-

class SubscribeController < ApplicationController
  before_filter :authenticate_client!

  def new
  end

  def update
    #gets the credit card details submitted in the form
    token    = params[:stripeToken]

    #create a customer
    customer = Stripe::Customer.create(
      card:  token,
      plan:  111,
      email: current_user.email,
    )

    current_client.subscribed = true
    current_client.stripeid   = customer.id
    current_client.plan_id    = 111
    current_client.save

    redirect_to root_path, notice: "Your subscription was set up successfully!"
  end
end

这里 111 是我的基本计划 ID。

现在,我想将它用于不同的支付方式,比如基本和高级。例如,如果用户单击一个按钮,他应该能够支付基本费用,例如 10 美元,如果他单击高级费用,他必须能够支付高级费用,例如 20 美元。

我的看法是这样的:-

#views/subscirbe/new.html.erb
<div class="container">
    <div class="row">
        <div class="col-md-6 col-md-offset-3 panel panel-default form-style">
            <div class="panel-body">
                <h2>Final Signup Step</h2>
                <h4>This is the final step to give you full access to PinAuth Services</h4>  
                <%= render 'form' %>
            </div>
        </div>
    </div>
</div>

和我的 _form.html.erb 一样

    <%= form_tag subscribe_path(1), method: :put do %>


<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
          data-description="A month's subscription"
          data-amount="2900"></script><span> $29 per month, cancel at any time.</span>
<% end %> 

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-4 stripe-payments


【解决方案1】:

通过为不同的计划创建不同的控制器来解决它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-09
    • 2016-04-10
    • 2021-05-04
    • 2017-12-05
    • 2019-08-08
    • 1970-01-01
    • 2011-01-31
    • 2017-04-12
    相关资源
    最近更新 更多