Clickbank instant notification version 6

2 replies
Hi;

I am using Clickbanks Instant notification.
I have set this and it works fine if I don't call "ipn_verification()". It returns false no matter what


PHP Code:
<?php 
class Welcome extends CI_Controller {

   
    public function 
index()
        {
            if(
$this->ipn_verification())
                {
                    
$this->update();    
                }
            else
                {
                    echo 
"Unverified";
                }    
        }        
            
    private function 
ipn_verification()
        {        
            
$secretKey="FFF";
            
$pop "";
            
$ipnFields = array();
            foreach (
$_POST as $key => $value
                {
                    if (
$key == "cverify"
                        {
                            continue;
                        }
                    
$ipnFields[] = $key;
                }
            
sort($ipnFields);
            foreach (
$ipnFields as $field
                {
                    
// if Magic Quotes are enabled $_POST[$field] will need to be
                    // un-escaped before being appended to $pop
                    
$pop $pop $_POST[$field] . "|";
                }
            
$pop $pop $secretKey;
            
$calcedVerify sha1(mb_convert_encoding($pop"UTF-8"));
            
$calcedVerify strtoupper(substr($calcedVerify,0,8));
            return 
$calcedVerify == $_POST["cverify"];
        }
    private function 
update()
        {
            
$secretKey "FFF"// secret key from your ClickBank account
             // get JSON from raw body...
            
$message json_decode(file_get_contents('php://input'));
            
// Pull out the encrypted notification and the initialization vector for
            // AES/CBC/PKCS5Padding decryption
            
$encrypted $message->{'notification'};
            
$iv $message->{'iv'};
            
error_log("IV: $iv");
            
// decrypt the body...
            
$decrypted trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,substr(sha1($secretKey), 032),base64_decode($encrypted),MCRYPT_MODE_CBC,base64_decode($iv)), "\0..\32");
            
error_log("Decrypted: $decrypted");
            
// convert the decrypted string to a JSON object...
            
$order json_decode($decrypted);
            

            
// Ready to rock and roll - If the decoding of the JSON string wasn't successful,
            // then you can assume the notification wasn't encrypted with your secret key.    
        
}    
}
Here is the docs:

https://support.clickbank.com/entrie...n-Service#CODE

What am I doing wrong?

Thanks
#clickbank #instant #notification #version
  • Profile picture of the author geekSoftware
    I had problems too with Clickbank IPN, so this is what I did:
    PHP Code:
    <?php
    class ClickBank {
        private 
    $secretKey "";
        private 
    $vendor "";
        private 
    $vendorReceived "";
        private 
    $itemNo "";
        private 
    $receipt NULL;
        private 
    $transactionType NULL;
        private 
    $version "";
        private 
    $currency "";
        
        public function 
    __construct($key$vendor) {
            
    $this->secretKey $key;
            
    $this->vendor $vendor;
        }    
        
        public function 
    decryptData($data) {
             
    $message json_decode($data);
             
    $encrypted $message->{'notification'};
             
    $iv $message->{'iv'};
             
    $decrypted trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,
                     
    substr(sha1($this->secretKey), 032),
                     
    base64_decode($encrypted),
                     
    MCRYPT_MODE_CBC,
                     
    base64_decode($iv)), "\0..\32");

            
    $order json_decode($decrypted);
            return 
    $order;        
        }
        
        public function 
    isVerified() {
            
            if (!(
    $this->vendor == $this->vendorReceived) ||  !is_numeric($this->itemNo) || !(strtolower($this->currency) ==  "usd"))
                return 
    false;
            
            if (
    is_null($this->receipt) || is_null($this->transactionType) || $this->version 6)
                return 
    false;
            
            return 
    true;
        }
        
        public function 
    getOrderDetails($order) {
            
    $vendor $this->vendorReceived $order -> vendor;
            
    $receipt $this->receipt $order -> receipt;
            
    $itemNo $this->itemNo $order -> lineItems[0] -> itemNo;
            
    $version $this->version $order -> version;
            
    $transactionType $this->transactionType $order -> transactionType;

            
    $customerCharged $order -> totalOrderAmount;
            
    $myEarnings $order -> totalAccountAmount;
            
    $currency $this->currency $order -> currency;

            
    $firstName $order -> customer -> billing -> firstName;
            
    $lastName $order -> customer -> billing -> lastName;
            
    $email $order -> customer -> billing -> email;

            
    $orderDetails = array(
                        
    "vendor" => $vendor,
                        
    "myEarnings" => $myEarnings,
                        
    "customerCharged" => $customerCharged,
                        
    "currency" => $currency,
                        
    "transactionType" => $transactionType,
                        
    "receipt" => $receipt,
                        
    "itemNo" => $itemNo,
                        
    "version" => $version,
                        
    "firstName" => $firstName,
                        
    "lastName" => $lastName,
                        
    "email" => $email
                    
    );    
                    
            return 
    $orderDetails;
        }
    }
    ?>
    Here is how I use this class:
    PHP Code:
        $clickBank = new ClickBank("SECRET-KEY""VENDOR");
        
    $data $clickBank->decryptData(file_get_contents('php://input'));
        
    $orderDetails $clickBank->getOrderDetails($data);
        
        if (
    $clickBank->isVerified()) 
                 
    //process order 
    {{ DiscussionBoard.errors[9877376].message }}
    • Profile picture of the author 21clg
      Hey guys. How do I implement this? I am trying to get cb order amount data into the url of my thankyou (post purchase) page as a parameter ( like ?totalOrderAmount=100&otherstuff... )

      I then want to pull the value of that parameter into my page using php (already know that part)

      So how do I get this encoded JSON shit in readable format into to the address bar after checkout?
      {{ DiscussionBoard.errors[9978389].message }}

Trending Topics