Help with ClickBank API Instant Email Notification Script

3 replies
I have a working instant email notification script, however CB has since updated their api to include new variables. The old script still works for now, but will be depreciated at some point. I like some of these variables in the new version (2.1), but can't get it to verify.

(documentation HERE: Instant Notification Service)

Here's the working script for CB Instant Notification V1.0

Code:
<?php

function cbValid() {

$key='YOUR_SECRET_KEY_HERE';
$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'];

$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) return 1;
else return 0;
}
if (cbValid())
mail("YOUR_EMAIL_ADDRESS_HERE", "ClickBank - " .
$_REQUEST['ctransaction'],"Product: " . $_REQUEST['cprodtitle'] . "\nPublisher: " . $_REQUEST['ctranspublisher'] . "\nAffiliate: " . $_REQUEST['ctransaffiliate'] . "\nTransaction: " . $_REQUEST['ctransaction'] . "\nAmount: " . $_REQUEST['ctransamount']);

?>
And here I've included all the new and changed variables in Version 2.1... however, I can't seem to get it to verify.

Code:
<?php

function cbValid() {

    $key='SECRET KEY';
    $ccustfullname = $_REQUEST['ccustfullname'];
    $ccustfirstname = $_REQUEST['ccustfirstname'];
    $ccustlastname = $_REQUEST['ccustlastname'];
    $ccuststate = $_REQUEST['ccuststate'];
    $ccustzip = $_REQUEST['ccustzip'];
    $ccustcc = $_REQUEST['ccustcc'];
    $ccustaddr1 = $_REQUEST['ccustaddr1'];
    $ccustaddr2 = $_REQUEST['ccustaddr2'];
    $ccustcity = $_REQUEST['ccustcity'];
    $ccustcounty = $_REQUEST['ccustcounty'];
    $ccustshippingstate = $_REQUEST['ccustshippingstate'];
    $ccustshippingzip = $_REQUEST['ccustshippingzip'];
    $ccustshippingcountry = $_REQUEST['ccustshippingcountry'];
    $ccustemail = $_REQUEST['ccustemail'];
    $cproditem = $_REQUEST['cproditem'];
    $cprodtitle = $_REQUEST['cprodtitle'];
    $cprodtype = $_REQUEST['cprodtype'];
    $ctransaction = $_REQUEST['ctransaction'];
    $ctransaffiliate = $_REQUEST['ctransaffiliate'];
    $caccountamount = $_REQUEST['caccountamount'];
    $corderamount = $_REQUEST['corderamount'];
    $ctranspaymentmethod = $_REQUEST['ctranspaymentmethod'];
    $ccurrency = $_REQUEST['ccurrency'];
    $ctranspublisher = $_REQUEST['ctranspublisher'];
    $ctransreceipt = $_REQUEST['ctransreceipt'];
    $ctransrole = $_REQUEST['ctransrole'];
    $cupsellreceipt = $_REQUEST['cupsellreceipt'];
    $crebillamnt = $_REQUEST['crebillamnt'];
    $cprocessedpayments = $_REQUEST['cprocessedpayments'];
    $cfuturepayments = $_REQUEST['cfuturepayments'];
    $cnextpaymentdate = $_REQUEST['cnextpaymentdate'];
    $crebillstatus = $_REQUEST['crebillstatus'];
    $ctid = $_REQUEST['ctid'];
    $cvendthru = $_REQUEST['cvendthru'];
    $cverify = $_REQUEST['cverify'];
    $ctranstime = $_REQUEST['ctranstime'];

    $xxpop = sha1("$ccustfullname|$ccustfullname|$ccustfirstname|$ccustlastname|$ccuststate|$ccustzip|$ccustcc|$ccustaddr1|$ccustaddr2|$ccustcity|$ccustcounty|$ccustshippingstate|$ccustshippingzip|$ccustshippingcountry|$ccustemail|$cproditem|$cprodtitle|$cprodtype|$ctransaction|$ctransaffiliate|$caccountamount|$corderamount|$ctranspaymentmethod|$ccurrency|$ctranspublisher|$ctransreceipt|$ctransrole|$cupsellreceipt|$crebillamnt|$cprocessedpayments|$cfuturepayments|$cnextpaymentdate|$crebillstatus|$ctid|$cvendthru|$ctranstime|$key");

    $xxpop=strtoupper(substr($xxpop,0,8));

    if ($cverify==$xxpop) return 1;
    else return 0;
}
if (cbValid())
mail("ENTER YOUR EMAIL", "ClickBank - " . $_REQUEST['ctransaction'],"Product: " . $_REQUEST['cprodtitle'] . "\nPublisher: " . $_REQUEST['ctranspublisher'] . "\nItem Number: " . $_REQUEST['cproditem'] . "\n\nTransaction: " . $_REQUEST['ctransaction'] . "\nRecurring or 1-Time: " . $_REQUEST['cprodtype'] . "\nAmount: " . $_REQUEST['caccountamount'] . "\n\nIf Rebill Amt: " . $_REQUEST['crebillamnt'] . "\nMembership Staus: " . $_REQUEST['crebillstatus'] . "\nMonth as Member: " . $_REQUEST['cprocessedpayments'] . "\n\nCust Name: " . $_REQUEST['ccustfullname'] ."\nCust Email: " . $_REQUEST['ccustemail'] . "\nCust State: " . $_REQUEST['ccuststate'] . "\nCust Zip: " . $_REQUEST['ccustzip'] . "\nCust County: " . $_REQUEST['ccustcc'] . "\n\nAffiliate: " . $_REQUEST['ctransaffiliate'] . "\nTrackingID: " . $_REQUEST['ctid']);
?>
I'm no coding expert so I can't figure out why it won't verify after trying many variations. Any ideas?

Again, here's the documentation from CB: Instant Notification Service

Thanks!
#api #clickbank #email #instant #notification #script
  • Profile picture of the author espradley
    <?php
    function ipnVerification($secretKey, $postVars = array()) {

    //Clear out any value $pop variable.
    $pop = "";

    //create the array that will hold the posted data.
    $ipnFields = array();

    //Loop through each post for the cverify value.
    foreach ($postVars as $key => $value) {
    if ($key == "cverify") {
    continue;
    }
    $ipnFields[] = $key;
    }

    //sort the IPN fields.
    sort($ipnFields);

    //Create the pop string which will be converted to UTF 8;
    foreach ($ipnFields as $field) {
    $pop = $pop . $postVars[$field] . "|";
    }

    //Add the secret key to the end of the pop value.
    $pop = $pop . $secretKey;
    //Use sha1 encoding and conver the UTF8 value of pop
    $calcedVerify = sha1(mb_convert_encoding($pop, "UTF-8"));

    //Get the first 8 characters in upper case.
    $calcedVerify = strtoupper(substr($calcedVerify,0,8));

    //check to see if the values match.
    if($calcedVerify <> $_POST["cverify"]){
    return false;
    }
    return true;

    }
    $secretKey = "your secret key";
    $isValid = ipnVerification($secretKey, $_POST);
    if($isValid){
    echo "The sale was verified";
    }
    ?>
    Signature

    Eddie Spradley

    {{ DiscussionBoard.errors[2873307].message }}
    • Profile picture of the author Ryan Dunn
      Thank you! That worked perfectly and is much simpler.

      Cheers,

      Ryan
      {{ DiscussionBoard.errors[2874057].message }}
  • Profile picture of the author George Lukas
    This is all deprecated. Use version 6
    {{ DiscussionBoard.errors[10474894].message }}

Trending Topics