我试图在Stripe.create中显示我的对象(服务)的数量,但是,每当我用保存该数字的变量替换数字时,就会从Stripe中收到错误400。
我尝试用不同类型的变量替换数字,但似乎只有当我输入直接整数时它才有效。
@service_name = @service.name
@service_price = @service.price <-- {Tried this but doesn't work.}
@service_price = 9999 <-- {Tried this and it DOES work.}
require "stripe"
Stripe.api_key = Rails.application.credentials.stripe[:secret_key]
token = params[:stripeToken]
# Create a Customer:
customer = Stripe::Customer.create(
email: @email,
source: token,
)
# Charge the Customer instead of the card:
charge = Stripe::Charge.create({
amount: @service.price, <-- {This gives me an error}
currency: 'usd',
customer: customer.id,
description: @service_price <-- {But, this doesn't and it displays correctly}
})
每个服务都有一个价格,我希望它仅显示该特定关联服务的价格。
答案 0 :(得分:0)
尝试将@service_price = @service.price
替换为@service_price = @service.price.to_i
,它应该可以工作。 to_i
会将其转换为整数,然后再进行进一步处理!