我正在使用条纹宝石,并按照非常基本的设置对卡进行收费。我试图在成功处理费用后更改我的数据库中的一个字段。下面的代码没有将我的数据库的 :charge (布尔类型)字段更新为 1。
处理成功后,它会将用户重定向到 create.html.erb,但我将它们重定向到不同的路径,但无法成功找到如何做到这一点。
谢谢堆栈!
收费控制器:
class ChargesController < ApplicationController
def index
end
def new
end
def create
@event = Event.find(session[:event_id])
#Amount in cents
@amount = 199
customer = Stripe::Customer.create(
:email => "user email",
:card => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'description',
:currency => 'usd'
)
@event[:charge] == 1
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
end
新的.html.erb:
<ul class="breadcrumb">
<li><a href="#">Event Information</a></li>
<li><a href="#">Image Upload</a></li>
<li><a href="#">Verify Details</a></li>
<li class="active">Pay</li>
</ul>
<%= form_tag charges_path do %>
<article>
<label class="amount">
<span>Amount: $1.99</span>
</label>
</article>
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-description="description"
data-amount="199"></script>
<% end %>
创建.html.erb
<h2>Thanks, you paid <strong>$1.99</strong>!</h2>