PayPal is a online payments system that supports online money transfers. With the help of this guide you will be able to integrate intercom no time.
We have two different approaches available when implementing PayPal gateway:
Active Merchant is a gem extracted from Shopify.
- Support for multiple payment gateways
- Maintained by Shopify
- Doesn’t support REST API
I’d recommend Active Merchant only when your project is a shop and requires only simple payments.
Instructions for Active Merchant can be found here.
Official PayPal SDK
PayPal Ruby SDK uses REST API and is recommended and maintained by PayPal.
- Big capabilities
- Provided by PayPal
Use official PayPal Ruby SDK every time you need customized solution and single payment method (PayPal).
Install and configure gem following gem README instructions.
Familiarize yourself with simple usage guide.
How to use this SDK in Rails:
At first, create controller which handles main operations required to process payments:
It has four main actions for every step:
- index handles initial operations (this could be form with amount or simple PayPal button)
- notify handles payment object creation (it should have proper
return_url) and request to paypal for response with link to accept payment process
- done, this action is immediately invoked after redirect from paypal acceptance page. In this method we can finalize the whole transaction and additionally save record to our database
- cancel takes care of clients who reconsider their payment and cancel acceptance on paypal page
Good idea is to create a Service which handles some of SDK operations: