我有这样的订阅控制器: -
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 %>
答案 0 :(得分:0)
通过为不同的计划创建不同的控制器来解决它。