Clickbank instant notification version 6

10 replies
Hi;

I am new to this

I just read https://support.clickbank.com/entries/22803622-Instant-Notification-Service

As I understand, if there is a payment, Clickbank calls a script on my server (the one I have set up under Instant Notification URL).

Now my question is what is the difference between these 2 scripts?

PHP Code:
function ipnVerification() {
    
$secretKey="YOUR SECRET KEY";
    
$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"];

AND


PHP Code:
// NOTE: the mcrypt libraries need to be installed and listed as an available extension in
// your phpinfo() to be able to use this method of decryption.
$secretKey "BEHNAM"// 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,
// 
All I need is to update my database with the buyers "email address" I receive.

Thanks
#clickbank #instant #notification #version
  • Profile picture of the author Jeff Lenney
    Hey I just met you

    And this is crazy

    We're not clickbank support

    Contact them maybe...
    Signature

    Too lazy to write something clever here, so check out my marketing blog and learn from a REAL Super Affiliate at JeffLenney.com

    {{ DiscussionBoard.errors[9875407].message }}
    • Profile picture of the author Sid Hale
      Hi Benham,

      Now my question is what is the difference between these 2 scripts?
      It should be obvious (even to a non-programmer) just from scanning those few lines of code, that the answer to your question is... Everything!

      From the CB article you referenced:
      Version 6.0 provides responses in JSON format and additional parameters
      The first code example will NOT decode JSON formatted data, so it will no longer be effective in trying to process the Instant Notification data sent by Clickbank.

      As stated in the article...
      Note: This service is intended for use by experienced programmers. Clients without extensive programming skills should refrain from implementing Instant Notifications without first enlisting the services of an experienced programmer.
      For the most part, you won't find anyone here capable of explaining the differences in the older versions vs. Version 6 - certainly NOT to the level of detail that is required for you to 1) implement a new PHP page to receive notifications, nor 2) to capture any needed data (i.e. email address) from that notification and post it to your database.

      It's not a difficult change for anyone qualified to make that change, but (as recommended by Clickbank) it does require the skills of an experienced programmer.
      Signature

      Sid Hale
      Coming Soon... Rapid Action Profits (Pro)

      {{ DiscussionBoard.errors[9875767].message }}
      • Profile picture of the author behnampmdg3
        Originally Posted by Sid Hale View Post

        The first code example will NOT decode JSON formatted data, so it will no longer be effective in trying to process the Instant Notification data sent by Clickbank.
        Hi;

        Yes I agree. I am reading about it and looking for help.

        I am not sure why they have provided 2 pieces of code! Why would they provide the first piece of code if "will no longer be effective in trying to process the Instant Notification data sent by Clickbank"?

        When I use the second code and email the $decrypted value (mail('myemail@yahoo.com','Test',$decrypted) , I get this:
        {"transactionTime":"2015-02-11T14:15:06-08:00","receipt":"********","transactionType":"TES T","vendor":"myVendorName","role":"VENDOR","totalA ccountAm ount":1.00,"paymentMethod":"VISA","totalOrderAmoun t":1.00,"totalTaxAmount":0.00,"totalShippingAmo unt ":0.00,"currency":"USD","lineItems":[{"itemNo":"1","productTitle":"A passed in title","shippable":false,"recurring":false,"accoun tAmount":1.00}],"customer":{"shipping":{"firstName":"TEST","lastN ame":"USER","fullName":"Test User","email":"testuser@somesite.com","address":{} },"billing":{"firstName":"TEST","lastName":"USER ", "fullName":"Test User","email":"testuser@somesite.com","address":{} } },"version":6.0,"attemptCount":1}
        Which is pretty close I believe. Now all I need is to access item number and email, then I can easily update the DB.

        Still not sure why they provided that first code though
        {{ DiscussionBoard.errors[9876242].message }}
        • Profile picture of the author Sid Hale
          Hi Benham,

          Contrary to my initial response...

          that first piece of code (shown last in the referenced CB document) is for fraud prevention and allows you to insure that the Notification is not bogus - and responds only with 0/1 (fail/pass).

          The second piece of code in your OP is used to then decode the notification so that you can use the variable from the post.
          Signature

          Sid Hale
          Coming Soon... Rapid Action Profits (Pro)

          {{ DiscussionBoard.errors[9876338].message }}
          • Profile picture of the author behnampmdg3
            Originally Posted by Sid Hale View Post

            Hi Benham,

            Contrary to my initial response...

            that first piece of code (shown last in the referenced CB document) is for fraud prevention and allows you to insure that the Notification is not bogus - and responds only with 0/1 (fail/pass).

            The second piece of code in your OP is used to then decode the notification so that you can use the variable from the post.
            Hi Sid;

            Thank you for your replies. It is working. I am now accessign customer's email and product number :

            $order->customer->billing->email
            $order->lineItems[0]->itemNo

            The only thing that is not yet working is the verification. This returns false no matter what
            PHP Code:
            if(ipnVerification()) 
            .
            {{ DiscussionBoard.errors[9876468].message }}
            • Profile picture of the author Sid Hale
              That's why Clickbank recommends:

              Note: This service is intended for use by experienced programmers. Clients without extensive programming skills should refrain from implementing Instant Notifications without first enlisting the services of an experienced programmer.
              Signature

              Sid Hale
              Coming Soon... Rapid Action Profits (Pro)

              {{ DiscussionBoard.errors[9876567].message }}
              • Profile picture of the author behnampmdg3
                Originally Posted by Sid Hale View Post

                That's why Clickbank recommends:
                Sid, your replies kept me going man. You explained the first part nicely and so that part is working. I like to do the same thing for this part too

                This is my DB update:

                PHP Code:
                //update DB
                            
                $query $this->db->get_where('members', array('email' => $order->customer->billing->email ));
                            if(
                $query->num_rows()==0)
                                {
                                    
                $insert_member = array(
                                   
                'email' => $order->customer->billing->email ,
                                   
                'name' => $order->customer->billing->firstName ,
                                   
                'date_added' => date('Y-m-d'));
                                    
                $this->db->insert('members'$insert_member);
                                    
                $member_id $this->db->insert_id();
                                }
                            else
                                {
                                    
                $member_id $query->result_array()[0]['id'];
                                }
                            
                $insert_order = array(
                            
                'email' => $order->customer->billing->email ,
                            
                'member_id' => $member_id,
                            
                'item_number' => $order->lineItems[0]->itemNo),
                            
                'date_added' => date('Y-m-d'));
                            
                $this->db->insert('orders'$insert_data);
                            
                // 
                {{ DiscussionBoard.errors[9876599].message }}
                • Profile picture of the author Sid Hale
                  Hi Benham,

                  Originally Posted by behnampmdg3 View Post

                  Sid, your replies kept me going man.
                  I don't understand why. When I quoted the Clickbank article above
                  Note: This service is intended for use by experienced programmers. Clients without extensive programming skills should refrain from implementing Instant Notifications without first enlisting the services of an experienced programmer.
                  I meant it as a recommendation. You really should get a qualified PHP programmer to implement this for you.

                  This is my DB update:
                  Not sure why you supplied your DB update code, when you previously stated that the ipnVerification function isn't returning the expected results. They are separate functions, with little/no dependence on one another.
                  Signature

                  Sid Hale
                  Coming Soon... Rapid Action Profits (Pro)

                  {{ DiscussionBoard.errors[9876680].message }}
                  • Profile picture of the author behnampmdg3
                    Originally Posted by Sid Hale View Post

                    Hi Benham,
                    Not sure why you supplied your DB update code, when you previously stated that the ipnVerification function isn't returning the expected results. They are separate functions, with little/no dependence on one another.
                    Hi Sid;

                    DB update I suppose should happen after ipnVerification returns 1. If the request is not verified, the DB update won't happen.

                    I pasted the code so you see how far I am and you get an idea of what I am missing. I assume that makes it easier for you to help.
                    {{ DiscussionBoard.errors[9876693].message }}
  • Profile picture of the author behnampmdg3
    Sid, I got the answer:

    The first bit of code is a verification check that only applies to version 1 of the API so you don't need it.

    They should say "IT IS NOT FOR VERSION 6".

    Thanks Sid.
    {{ DiscussionBoard.errors[9876696].message }}

Trending Topics