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:

  1. A customer purchases a product for which you are the affiliate or publisher
  2. ClickBank posts a notification to a URL you specify in your account
  3. 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”.

23 Responses to “Using ClickBank Instant Notification”

  • Ron Davies says:

    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 says:

    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 says:

    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 says:

    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 says:

    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 says:

    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.

  • Shah nawaz says:

    Today Internet Marketing is big bussiness in the world. In India big future for Internet marketing.

  • Mohamed Asik M says:

    Hi Greg,

    In recurring payment for instant notification, how to check the relationship between first payment and second payment?

    for example:

    Person A, purchased a product ‘B’ in January 2009
    Second payment that i received from January 2010 (if i used annual subscription)

    In the above case, How to maintain the relationship between the first payment (January 2009) & second payment (January 2010)?

    Thanks in advance

  • Greg Lems, ClickBank says:

    Mohamed,

    You use the receipt numbers to associate transactions for the same subscription. All transactions for the same transaction start with the same first 8 characters, then subsequent transactions have the characters “-B002″ appended on the end for the first rebilling, then “-B003″ for the second rebilling, etc.

    For example, if the receipt for the first purchase of the subscription is “12345FJK”, the receipt for the second purchase will be “12345FJK-B002″, the third will be “12345FJK-B003″. Hope this helps.

    Greg

  • Mohamed Asik M says:

    Great Response & am clear

    Thank You
    Greg

  • Mohamed Asik M says:

    Another one question for INS

    i need the detail about “cvendthru” variable.

    is it vendor variable..

    i passing the below query strings into order form name=Asik&user_id=14&user_type=f

    How to get my custom variable “user_id” & “user_type” in my INS page?

    or any other way to get my custom variable through INS page?

    INS=Instant notification service

    Thanks in advance

  • Greg Lems, ClickBank says:

    Mohamed,

    Yes, those variables you’re passing will be passed through to you as the cvendthru variable.

    The Release Summary for Instant Notification should have all the details you need for understanding the cvendthru variable, please take a look:

    https://www.clickbank.com/20080219_release_summary.html

    Thanks,
    Greg

  • Mohamed Asik M says:

    Thanks a lot “Greg” for your response

    yes i already read out that release summary but i can not get more details about “cvendthru”

    Please confirm me in the below cases, which one is right to get my custom variables?

    Case 1:
    Query String
    name=Asik&user_id=14&user_type=f
    INS Page
    $user_id=$_REQUEST["user_id"];
    $user_type=$_REQUEST["user_type"];

    Case 2:
    Query String
    name=Asik&cvendthru=14_f
    INS Page
    $cvendthru=explode(”_”,$cvendthru);
    $user_id=$cvendthru[0];
    $user_type=$cvendthru[1];

  • Greg Lems, ClickBank says:

    Mohamed,

    Unfortunately neither of those code examples you posted will accomplish what you’d like to do. Here is some code that should achieve what you’re looking for:

    // get cvendthru request parameter
    $cvendthru = $_REQUEST["cvendthru"];

    // create empty array to store name value pairs from cvendthru
    $data = array();

    // break up cvendthru by ‘&’ delimiter
    $urldata = explode(”&”, $cvendthru);

    // loop thru array created by above command
    for($i = 0; $i 0) {
    $data[$key] = $value;
    }
    }

    // loop thru associative to show name/value pairs
    foreach ($data as $key => $value) {
    echo $key.” -> “.$value.”\n”;
    }

    // syntax to get data by key from associative array
    echo “Get individual item from cvendthru data: “.$data["detail"].”\n”;

    Hope that helps,
    Greg

  • Mohamed Asik M says:

    Hi Greg,

    Thank you, Finally i got the point but your above code is little bit complicated to understand..some syntax error there.. please rectify that

    Simple Code :

    $cvendthru = $_REQUEST["cvendthru"];
    // for eg: $cvendthru=”user_id=14&user_type=F”;

    parse_str($cvendthru, $cdata);
    echo $cdata["user_id"];
    echo $cdata["user_type"];

    Once again thanks for your responses

    Cheers :)

  • bahar says:

    Hello,

    I am setting up the instant notification service for one of my client. I am not sure how to test if I am getting response. I have set one of the products as “test” product and tried with the test product.

    But I am not getting any response. In home page, I checked the “test url” option and it returns a HTTP 200 response.

    is INS working with test products?

    have a nice day.

  • Oleg says:

    I’m fairly confident I set everything up right.

    When I press “test” next to the INS link, everything works fine.
    When I try to make a test transaction, I don’t get an email. It’s not due to a security key issue as I have it set to email me whether it passes or fails. Basically, if the page it called, it should email me – but nothing happens with a test transaction.

    As bahar asked above, does INS work with test products?

  • Greg Lems, ClickBank says:

    Bahar and Oleg,

    Test purchases do not cause Instant Notification messages to go out. You must use the Instant Notification “test” button to test receiving Instant Notification messages. We are considering enhancing test purchases to send Instant Notifications in the future however a release date for this enhancement has not been set.

  • Erik says:

    Ha! Thankfully I read Greg’s post of June 1. I’ve been beating my head against a wall trying to figure out why my test purchases were not generating an IPN ping by ClickBank. Generally speaking, you guys are amazing and have a killer e-commerce platform for us vendors to use. One thing that’s especially nice is the ability to do test purchases. To the extent the test purchase process can be enhanced to generate an IPN, that would be fantastic! Anyway, keep up the great work.

  • Venu says:

    Hi All,

    My INS url is http://www.xxxxx.com/ClickBankINS.php?user_id=14&user_name=test.
    When i click on test button beside url textbox, system posting test data to this url. Fine, when i see request object i getting all values, but i am getting $_REQUEST['cvendthru'] as null. What i expect is querystring i passed in url.But it is not coming in $_REQUEST['cvendthru']; And i am getting $_REQUEST['user_id'], but not $_REQUEST['uesr_name']

    Am i doing anything wrong or am i missed anything..

    Thanks in advance
    -Venu

  • Marco says:

    I’m having the same problem as Ron above…
    I only get this:
    Product:
    Publisher:
    Affiliate:
    Transaction:
    Amount:

    I’m using the code found on this forum
    http://forums.digitalpoint.com/showthread.php?p=8675162

  • eric says:

    Thank God! i read the June 1 admin post….

    Just a question… Is it anywhere near “now” that this Test Product Instant Notification will be implemented?

    Cheers!

Leave a Reply

Anti-Spam Question: