ruby-on-rails - 付款页面刷新后出现无效的正整数 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 %>
解决方案
推荐阅读
- django - 能够让用户动态添加/编辑/删除表单字段吗?
- python - 重新排序数据框中的行以匹配另一个数据框中的行顺序
- spring-boot - sec:authentication 在 Spring Boot Security 中不起作用
- python - 如何在python函数中有多个arg参数
- python - 在python中,如何将两个非常大的列表与关联的计数列表组合成具有关联计数列表的单个列表?
- excel - 您可以在不嵌套的情况下对许多值使用 SUBSTITUTE 吗?
- python - FastAPI 取决于用例应用程序
- mlr3 - 如何从学习者那里获得 mlr3 重要性分数?
- jira - 如何使用 API 在 Jira 中为 sprint 中的项目添加时间戳或删除时间戳
- java - 使用 Optional (Java 8) 时获取异常 ClassCastException java.lang.Integer 不能强制转换为 java.lang.Long,否则不能