Take the 2-minute tour ×

I need to get Transaction data(date, valued) and user adata.Can I use this gem with some modifications as in this question?

Also, from documentation:

For example, if you plan to query PayPal using getBasicPersonalData and getAdvancedPersonalData, you might generate a merchant model like:

rails generate paypal_permissions merchant email:string first_name:string last_name:string full_name:string country:string payer_id:string street1:string street2:string city:string state:string postal_code_string phone:string birth_date:string 
bundle exec
rake db:migrate

I should use Payment Data Transfer (PDT) or TRANSACTION_DETAILS? It is place,where I will write data, but how I can get data from PayPal ?

Can anyone give me example of code ?

share|improve this question
I reccomend you to try to make it on your own. Write your OWN action, which will be sending request and receive response. I tried different gem and understood, that it is hard to understand them. If you need help - I can show you my request. Write me if you need help. P.S. Are you from Ukraine ? –  DenMed Oct 12 '12 at 6:27
Can you try this gem : paypal_adaptive ? Copied from- stackoverflow.com/questions/11389726/… –  Sreekesh Okky Oct 16 '12 at 4:57

1 Answer 1

Paypal Adaptive seems to be the way to go on this, here are some documentation I found, hope it helps.

PayPal Adaptive with Rails 3

As usual the PayPal documentation is quite messy and disorganised and thus I thought I’d document how I managed to get PayPal Adaptive working on a marketplace style website.


Please use this post as a guide as to how the paypal API connects with your rails app. As Jamesw in the comments below points out, I have not created an adequate way of recording all details of each transaction; something that is no doubt required by law. So perhaps take a look at his comment after reading this. Hopefully you can work out a way to do this


After some searching I found that the best gem to use right now is paypal_adaptive. ActiveMerchant currently does not support PayPal Adaptive (there is a gem that add’s it in but it does not seem to be maintained.)

# Gemfile
gem 'paypal_adaptive'

How it works

PayPal Adaptive is relatively simple, yet the messy documentation can make it appear daunting. Put simply, this is how I did it:

  1. create paypal_adaptive.yml in your config folder and add your details
  2. create a resource to handle payments – I created a “Purchases” resource (model: Purchase)
  3. when the user clicks a buy button it invokes an action I called “buy” in my PurchasesController
  4. in the “buy” action I firstly create a new Purchase item (Purchase.new) and then add in some details like user_id, product_id, amount etc.
  5. I then invoke a model method called “pay” on my newly created Purchase object (purchase.pay)
  6. in my Purchase model I define the “pay” method and inside it I finally make use of the paypal_adaptive gem by creating its Request class (PaypalAdaptive::Request.new)
  7. I add all the necessary data I want to ship off to PayPal into a hash, and then invoke the Request.pay method, passing in that hash of data. This makes an API call to PayPal, who then replies with a confirmation that this request is successful
  8. If the API call is successful I redirect the user off to PayPal to sign in and confirm the payment
  9. Once the user makes the payment, PayPal sends an IPN (instant payment notification) to your specified IPN address – which I routed to a method in my PurchasesController
  10. In this method, I find the the Purchase object and mark it as paid (purchase.paid = true) and then it’s done!


Go here to create a sandbox account (you will need it). Once logged in go to “Create a preconfigured account”. Create two accounts – one buyer and one seller. If you are using chained or parallel payments (payments that are split amongst more than one person) then create some more accounts.

Click on Api Credentials in the left hand side panel.

Now fill out your paypal_adaptive.yml using those credentials (also use the application_id I provide below – this is the testing application_id provided by www.x.com

  environment: "sandbox"
  username: "platts_xxxxxxxx_biz_api1.gmail.com"
  password: "xxxxxxxxxxxx"
  signature: "xxxxxxx"
  application_id: "APP-80W284485P519543T"

  environment: "sandbox"
  username: "platts_xxxxxxxx_biz_api1.gmail.com"
  password: "xxxxxxxx"
  signature: "xxxxxxxx"
  application_id: "APP-80W284485P519543T"

  environment: "production"
  username: "my_production_username"
  password: "my_production_password"
  signature: "my_production_signature"
  application_id: "my_production_app_id"

Create controller action to handle a buy request

Here you only really need the amount of money to be paid and a list of the emails you want that money to go to. So write your logic to work that out and then make a call to PayPal to setup the purchase.

pay_request = PaypalAdaptive::Request.new
    data = {
      "returnUrl" => return_url,
      "requestEnvelope" => {"errorLanguage" => "en_US"},
      "currencyCode" => "USD",
      "receiverList" =>
              { "receiver" => [
                {"email" => "platts_xxxxxxxx_biz@gmail.com", "amount"=> amount}
      "cancelUrl" => cancel_url,
      "actionType" => "PAY",
      "ipnNotificationUrl" => ipn_url

    #To do chained payments, just add a primary boolean flag:{“receiver”=> [{"email"=>"PRIMARY", "amount"=>"100.00", "primary" => true}, {"email"=>"OTHER", "amount"=>"75.00", "primary" => false}]}

    pay_response = pay_request.pay(data)

    if pay_response.success?
        # Send user to paypal
        redirect_to pay_response.approve_paypal_payment_url
        puts pay_response.errors.first['message']
        redirect_to "/", notice: "Something went wrong. Please contact support."

Handling the IPN call

I route my IPN call from PayPal to this method:

def ipn_notification
    ipn = PaypalAdaptive::IpnNotification.new

    if ipn.verified?
      logger.info "IT WORKED"
      logger.info "IT DIDNT WORK"

    render nothing: true

Unfortunately if you are on localhost, PayPal can’t send you the IPN, and hence there is a problem with testing this whole process. Ryan Bates’ solution is to use curl to mimic an IPN request. However as you can see in the code above, we make another request to PayPal confirming that the IPN is real. So even with curl sending a fake IPN, we run into problems. I’m going to go hunt for solutions now, but please comment if you have any ideas.

share|improve this answer
I wrote this app a while back, it forwards your IPNs to your local machine (must have a public IP or host, I use DynDns) based on the custom variable. So you can configure a single sandbox account to serve multiple developers on the project (I use an local .env file to store the local machine's public host). See it here: github.com/tinkerbox/fast-forward –  Jaryl Sep 5 '13 at 8:21

Your Answer


