Paypal Adaptive Ruby Gem Released

I have been tinkering with the new Paypal Adaptive Payments API and created a simple ruby gem to interface with it. Still pretty new but I’m using it with little problems so far. Submit bug reports if found. See the code at github

Paypal Adaptive Payments API
The adaptive payments api gives you the opportunity to make preapproved payments, chained payments and parallel payments. The chained/parallel payments are great for commission-based apps or if you are trying to connect a buyer to multiple sellers with a single interface.

How to use with Rails:
Install:

sudo gem install paypal_adaptive

Setup your API info by adding a paypal_adaptive.yml to your config folder:


development:
  environment: "sandbox"
  username: "sandbox_username"
  password: "sandbox_password"
  signature: "sandbox_signature"
  application_id: "sandbox_app_id"

test:
  environment: "sandbox"
  username: "sandbox_username"
  password: "sandbox_password"
  signature: "sandbox_signature"
  application_id: "sandbox_app_id"

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

Make the payment request:


pay_request = PaypalAdaptive::Request.new

data = {
"returnUrl" => "http://testserver.com/payments/completed_payment_request",
"requestEnvelope" => {"errorLanguage" => "en_US"},
"currencyCode"=>"USD",
"receiverList"=>{"receiver"=>
     [{"email"=>"testpp_1261697850_per@nextsprocket.com", "amount"=>"10.00"}]},
"cancelUrl"=>"http://testserver.com/payments/canceled_payment_request",
"actionType"=>"PAY",
"ipnNotificationUrl"=>"http://testserver.com/payments/ipn_notification"
}

pay_response = pay_request.pay(data)

if pay_response.success?
  redirect_to pp_response.approve_paypal_payment_url
else
  puts pay_response.errors.first['message']
  redirect_to failed_payment_url
end

Once the user goes to pp_response.approve_paypal_payment_url, they will be prompted to login to Paypal for payment.

Upon payment completion page, they will be redirected to http://testserver.com/payments/completed_payment_request.

They can also click cancel to go to http://testserver.com/payments/canceled_payment_request

The actual payment details will be sent to your server via “ipnNotificationUrl” You have to create a listener to receive POST messages from paypal. I added a Rails metal template in the templates folder which handles the callback.

Additionally, you can make calls to Paypal Adaptive’s other APIs:


payment_details, preapproval, preapproval_details,
cancel_preapproval, convert_currency, refund

Input is just a Hash just like the pay method. Refer to the Paypal Adaptive manual for more details.

  • ncri
    Works fine now. But I'd require users to also be able to pay with credit card, without having a PP account, like it is possible with website payments standard checkout. Also I don't like the user to see how much money goes to which email address.

    So ideally I'd like PP Website Payments Standard checkout capability but diverting the payment to different paypal accounts in the background. I think this must be somehow possible.

    Any ideas are greatly appreciated.
  • tommychheng
    hi nico, you are right that paypal adaptive payments don't support credit card payments yet. It is scheduled in their roadmap. You can get a date from paypal to see how soon this is.
  • ncri
    Thanks for the info. Any references?

    Is your gem also supporting chained payments? That is more interesting for me, as I don't like payers to see all the receivers of the payment.
  • tommychheng
    There were a few posts on the http://x.com regarding CC payments coming in the near future.

    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}]}
  • ncri
    Thanks!
  • ncri
    Hi. Looks good! Thx. Just trying it out.

    What do I need to put in application_id: "sandbox_app_id"?

    I didn't get one with my sandbox account and even googling doesn't reveal the answer...

    Nico
  • Do you have an example of how your gem does Parallel payments?
  • tommychheng
    Hey Matt,
    Just add two or more people to the receiverList to make it a parallel payment like:
    "receiverList"=>{"receiver"=>
    [{"email"=>"person1@chheng.com", "amount"=>"10.00"}, {"email"=>"person2@chheng.com", "amount"=>"20.00"}]},
  • guest2222222
    Hi Tommy,

    Above format is not working for me, getting an error message "This kind of unilateral payment is not allowed". I had provided API username, pass, signature. Do I missing something?

    Thanks
  • tommychheng
    hey, if you are getting a 'unilateral payment is not allowed', make sure the test email is a registered email in your sandbox account.
  • Coll !!!
blog comments powered by Disqus