O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  

Buy the book!
PayPal Hacks
By Shannon Sofield, Dave Nielsen, Dave Burchell
September 2004
More Info

Issue Payments en Masse with the Mass Pay API
Send out a large number of payments all at once with the Mass Pay feature through the API
The Code
[Discuss (0) | Link to this hack]

As described in "Use Mass Pay to Create an Affiliate System" [Hack #77], PayPal allows you to send many payments at once through the PayPal web site. Using the Mass Pay API and some slight modifications to the code in , you can also do this from your own applications.


You can pay up to 250 payees at once using Mass Pay. To make more than 250 payments, you'll need to call Mass Pay repeatedly.

The Code

This code uses the MassPayReq, MassPayRequestType, MassPayRequestItemType, and MassPayResponseType objects generated by the web reference in order to process the Mass Pay request.


This code requires the SSL certificate generated in .

// Load the Certificate
X509Certificate certificate = X509Certificate.CreateFromCertFile(certPath);
// Create the API Service
PayPalAPIInterfaceService service = new PayPalAPIInterfaceService( );
service.Url = url;
// Add the X509 Cert to the service for authentication
// Create the MassPay Request Item
1.  MassPayRequestItemType masspayRequestItem = new MassPayRequestItemType( );

// create the Amount
BasicAmountType amount = new BasicAmountType( );
amount.currencyID = CurrencyCodeType.USD;
amount.Value = "0.67";
masspayRequestItem.Amount = amount;

// create the recipient email
masspayRequestItem.ReceiverEmail = "your-recipient@domain.com";

// create the optional unique id (for your own benefit)
masspayRequestItem.UniqueID = "some unique id";

// create the optional Note
masspayRequestItem.Note = "some note";
// Create the MassPay Request 
2.  MassPayRequestType masspayRequest = new MassPayRequestType( );

// you can set an email subject if you want to. 
// This will be the subject of the email that your payees are going 
                to receive
masspayRequest.EmailSubject = "some email subject";

masspayRequest.MassPayRequestItemDetails = new MassPayRequestItemType[ 1 ];

// add the previously created MassPayRequestItemType object to this array
masspayRequest.MassPayRequestItemDetails[0] = masspayRequestItem;

MassPayReq request = new MassPayReq( );
request.MassPayRequest = masspayRequest;
// Build the Security Header
CustomSecurityHeaderType securityHeader = new CustomSecurityHeaderType( );
UserIdPasswordType userIdPassword = new UserIdPasswordType( );
userIdPassword.Username = ""; // Insert your API username here
userIdPassword.Password = ""; // Insert your API password here
userIdPassword.Subject = "";
securityHeader.Credentials = userIdPassword;
securityHeader.MustUnderstand = true;
service.RequesterCredentials = securityHeader;
MassPayResponseType response = service.MassPay(request);

Console.WriteLine("Ack: " + response.Ack.ToString( ));
Console.WriteLine("Correlation ID: " + response.CorrelationID);
Console.WriteLine("Timestamp: " + response.Timestamp.ToString( ));

O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.