RailsCasts Pro episodes are now free!

Learn more or hide this

Fan's Profile

GitHub User: fan-jin

Comments by Fan

Avatar

Thank you Ryan! After years this worked like a charm.

@VISHAL DEEPAK

A couple things I would suggest for you:

  • For redirecting to Paypal, my application's user flow is similar to yours; however, I would suggest using a form to send a POST request to the Paypal url instead of get as required by Paypal. You can use jquery to dynamically inject the form and submit and then remove it like so:
js.erb
$('<form action="<%= encrypted_paypal_url %>" method="post" target="_blank"></form>').appendTo('body').submit().remove();
  • You have an error because you're trying to parse a string to query (see my solution below)
  • For your url you only returned encrypted values and not the additional fields indicating to Paypal that this is encrypted. Following my approach above, you can return the url like so (append this to the end of paypal_url):
ruby
encrypted = {
      :cmd => "_s-xclick",
      :encrypted => encrypt_for_paypal(values)
    }
    "https://www.sandbox.paypal.com/cgi-bin/webscr?" + encrypted.to_query
Avatar

Thank you Ryan! After years this worked like a charm.

@VISHAL DEEPAK

A couple things I would suggest for you:

  • For redirecting to Paypal, my application's user flow is similar to yours; however, I would suggest using a form to send a POST request to the Paypal url instead of GET as required by Paypal. You can use jquery to dynamically inject the form and submit and then remove it like so:
js.erb
$('<form action="<%= encrypted_paypal_url %>" method="post" target="_blank"></form>').appendTo('body').submit().remove();
  • You have an error because you're trying to parse a string to query (see my solution below)
  • For your url you only returned encrypted values and not the additional fields indicating to Paypal that this is encrypted. Following my approach above, you can return the url like so (append this to the end of paypal_url):
ruby
encrypted = {
      :cmd => "_s-xclick",
      :encrypted => encrypt_for_paypal(values)
    }
    "https://www.sandbox.paypal.com/cgi-bin/webscr?" + encrypted.to_query