Using ClickBank Instant Notification
Posted by: Greg Lems, Director of Application Development
Please note: This post is intended for readers with some experience in programming and Internet servers.
I read once that in the very early days of Amazon.com, Jeff Bezos and his engineers had wired up their server to make a cash-register “ka-ching!” sound every time they made a sale. As business picked up, they had to turn it off because it was going off all the time! It got me thinking whether a fun little widget like this might be something that ClickBank publishers and affiliates are interested in.
To build something that performs an action with each sale, you can use ClickBank Instant Notifications, a feature we enabled earlier this year. This post is about using this ClickBank feature. It assumes that the reader has experience with programming and Internet servers.
How ClickBank Instant Notification Works
ClickBank Instant Notification works like this:
- A customer purchases a product for which you are the affiliate or publisher
- ClickBank posts a notification to a URL you specify in your account
- You respond with an HTTP 200 response code (”OK”) to acknowledge receipt of the information.
This occurs not only for sales, but other actions that can occur on a transaction, such as refunds, chargebacks, cancellations of subscriptions, etc.
Assuming you have an Internet server that can listen to these requests, you can install code to respond to these requests and perform actions.
Security is Important to ClickBank
To ensure security of your ClickBank Instant Notifications, you can choose to have your requests sent by https. Also, with every ClickBank Instant Notification we send along an encrypted string called “cverify” which only you (the account holder) can decrypt to ensure that someone isn’t sending you false ClickBank Instant Notifications.
Enabling Instant Notification
The first step to enabling Instant Notification is to log into your ClickBank account, go to your “My Site” page, and click “Edit” in the “Advanced Tools” box. A link to request access to Instant Notification will appear. Click that link and follow the instructions. You will enter a URL where you’d like ClickBank to send your instant notifications.
Writing Code to Process Instant Notifications
Now that notifications are enabled, you need to create a script that can process the ClickBank notifications. This particular snippet is in PHP; however, we also have a Java example in our documentation (see “Resources” below).
function cbProcess() {
$key=’YOUR SECRET KEY’;
$ccustname = $_REQUEST[’ccustname’];
$ccustemail = $_REQUEST[’ccustemail’];
$ccustcc = $_REQUEST[’ccustcc’];
$ccuststate = $_REQUEST[’ccuststate’];
$ctransreceipt = $_REQUEST[’ctransreceipt’];
$cproditem = $_REQUEST[’cproditem’];
$ctransaction = $_REQUEST[’ctransaction’];
$ctransaffiliate = $_REQUEST[’ctransaffiliate’];
$ctranspublisher = $_REQUEST[’ctranspublisher’];
$cprodtype = $_REQUEST[’cprodtype’];
$cprodtitle = $_REQUEST[’cprodtitle’];
$ctranspaymentmethod = $_REQUEST[’ctranspaymentmethod’];
$ctransamount = $_REQUEST[’ctransamount’];
$caffitid = $_REQUEST[’caffitid’];
$cvendthru = $_REQUEST[’cvendthru’];
$cbpop = $_REQUEST[’cverify’];
//first, calculate whether cverify is properly encrypted
$xxpop = sha1(”$ccustname|$ccustemail|$ccustcc|$ccuststate|$ctransreceipt|”
.”$cproditem|$ctransaction|$ctransaffiliate|$ctranspublisher|$cprodtype|”
.”$cprodtitle|$ctranspaymentmethod|$ctransamount|”
.”$caffitid|$cvendthru|$key”);
$xxpop=strtoupper(substr($xxpop,0,8));
if ($cbpop==$xxpop)
{
// cbverify was properly encrypted, proceed
if ($ctransaction == ‘SALE’)
{
// Make a “CHA-CHING” Sound or perform some action.
// Specific code will be dependent on operating system
return 1;
}
}
else
{
// cbverify was not properly encrypted, fail
return 0;
}
}
Resources
The best resource available to you to learn more about ClickBank Instant Notifications is the release notes for this feature which are here:
https://www.clickbank.com/20080219_release_summary.html
Additionally, if you don’t want to write your own code, there are products available that do it for you already. Try searching on “ClickBank Instant Notification”.
Ron Davies said,
October 14, 2008 @ 5:19 am
Great stuff, but not working for us.
Wer receive the email, but there is no data - just headings.
This is the body of the email. Note that the data is missing. I have 26 transactions like this.
Product:
Publisher:
Affiliate:
Transaction:
Amount:
Greg Lems, ClickBank said,
October 14, 2008 @ 7:10 am
Ron,
You mentioned receiving an email but there’s nothing in the code that was posted about sending an email, so I’m curious what you’re trying to do. The IPN only sends an http request to a server you host. Are you taking your IPN and then trying to convert it into an email? If so, you may not be extracting or reassembling the variables correctly. The IPN reference document mentioned above lists all the variables sent, make sure you’re extracting them and passing them along properly.
Lucie Bellemare said,
October 15, 2008 @ 11:41 am
But is it possible to simply receive an email from ClickBank whenever we get a sale (as an affiliate or as a publisher)?
Beau Blackwell, ClickBank said,
October 15, 2008 @ 11:48 am
Hi Lucie,
ClickBank publishers automatically receive email notifications whenever one of their products sells. For affiliates, the only way to receive emails when sales are made is to use the Instant Notification system.
Kevin said,
October 22, 2008 @ 1:00 am
Hi,
I’ve checked with support. They said that instant notification is disabled for affiliates. So is it or is it not working for affiliate?
Greg Lems, ClickBank said,
October 23, 2008 @ 2:23 pm
Hi Kevin,
I think there’s some confusion. What support must have meant is that affiliates don’t automatically get emailed after each sale like publishers do- that aspect of instant notification is disabled for affiliates. I can assure you that if you want to use Instant Notification in the method described in my post, it is definitely enabled for affiliates.