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 => '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