Skip to main content

Testing Paypal Payments on Localhost

Turn off foreman.

Deal with ngrok​

Start by making sure you have ngrok...

npm install ngrok -g

start ngrok by doing the following command in a new terminal tab: ngrok http 3000

Copy the https forwarding url... should be something like: https://61f252aa.ngrok.io

Leave that terminal tab running

Update development.rb​

change the config.paypal_notify_url to use that ngrok. It should be something like this: https://61f252aa.ngrok.io/payment_notification/

Make sure your application.yml has a paypal_base_url PAYPAL_BASE_URL: 'https://www.sandbox.paypal.com/cgi-bin/webscr?'

Modify Procfile.dev​

In your Procfile.dev, comment out: web: bundle exec thin start --ssl

Uncomment: #web: bundle exec thin start --timeout 60

and then restart foreman

NOTE. When the server comes back up, use http, not https for localhost. This is necessary for the paypal responses to come through correctly.

Update AppFormResponseController​

In app_form_response_controller.rb uncomment this line and update the ngrok url with the one you copied earlier: params[:paypal_data]['notify_url'].gsub!('https://localhost:3000', 'https://61f252aa.ngrok.io')

Now you should be able to locally test paypal things and get a response token which will do things like trigger form builder email responses after a payment.