PayPal Hacks. 100 Industrial-Strength Tips and Tools Free Open Book

PayPal Hacks. 100 Industrial-Strength Tips and Tools

Previous Section  < Day Day Up >  Next Section

Hack 96 Issue Payments en Masse with the Mass Pay API

figs/expert.gif figs/hack96.gif

Send out a large number of payments all at once with the Mass Pay feature through the API.

As described in [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 [Hack #88], 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.


8.12.1 Setting up the Request

The first thing to do is set up a simple tab-delimited text file that contains all the information about your payees, as shown in Figure 8-13.

Figure 8-13. Using a simple tab-delimited text file to store the information about the recipients of your payments
figs/pph_0813.gif


List the recipients' email addresses in the first column and the corresponding payment amounts in the second column. Include an optional third column to list a unique identifier for each recipient for tracking and reconciliation purposes. The optional fourth column lets you include a customized note to be sent to each of your recipients.

8.12.2 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 [Hack #88] .


// 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

service.ClientCertificates.Add(certificate);

// 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( ));

8.12.3 Running the Hack

When you successfully execute the code [Hack #90], the Ack code returned will be Success:

Ack: Success

CorrelationID: 

Timestamp: 4/27/2004 10:25:30 AM

Each payee is represented in the code as a MassPayRequestItemType object. Create the initial MassPayRequestItemType instance (line 1) and a BasicAmountType instance that contains the amount, and add it to the item request. Also create the recipient's email, unique ID, and note, and add them to the item request.

Note that this code creates only one MassPayRequestItemType object (line 2). You can repeat the steps to fill in as many objects as you want and thus overcome the limit of 250 payees. Typically, the way to do this is to read the individual item details from the tab-delimited file and create the objects on the fly. That way, you should be able to create a list of MassPayRequestItemType objects.

When you send a payment with Mass Pay, you pay the seller fees [Hack #14] that would otherwise be assessed to your recipients.


Souvik Das, Rob Conery, and Dave Nielsen

    Previous Section  < Day Day Up >  Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y]


         Main Menu
    PayPal Hacks
    Table of Contents
    Copyright
    Credits
    Preface
    Chapter 1. Account Management
    Chapter 2. Making Payments
    Chapter 3. Selling with PayPal
    Chapter 4. Payment Buttons
    Chapter 5. Storefronts and Shopping Carts
    Chapter 6. Managing Subscriptions
    Chapter 7. IPN and PDT
    Chapter 8. The PayPal Web Services API
    Introduction: Hacks #87-100
    8.2 Create a Developer Account
    Hack 87 Set up the Sandbox
    Hack 88 Make Your First API Call
    Hack 89 Create a Wrapper Class for Your API Calls
    Hack 90 Use the PayPal API Wrapper Class
    Hack 91 Refund Payments with the API
    Hack 92 Handle Transaction Errors within the API Wrapper
    Hack 93 Retrieve Transaction Details with the API
    Hack 94 Search for PayPal Transactions
    Hack 95 Hack the API Wrapper
    Hack 96 Issue Payments en Masse with the Mass Pay API
    Hack 97 Pay Affiliates and Suppliers on a Schedule
    Hack 98 Search eBay for Listings that Accept PayPal
    Hack 99 Test IPN and PDT in the Sandbox
    Hack 100 Go Live
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele