Mahmoud Moustafa
Mahmoud Moustafa

Reputation: 35

Getting Internal Server Error when trying to create a payment through PayPal

This is a "Now it's working now it's not" situation Everything was working just fine with PayPal sandbox and now it's giving me the following error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable 
to complete your request.

Please contact the server administrator, [email protected] and inform 
them of the time the error occurred, and anything you might have done that 
may have caused the error.

More information about this error may be available in the server error log.

this is my cart.rb

def paypal_url(return_url,notify_url)
  values = {
    :business => '[email protected]',
    :cmd => '_cart',
    :upload => 1,
    :return => return_url,
    :invoice => id,
    :notify_url => notify_url,
    :cert_id => "4VA2YEE757V8A"
  }
  shopping_cart_items.each_with_index do |item, index|
    values.merge!({
      "amount_#{index+1}" => (item.price_cents/100),
      "item_name_#{index+1}" => Product.find(item.item_id).name,
      "item_number_#{index+1}" => item.item_id,
      "quantity_#{index+1}" => item.quantity
    })
  end
  encrypt_for_paypal(values)
end

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

my redirecting view

<%= form_tag "https://www.sandbox.paypal.com/cgi-bin/webscr", :id => 
'checkoutform' do %>
  <%= hidden_field_tag :cmd, "_s-xclick" %>
  <%= hidden_field_tag :encrypted, 
  @cart.paypal_url("http://www.mywebsite.com", 
  payment_notifications_url(:secret => "secretcode")) %>
<% end %>

I went through everything step by step and I got nothing

Upvotes: 0

Views: 534

Answers (1)

Programmer Joe
Programmer Joe

Reputation: 114

I'm getting the same error from PayPal sandbox with an encrypted button. I did not change my code either and it was working two or three weeks ago. But now I get the same error as you. It looks like PayPal doesn't really care much about fixing their Sandbox. They put a low priority on it. I suggest you open a ticket with them. The only way they will address this if enough customers complain.

Upvotes: 1

Related Questions