Copyright Groundbreak.com. All rights reserved.
Any comments, suggestions, or mistakes: smiles@groundbreak.com

Integrating Ultimate Affiliate with Paypal.com - Updated 3/24/2004

Paypal.com has a great "Instant Payment Notification" (IPN) system that will silently trigger a script on your site after each sale is made. This can be used to trigger commissions in Ultimate Affiliate. There are basically three steps to the setup process:

1) Install the paypal.cgi script.
2) Create a paypal button that carries along the referring affiliate's username to paypal.
3) Test your setup


1. Set up the paypal.cgi script:

The paypal.cgi script can be found in the /extras/PROCESSORINTEGRATION folder of the Ultimate Affiliate zip file. First you need to edit the few config lines at the top of the paypal.cgi script in your text editor:

$url_to_paypal = "https://www.paypal.com/cgi-bin/webscr";
$url_to_sale = "http://www.yoursite.com/cgi-bin/affiliates/sale.cgi";
$secret = "";

The $url_to_paypal should remain the same. The $url_to_sale is the FULL URL to your sale.cgi script without any extra variables at the end of it. You should just be replacing "yoursite.com" above with your actual domain - unless you have the affiliate program installed in a different directory than normal. Then, the $secret variable is whatever you set the "secret" to be at the admin configuration commission settings. Here's an example of a typical setting:

$url_to_paypal = "https://www.paypal.com/cgi-bin/webscr";
$url_to_sale = "http://www.johnnystamales.com/cgi-bin/affiliates/sale.cgi";
$secret = "grover123";

Upload the paypal.cgi script into your /cgi-bin/affiliates directory. Chmod it 755. Note that this script MUST be in the directory that contains the /emails directory as this is where it writes it's data too. By default, you should already have the /emails directory there and chmod 777, if not, do so.


2. Create a paypal button

Paypal has some great tools in their online member area for creating payment buttons. Whether you create a shopping cart button, one-time payment button, or subscription button you can integrate any of them with Ultimate Affiliate by adding two hidden fields in the button:

<input type=hidden name="notify_url" value="http://www.yoursite.com/cgi-bin/affiliates/paypal.cgi">
<input type=hidden name="custom" value="AFFILIATENAME">

The two hidden tags above would tell paypal to remotely call the paypal.cgi script after the sale (this is NOT the "return" variable which should go to a "thank-you" page...) and send along all of the payment variables. One of these variables will be the "custom" variable that contains the referring affiliate's username. This is what will be used to award the commission.

To do this, the AFFILIATENAME in the above code needs to be replaced with the referring affiliate's name. This can be done with some javascript code, or by making the page with the paypal button a PHP page (ending in .php). Let's create an example paypal button:

<!-- Begin PayPal Button -->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="paypalemail@yoursite.com">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="item_name" value="Product Name">
<input type="hidden" name="amount" value="19.95">
<input type="hidden" name="image_url" value="https://yoursite.com/images/paypaltitle.gif">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.yoursite.com/paypalthanks.html">
<input type="hidden" name="cancel_return" value="http://www.groundbreak.com">
<input type="image" src="http://images.paypal.com/images/x-click-but5.gif" border="0" name="submit">
</form>
<!-- End PayPal Button -->

If this button were in a php script/page, you would simply change it to look like this:

<!-- Begin PayPal Button -->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type=hidden name="notify_url" value="http://www.yoursite.com/cgi-bin/affiliates/paypal.cgi">
<input type=hidden name="custom" value="<? echo $COOKIENAME; ?>">

<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="paypalemail@yoursite.com">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="item_name" value="Product Name">
<input type="hidden" name="amount" value="19.95">
<input type="hidden" name="image_url" value="https://yoursite.com/images/paypaltitle.gif">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.yoursite.com/paypalthanks.html">
<input type="hidden" name="cancel_return" value="http://www.groundbreak.com">
<input type="image" src="http://images.paypal.com/images/x-click-but5.gif" border="0" name="submit">
</form>
<!-- End PayPal Button -->

The only trick above is that you need to change the $COOKIENAME variable to whatever you named the affiliate cookie. If the cookie is called "yoursite", then you'd change the above to $yoursite.

If you don't want to use a php page, you can use some javascript code to fetch the cookie and insert it into the "custom" hidden variable:

<script>
function getCookie (name) {
var dc = document.cookie;
var cname = name + "=";
var clen = dc.length;
var cbegin = 0;
while (cbegin < clen) {
var vbegin = cbegin + cname.length;
if (dc.substring(cbegin, vbegin) == cname) {
var vend = dc.indexOf (";", vbegin);
if (vend == -1) vend = clen;
return unescape(dc.substring(vbegin, vend));
}
cbegin = dc.indexOf(" ", cbegin) + 1;
if (cbegin== 0) break;
}
return null;
}
affiliatecookie = getCookie('COOKIENAME');
</script>

<!-- Begin PayPal Button -->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name="notify_url" value="http://www.yoursite.com/cgi-bin/affiliates/paypal.cgi">
<script>
document.write("<input type=hidden name=custom value="+affiliatecookie+">");
</script>

<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="paypalemail@yoursite.com">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="item_name" value="Product Name">
<input type="hidden" name="amount" value="19.95">
<input type="hidden" name="image_url" value="https://yoursite.com/images/paypaltitle.gif">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.yoursite.com/paypalthanks.html">
<input type="hidden" name="cancel_return" value="http://www.groundbreak.com">
<input type="image" src="http://images.paypal.com/images/x-click-but5.gif" border="0" name="submit">
</form>
<!-- End PayPal Button -->

Note that again, you'd be replacing the COOKIENAME with whatever you named the cookie in the affiliate program.

At this point, when someone clicks through an affiliate link and goes to the paypal button and orders the product a commission should be registered.


TESTING YOUR SETUP

Sometimes the toughest part of setting this up is just making sure everything is working properly. Because paypal typically only wants you to have one paypal account, it's tough to make a truly "live" test - but if you know someone who has an account possibly you could ask them to test it for you. You can always make a $1.00 product or just cancel their order after it's completed.

Here are a few tips for testing the system.

  • First test to see if sale.cgi can record commissions. Click through an affiliate link and try to trigger a commission by going to ...sale.cgi?cashflow=10&secret=SECRETWORD and see if a commission is made.
  • Then, execute paypal.cgi in your browser - you should get a blank white page (no error)
  • Temporarily change the paypal button, changing the <form method=post> to <form method=get> and then click through the paypal button. When you do this, all of the sent variables should be shown in the url in your browser's address bar. You can scan through this long url for the "notify_url" and "custom" variables and make sure they are correct (after you've clicked through an affiliate link first, of course)

If sale.cgi doesn't seem to be recording commissions from the manual tests, here are some variables to check:

Check IP addresses after sale: OFF (paypal always uses the same IP address)
Secret Word: make sure it matches what you put in the paypal.cgi script
Check for duplicate "goods" variable: OFF (the paypal.cgi script actually does this now)



© 1998 - present Groundbreak.com, All Rights Reserved