#1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,150
    Rep Power
    220

    How come this part of my code doesn't get executed?


    This is supposed to send me an email if $transaction_type=='CANCEL-REBILL'.

    Strange. There are no errors and I get the first transaction report email. Basically everything works fine up to right after
    mail('MYEMAIL@yahoo.com','Transaction report',$message);

    But ####### THE PART AFTER HERE NEVER "HAPPENS"! I DON'T GET THE EMAILS AND OP API DOESN'T TAG THEM EITHER.

    if($transaction_type=='RFND' || $transaction_type=='CANCEL-REBILL' || $transaction_type=='CGBK')
    {
    PHP Code:
    <?php
    defined
    ("BASEPATH") OR exit("No direct script access allowed");

    use 
    OntraportAPI\Ontraport;
    include 
    'SDK-PHP/src/Ontraport.php';

    class 
    Clickbank_instant_notification_model extends CI_Model {

        protected 
    $_eodemembers_item_nos = array(
            
    18
        
    );
        protected 
    $_vdcmembers_item_nos = array(
            
    20,
            
    21 
        
    );
        protected 
    $_myvdcmembers_item_nos = array(
            
    22,
            
    23,
            
    24,
            
    25,
            
    26
        
    );
        protected 
    $_urcmember_item_nos = array(
            
    19,
            
    28,
            
    29,
            
    30
        
    );

        protected 
    $_thtb_item_nos = array(
            
    36
        
    );

        
    // --------------------------------------------------------------------------------------

        
    public function __construct()
        {
            
    parent::__construct();
        }

        
    // --------------------------------------------------------------------------------------

        
    public function connect_to_api($your_secret_key)
        {
            
    // 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 $your_secret_key// 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'};
            
    //var_log_message("IV: $iv");
            // decrypt the body...
            
    $decrypted trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128substr(sha1($secretKey), 032), base64_decode($encrypted), MCRYPT_MODE_CBCbase64_decode($iv)), "\0..\32");
            
    //var_log_message("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.

            
    return $order;
        }

        
    // --------------------------------------------------------------------------------------

        
    public function insert_order($order)
        {
            
    //var_log_message($order);
            
    $transaction_time $order->transactionTime;
            
    $receipt $order->receipt;
            
    $transaction_type $order->transactionType;
            
    $affiliate $order->affiliate;
            
    $payment_method $order->paymentMethod;
            
    $tracking_codes $order->trackingCodes;
            
    $item_no $order->lineItems[0]->itemNo;
            
    $recurring $order->lineItems[0]->recurring;
            
    $line_item_type $order->lineItems[0]->lineItemType;
            
    $first_name $order->customer->billing->firstName;
            
    $email $order->customer->billing->email;
            
    $upsell_original_receipt = ($order->lineItems[0]->lineItemType == "UPSELL" $order->upsell->upsellOriginalReceipt '');
            
    $upsell_flow_id $order->upsell->upsellFlowId;

            
    $this->load->library("clickbank_instant_notification_library");
            
    $username $this->clickbank_instant_notification_library->get_username($order);

            
    $sql "
                INSERT INTO
                    transactions
                    (
                        transaction_time
                        , receipt
                        , transaction_type
                        , affiliate
                        , payment_method
                        , item_no
                        , recurring
                        , line_item_type
                        , first_name
                        , email
                        , upsell_original_receipt
                        , upsell_flow_id
                        , username
                    )
                VALUES
                    (
                        '
    {$transaction_time}'
                        , '
    {$receipt}'
                        , '
    {$transaction_type}'
                        , '
    {$affiliate}'
                        , '
    {$payment_method}'
                        , '
    {$item_no}'
                        , '
    {$recurring}'
                        , '
    {$line_item_type}'
                        , '
    {$first_name}'
                        , '
    {$email}'
                        , '
    {$upsell_original_receipt}'
                        , '
    {$upsell_flow_id}'
                        , '
    {$username}'
                    )
                ;
                "
    ;

            if (
    in_array($item_no$this->_eodemembers_item_nos))
            {
                
    $eodemembers_db $this->load->database('eodemembers_db'TRUE);
                
    $eodemembers_db->query($sql);
                
    $eodemembers_db->close();
            }
            elseif (
    in_array($item_no$this->_vdcmembers_item_nos))
            {
                
    $vdcmembers_db $this->load->database('vdcmembers_db'TRUE);
                
    $vdcmembers_db->query($sql);
                
    $vdcmembers_db->close();
            }
            elseif (
    in_array($item_no$this->_myvdcmembers_item_nos))
            {
                
    $myvdcmembers_db $this->load->database('myvdcmembers_db'TRUE);
                
    $myvdcmembers_db->query($sql);
                
    $myvdcmembers_db->close();
            }
            elseif (
    in_array($item_no$this->_urcmember_item_nos))
            {
                
    $urcmember_db $this->load->database('urcmember_db'TRUE);
                
    $urcmember_db->query($sql);
                
    $urcmember_db->close();
            }
            
    /*elseif (in_array($item_no, $this->_thtb_item_nos))
            {
                $thtbmember_db = $this->load->database('texthert_thtb', TRUE);
                $thtbmember_db->query($sql);
                $thtbmember_db->close();
            }*/
            
    else
            {
                
    $this->db->query($sql);
                

                
    //Send email report
                
    $message $email." just got a ".$transaction_type.".";
                
    mail('MYEMAIL@yahoo.com','Transaction report',$message);
                
    //Tag User in OP as refunder

    ####### THE PART AFTER HERE NEVER "HAPPENS"! I DON'T GET THE EMAILS AND OP API DOESN'T TAG THEM EITHER.

                
    if($transaction_type=='RFND' || $transaction_type=='CANCEL-REBILL' || $transaction_type=='CGBK')
                    {
                        
    $client = new Ontraport("********","********");    
                        
    $requestParams = [ 
                            
    'condition' => json_encode([[
                                
    'field' => ['field' => 'email']
                                , 
    'op' => '='
                                
    'value' => ['value' => $email]
                            ]])
                        ];
                        
    $response $client->contact()->retrieveMultiple($requestParams);
                        
    $response json_decode($response);
                                foreach(
    $response as $val=>$row)
                                   {
                                        if(isset(
    $row[0]->id))
                                            {
                                                
    $contact_id $row[0]->id;
                                            }
                                   }
                        
    //
                    
    if(isset($contact_id) && (is_numeric($contact_id)))
                        {
                            
    $requestParams = array(
                                
    "objectID" => 0// Contact object
                                
    "ids"      => $contact_id,
                                
    "add_list" => 96
                            
    );
                            
    $response $client->object()->addTag($requestParams);
                            
    $message "OP ID ".$contact_id." (email".$email.") got a ".$transaction_type." and so tagged as refunder (tag 96)";
                            
    mail('myemail@yahoo.com','Tagged a refunder',$message);
                        }
                    else 
                        {
                            
    $message "OP ID NOT FOUND (email".$email.") got a ".$transaction_type.". Wanted to tagged him as refunder (tag 96) but doesn't seem to be in OP! Check this";
                            
    mail('myemail@yahoo.com','Tagged a refunder',$message);
                        }    
                    }
                    
            }
        }

        
    // --------------------------------------------------------------------------------------
    }
    What am I missing?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,308
    Rep Power
    630
    Either there is a fatal error occurring that you are missing (did you check the httpd logs?) or the logic is not behaving as you expect. I suggest you start by adding echo statements to trace the program.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,150
    Rep Power
    220
    Originally Posted by gw1500se
    Either there is a fatal error occurring that you are missing (did you check the httpd logs?) or the logic is not behaving as you expect. I suggest you start by adding echo statements to trace the program.
    If there is fatal error, will the rest of the code still work?

    I get parts of the code. Does it mean the logic is not being met?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,308
    Rep Power
    630
    Any code preceding the fatal error will be executed and anything after will not. Tracing your code will tell you where it is failing though not necessarily why but that is a place to start. I don't see anything obviously wrong with your code.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,067
    Rep Power
    4101
    To start with ensure that your if condition is true:
    Code:
    var_dump($transaction_type=='RFND' || $transaction_type=='CANCEL-REBILL' || $transaction_type=='CGBK');
    If that checks out then start adding echo's / var_dumps inside the if to see where it goes. A next good step would probably be
    Code:
    var_dump(isset($contact_id) && (is_numeric($contact_id)));
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  10. #6
  11. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,760
    Rep Power
    4536
    I see you're also inserting $transaction_type directly into the database. Is it possible you've processed/validated that in a way that converts the dash character to something else?
    -- Cigars, whiskey and wild, wild women. --

IMN logo majestic logo threadwatch logo seochat tools logo