Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal integration Ruby on Rails

I've seen posts that you should use ActiveMerchant for PayPal integration, but I also found this on the PayPal website.I'm struggling with placing what in which file, since I'm totally new to RoR. So I was trying to integrate the PayPal, but am not sure where to place which code.

Should I use active merchant for PayPal integration, or is the Rest-API the best choice. I want people to fill out their username, pay and when successful they receive digital content. So there should be a call with a result and the username.

Do you have a link, step by step, at least including which code I should place in which file, so I get the basics of RoR better.

like image 507
Diego Avatar asked Sep 14 '13 05:09

Diego


People also ask

How do I integrate PayPal with Ruby on Rails?

Step 1: Create a plan using the PayPal API. Step 2: Update the last product in the database paypal_plan_name with the returned plan.id . Step 3: Add routes for PayPal subscription. Step 4: Handle create and execution in the PayPal service.

How do I integrate PayPal into my ecommerce website?

Standard PayPal integration This method allows you to add PayPal to all of your product pages and to your checkout process in 3 steps: Open the admin panel for your checkout on your shop or ecommerce platform. Select standard PayPal payments as a payment option. Add the access information for your PayPal account.

Does PayPal use flutter?

It utilizes Flutter Webview, to complete the payment process... "It's a Simple Spell But Quite Unbreakable".


2 Answers

Standard PayPal Integration with Rails app Active Merchant gem :

step 1:

-> add 'gem activemerchant' in  gem file

-> bundle install

step 2:

-> Go to "www.developer.paypal.com" and create an account(also known as Merchant Account) with US address details.

-> It will create two dummy test account for buyer and seller(alias facilitator) in "sandbox.paypal.com".

  Ex: 
     Seller account  --->  [email protected]
     Buyer account  --->  [email protected]
      
-> To see test accounts details Click on "Dashboard -> Accounts"

-> Now set the password for both test accounts by clicking on profile link

step 3:

-> Go to seller account(i.e, facilitator) profile details and copy the API Credentials i.e, Username, password and signature

  Ex:
    Username:  naveengoud-facilitator_api1.gamil.com
    Password:   VSPALJ5ALA5YY9YJ
    Signature:   AVLslxW5UGzEpaDPEK4Oril7Xo4IAYjdWHD25HhS8a8kqPYO4FjFhd6A

-> Set these API Credentials in "config/environments/development.rb" as follows, add the below code with API credentials

  config.after_initialize do  
ActiveMerchant::Billing::Base.mode = :test         
        ::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(  
             login: "merchant_api1.gotealeaf.com",  
            password: "2PWPEUKZXAYE7ZHR",  
            signature: "AFcWxV21C7fd0v3bYYYRCpSSRl31A-dRI5VpyF4A9emruhNYzlM8poc0"  
        )  
     end

step 4:

-> From here onward follow the Rails cast 145 episode(http://railscasts.com/episodes/145-integrating-active-merchant)

like image 109
Naveen Thonpunoori Avatar answered Sep 19 '22 04:09

Naveen Thonpunoori


I found the PayPal API documentation to be quite confusing. Also, my application requirements were not satisfied through the API, so I ended up with a rather simple solution.

The solution mainly consists of two components:

  1. PayPal buttons, which I generate on PayPal website and copy the HTML to my website
  2. PayPal IPN notifications, for which I have a simple handler on my website

This is how the whole solution works in detail

  1. For the user to make payments, I use the PayPal Buttons. For this, you just login to your PayPal business account and generate HTML code for buttons which you can copy and paste into your website.
  2. The user can click on these buttons, they will be redirected to PayPal website, they make payments and have a button to come back to your website.
  3. When the transaction is done (either success or failure), PayPal will inform you via PayPal IPN Notifications. I have implemented an IPN handler on my website, which was quite easy to do.
  4. By the time the user returns to my website, in most cases, I would have already got the IPN notification, hence I can show them a success message.
  5. In case the IPN got delayed, I tell the users that it will take a couple more minutes to update their balance and use AJAX to keep querying the server for updates.

Here are some useful references:

  1. PayPal Buttons
  2. Rail Casts on PayPal IPN
  3. If you need, you can also dynamically generate the buttons via the Button Manager API gem
like image 37
Rajesh Kolappakam Avatar answered Sep 21 '22 04:09

Rajesh Kolappakam