首页 > 解决方案 > 付款页面刷新后出现无效的正整数 Stripe Payments 错误

问题描述

嘿,伙计们,基本上在我填写付款信息后出现错误,我通过购物车进入付款页面,在我写下我的信息后,它似乎通过但最终显示该错误

class ChargesController < ApplicationController
  def new
    @cart = current_user.carts.where(status: 'pending').last
    @amount = @cart.deals.sum(&:final_cost)
  end

  def create
    @amount = (params[:final_cost].to_f*100).round
    customer = Stripe::Customer.create(
      email: params[:stripeEmail],
      source: params[:stripeToken]
    )

    charge = Stripe::Charge.create(
      customer: customer.id,
      amount: @amount,
      description: 'Rails Stripe customer',
      currency: 'usd'
    )

    rescue Stripe::CardError => e
    flash[:error] = e.message
    redirect_to new_charge_path
  end
end

收费/new.html.erb

<h1 class="title">Charges#new</h1>
<%= form_tag charges_path do %>
  <article>
    <% if flash[:error].present? %>
      <div id="error_explanation">
        <p><%= flash[:error] %></p>
      </div>
    <% end %>
    <label class="amount">
      <span>Amount: $<%= @amount %></span>
    </label>
  </article>
  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
          data-description="<%= "#{Rails.env}-#{@cart.id}" %>"
          data-amount="<%= @amount*100 %>"
          data-locale="auto">
  </script>
<% end %>


标签: ruby-on-railsrubystripe-paymentscredentials

解决方案


推荐阅读