处理条纹电荷后更新充电字段

时间:2013-08-19 22:03:28

标签: ruby-on-rails stripe-payments

我正在使用条纹宝石,并按照非常基本的设置为卡充电。我正在尝试在成功处理费用后更改我的数据库中的字段。以下代码不会将我的数据库的:charge(boolean type)字段更新为1。

处理成功后,它会将用户重定向到create.html.erb,但我将它们重定向到不同的路径,但无法成功找到如何执行此操作。

谢谢Stack!

充电控制器:

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

New.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 %>

Create.html.erb

<h2>Thanks, you paid <strong>$1.99</strong>!</h2>

0 个答案:

没有答案