Railscast 143(Paypal 安全)导致“我们无法解密证书 ID”。
进行 Railscast #143。代码如下。当我添加安全内容时,我得到“我们无法解密证书 ID”。发展中。当我把安全装置去掉后,它又恢复正常了。我用新证书等重做了整个过程几次。运气不好。
下一步要尝试什么?
我遇到了与这篇文章中完全相同的问题,它在生产中遇到了它,并且它神奇地开始工作:
在“购买这些”页面中:
<%= form_tag "https://www.sandbox.paypal.com/cgi-bin/webscr" do %>
<%= hidden_field_tag :cmd, "_s-xclick" %>
<%= hidden_field_tag :encrypted, @cart.paypal_encrypted("#{@url}/buy_these", payment_notifications_url) %>
<p><%= submit_tag "Buy these for #{number_to_currency(@cart.total_price)}" %></p>
在购物车.rb:
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
def paypal_encrypted(return_url, notify_url)
values = {
:business => '[email protected]',
:cmd => '_cart',
:upload => 1,
:return => return_url,
:invoice => id,
:notify_url => notify_url,
:cert_id => 'DVFY6JS476MR8'
}
things.each_with_index do |item, index|
values.merge!({
"amount_#{index+1}" => item.price,
"item_name_#{index+1}" => item.id,
"item_number_#{index+1}" => item.id,
"quantity_#{index+1}" => 1
})
end
encrypt_for_paypal(values)
end
Doing railscast #143. Code is below. When I add the security stuff, I get "We were unable to decrypt the certificate id." in development. When I take the security stuff out, it works peachy again. I've redone the whole process a couple times with new certificates and such. No luck.
Any ideas of what to try next?
I'm having exactly the same problem as in this posting, which experienced it in production and it magically started working:
Can't get PayPal Encrypted Website Payments to work in Rails
In "buy these" page:
<%= form_tag "https://www.sandbox.paypal.com/cgi-bin/webscr" do %>
<%= hidden_field_tag :cmd, "_s-xclick" %>
<%= hidden_field_tag :encrypted, @cart.paypal_encrypted("#{@url}/buy_these", payment_notifications_url) %>
<p><%= submit_tag "Buy these for #{number_to_currency(@cart.total_price)}" %></p>
In cart.rb:
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
def paypal_encrypted(return_url, notify_url)
values = {
:business => '[email protected]',
:cmd => '_cart',
:upload => 1,
:return => return_url,
:invoice => id,
:notify_url => notify_url,
:cert_id => 'DVFY6JS476MR8'
}
things.each_with_index do |item, index|
values.merge!({
"amount_#{index+1}" => item.price,
"item_name_#{index+1}" => item.id,
"item_number_#{index+1}" => item.id,
"quantity_#{index+1}" => 1
})
end
encrypt_for_paypal(values)
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我又重复了整个过程几次,它开始起作用了。还审查了类似于下一个答案的过程中的每个值。不幸的是,每当我切换部署平台时,我似乎都会遇到同样的问题。最终,它再次开始工作。
I repeated the entire process a few more times, and it started working. Also reviewed each value in a process similar to the next answer. Unfortunately, any time I switch deployment platforms, I seem to run into the same issue. And eventually, it starts working again.
我遇到了同样的问题,但问题与
paypal_cert.pem
文件(即 Paypal 的证书文件)有关。Paypal 在临时环境和实时环境中使用不同的证书。请检查
paypal_cert.pem
文件,您会看到第一行提到了它应该使用的环境。我使用以下代码
和两个文件
paypal_cert_prod.pem
和paypal_cert_sandbox .pem
每个环境一个。I faced the same issue but the issue was related to
paypal_cert.pem
file i.e. Paypal's certificate file.Paypal uses different certificates for staging and live environment. Please check
paypal_cert.pem
file and you would see first line mentioning the environment it should be used in.I use following code
with two files
paypal_cert_prod.pem
andpaypal_cert_sandbox.pem
one for each environment.由于我们在 paypal_encrypted 方法中对多个值进行加密,因此当同一过程中发生某些加密错误时,可能会出现此错误。
确保问题不是由加密错误引起的最好方法是,尝试从上述给定值哈希中一一删除键值对并发出付款请求。
Since we are encrypting a number of values in paypal_encrypted method, this error can arise when some encryption error occurs during the same process.
The best way to make sure that the issue is not because of the encryption error, try removing key-value pair one by one from the above given values hash and make payment request.