【发布时间】: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 %>
【问题讨论】:
-
另外,这看起来很有帮助youtube.com/watch?v=hyEsiwc0ys4
-
@Abram,我之前尝试过那个 youtube 链接。谢谢。我通过为不同的付款方式创建不同的控制器解决了这个问题。
标签: ruby-on-rails ruby ruby-on-rails-4 stripe-payments