【发布时间】:2023-03-07 00:13:01
【问题描述】:
我正在尝试计算付款表单的哈希值,但出现错误:
Fixnum 没有隐式转换为字符串
所以我解释说我正在尝试对什么是文本进行数学计算。但是我应该如何更正我的代码呢?
支付商家的说明是:
hash = SHA1(salt + "|" + description + "|" + amount + "|" + currency + “|” + 交易类型)
所以在我的控制器中我有:
def checkout
@organization = Organization.new(organizationnew_params)
if @organization.save
@organization.members.each do |single_member|
single_member.send_activation_email
end
@amount = 100.00
@currency = "EUR"
@description = @organization.id
@transaction_description = "My description"
@transaction_type = "S"
### LINE BELOW HAS THE HASH, WHICH REFERS TO THE PRIVATE METHOD BELOW ###
@hash = hash(@description, @amount, @currency, @transaction_type)
render 'checkout'
else
render 'new_premium'
end
end
private
def hash(description, amount, currency, transaction_type)
@hash = SHA1(SALT + "|" + description + "|" + amount + "|" + currency + "|" + transaction_type)
end
在初始化程序中,我定义了SALT(以及我的merchant_id,它在结帐视图中发布给商家的表单中使用)。
【问题讨论】:
-
您的金额和描述是浮点数/整数
标签: ruby-on-rails ruby ruby-on-rails-4 hash