做 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 => 'seller_1316654707_biz@myurl.com',
: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