|< Day Day Up >|
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.
7.17.1 Creating Your Business Model
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:
7.17.2 Building a Button for Your Affiliate
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="email@example.com"> <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=" firstname.lastname@example.org "> </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.
7.17.3 Recording Referred Purchases
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.
7.17.4 Notifying Your Affiliates
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
7.17.5 Paying Your Affiliates en Mass
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:
7.17.6 Hacking the Hack
You can further enhance this system with the following:
|< Day Day Up >|