# Automatically sending a PayPal payment with Ruby

**URL:** <https://www.ruby-forum.com/t/automatically-sending-a-paypal-payment-with-ruby/156937>\
**Category:** Rails\
**Created:** [January 5, 2009, 3:54pm UTC](https://www.ruby-forum.com/t/automatically-sending-a-paypal-payment-with-ruby/156937 "2009-01-05T15:54:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Commander\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a8b319/32.png) [@Commander\_J](https://www.ruby-forum.com/u/Commander_J)\
**Post date:** [January 5, 2009, 3:54pm UTC](https://www.ruby-forum.com/t/automatically-sending-a-paypal-payment-with-ruby/156937/1 "2009-01-05T15:54:36Z")

</div>

Hello,  
I found that Chang Sau S.'s ruby-paypal library can use Mass Payment  
(  
[http://ruby-paypal.rubyforge.org/](http://ruby-paypal.rubyforge.org/)) to automatically send money to any  
PayPal  
recipient. What’s confusing is that the RDoc on the site is from an  
older  
version that did not support Mass Payment.

Some older (2006) threads mention they want this, but they were never  
resolved. I hope this information will be useful to people that still  
don’t  
have the answer to this.

== Unofficial guide to sending automatic payments with Ruby

1. gem install ruby-paypal
2. require ‘ruby-paypal’ at the top of your file
3. Use this example code for a single transaction or create your own:

# Credentials found in environment files.

pp\_nvp = PaypalNVP.new(PPG\_API\_USERNAME, PPG\_API\_PASSWORD,  
PPG\_API\_SIGNATURE)

# def do\_mass\_payment(payments, email\_subject,

receiver\_type=‘EmailAddress’,  
currency\_code=‘USD’)  
payments = []  
payments[0] = PayPalPayment.new  
payments[0].email = self.email  
payments[0].unique\_id = 1239829  
payments[0].note = “Note”  
payments[0].amount = Money.new(self.current\_value)

# Make the call.

response = pp\_nvp.do\_mass\_payment(payments, “Email subject line”)

# Update our own administration.

if response.ack == ‘Success’

# Do success stuff here

end

A sidenote:  
I could not get the ruby-paypal and the paypal (by Tobias L.) gem to  
work on the same Rails installation - they both use a class called  
Paypal. I  
fixed this by including ruby-paypal in my vendor/ dir and renaming the  
class  
Paypal to PaypalNVP. The Money library is included with the ‘paypal’  
(NOT  
the ruby-paypal) gem.

CmdJohnson
