Automate payout incentives to affiliates and resellers with PayPal's Mass Pay feature.
A great way to increase your sales is to provide incentives for other people to promote your products and services. This is typically done with an affiliate program, in which you reward those who send traffic to your site by paying them a small fee, usually either a fixed amount per sale or a percentage of the items sold as a result of the affiliate's efforts.
Managing an affiliate system involves tracking all the successful sales from referrals by your affiliates and then paying the affiliates their due on a regular basis. This hack uses IPN [Hack #65] to track affiliate referrals and PayPal's Mass Pay feature to pay all your affiliates at once.
The following code employs a simple business model, in which each affiliate gets one dollar for each sale you receive as a result of their referral, regardless of the amount of the sale.
Here's how it works:
Create a sign-up system on your web site, in which prospective affiliates enter their email addresses. Instruct each affiliate to open a PayPal account with that email address.
Generate a custom button [Hack #28] for each affiliate, as described in the next section.
Instruct the affiliate to place the button on his site. If you want to be creative, supply some custom payment button images [Hack #29] to spruce up the button appearance and help attract attention.
Visitors to your affiliate's site see your product advertisement, crave it instantly, and click the Buy Now button. The payment is sent to you and you deliver the product.
Use IPN to record the affiliate's email address (and any other relevant information) into a database.
Use Mass Pay to send a buck per sale to the affiliate responsible.
Each affiliate's button should be like any other Buy Now button [Hack #28], with two important exceptions.
First, include the email address of your affiliate in the custom variable of the button (make sure the payment still goes to you, however). Second, specify the location of your IPN script for handling affiliate program payments in the notify_URL variable:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="firstname.lastname@example.org"> <input type="hidden" name="item_name" value="Widget"> <input type="hidden" name="item_number" value="Item-123"> <input type="hidden" name="amount" value="10"> <input type="image" name="Submit" value="Submit" src="buynow.gif"> <input type="hidden" name="notify_url" value="http://yoursite/affiliate_ipn.asp"> <input type="hidden" name="custom" value="email@example.com"> </form>
Save this button code into a text file and email it to each affiliate. Better yet, create a script on your server that does this automatically, and take yourself out of the loop entirely.
The IPN script specified in the notify_url variable receives a post of the transaction details from PayPal when a sale is made from the affiliate's site. The script writes the affiliate tracking information to a tab-delimited text file, along with the amount of the reseller incentive. This example is written in Microsoft VBScript and uses a Windows File System Object to manipulate the file.
Use the following VBScript code in conjunction with a standard IPN validation script, such as the one in [Hack #65] :
Const fsoForWriting = 2 Dim objFSO Dim objTextStream Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 'Open the text file 1. vFilePath = "C:\InetPub\yoursite\affiliates\output\MassPay.txt" Set objTextStream = objFSO.OpenTextFile(vFilePath, fsoForWriting, True) 'Write the new line to the file 2. objTextStream.WriteLine custom & " " & (rsAffiliateFees.Fields.Item("AffiliateFee").Value) 'Close the file and clean up objTextStream.Close Set objTextStream = Nothing Set objFSO = Nothing
Replace the example filename on line 1 with the full path of the file in which to save your affiliate data. Make sure you have the proper permissions to write to the file on your server. When using IIS on Windows, for example, you'll probably need to set IUSER (Internet guest) write permissions.
You might want to let your affiliates know whenever you've received a payment as a result of an affiliate referral. They'll be more likely to stay enthusiastic about your affiliate program if they can see it working. Add the following code to your IPN script, after the main IPN processing code [Hack #65] :
Dim InvCDO Set InvCDO = Server.CreateObject("CDONTS.NewMail") InvCDO.From = receiver_email InvCDO.To = custom InvCDO.Subject = "Affiliate Sale" InvCDO.Body = "You have an affiliate sale. Your affiliate account has been credited and will be paid according to the schedule in the affiliate program aggreement." InvCDO.Send( ) Set InvCDO = Nothing
Making a Mass Payment is easy, especially since the file in which you've recorded your affiliate sales, MassPay.txt, already contains the information in the proper format.
To make the affiliate payments, upload your data file, and PayPal does the rest:
Download the MassPay.txt file from your server and save it on your local hard disk.
Log into your PayPal account, and click the Mass Pay link near the bottom of the page.
On the Mass Payment Overview page, click Make a Mass Payment.
Click Browse to locate the MassPay.txt file, or type the full path of the file in the box, and then click Continue when you're done.
Review the details of the transaction and the first few lines of the MassPay.txt file you just uploaded, and then send your payment. You and your affiliates will be notified by PayPal that the payments have been made.
You can further enhance this system with the following:
Create a statistics page on the fly so that affiliates can see their sales figures and possibly fine-tune their earnings (and thus boost your sales).
Use a task scheduler (or a Unix cron job) on your server to mail the MassPay.txt file to yourself each week.
This hack is only the beginning; you can use Mass Pay for customer rebates, pay-to-surf rewards, employee benefits, survey incentives, and more.