简体   繁体   中英

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.

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

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 ---> naveengoud-facilitator@gmail.com
Buyer account ---> naveengoud-buyer@gmail.com

-> 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(ie, facilitator) profile details and copy the API Credentials ie, 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 )

This link will help you to get better understanding on integration of Basic Checkout, Charge Credit Cards and Recurring Payments with paypal in Ruby On Rails application

http://www.gotealeaf.com/blog/basic-paypal-checkout-processing-in-rails

You can find solutions for following concepts,

1) Basic Checkout 2) Charge Credit Cards 3) Recurring Payments

Look at this for rails integration:

but also here, more in general (less related to Rails):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM