Plugin Directory

Changeset 2900759


Ignore:
Timestamp:
04/18/2023 02:08:02 PM (3 years ago)
Author:
totalprocessing
Message:
  • Optimized log system
  • removed unwanted validations
Location:
totalprocessing-card-payments
Files:
82 added
4 edited

Legend:

Unmodified
Added
Removed
  • totalprocessing-card-payments/trunk/includes/class-tp-payment-gateway.php

    r2875305 r2900759  
    443443            $resourcePath = (string)$_REQUEST['resourcePath'];
    444444           
    445             $this->writeLog( '----- checkForVerifyTx [Querystring values Array] -----', 'debug' );
    446             $this->writeLog( $_GET, 'info' );
     445            $this->writeLog( '----- checkForVerifyTx [Querystring values Array] -----', $_GET, 'debug' );
    447446
    448447            if(isset($_REQUEST['platformBase'])){
     
    459458                $platformBase = $this->platformBase;
    460459            }
    461             $this->writeLog( '----- checkForVerifyTx [requesting transaction status for modal view request or orderpay request] -----', 'debug' );
     460            $this->writeLog( '----- checkForVerifyTx [requesting transaction status for modal view request or orderpay request] -----', null, 'debug' );
    462461            $responseObject = $this->requestTransactionStatus( $platformBase, $id, $resourcePath, $order_id);
    463462           
     
    468467                            if(isset($responseObject->registrationId)){
    469468                                $id = (string)$responseObject->registrationId;
    470                                 $this->writeLog( '----- checkForVerifyTx [requesting transaction status when registarion id exists] -----', 'debug' );
     469                                $this->writeLog( '----- checkForVerifyTx [requesting transaction status when registarion id exists] -----', null, 'debug' );
    471470                                $responseObject = $this->requestTransactionStatus($platformBase, $id, false, $order_id);
    472471                            }
     
    475474                }
    476475            }
    477             $this->writeLog( '----- checkForVerifyTx [response data for modal view request or orderpay request] -----', 'debug' );
     476            $this->writeLog( '----- checkForVerifyTx [response data for modal view request or orderpay request] -----', null, 'debug' );
    478477            $responseResult = $this->parseResponseData($responseObject);
    479478            if(isset($responseResult['result'])){
     
    614613        }
    615614        if((float)$amount === 0){
    616             $this->writeLog( '----- createCheckoutArray [amount is zero] -----', 'debug' );
    617             $this->writeLog( $amount, 'debug' );
     615            $this->writeLog( '----- createCheckoutArray [amount is zero, amount:' . $amount . '] -----', null, 'debug' );
    618616            return false;
    619617        }
     
    635633        if((float)$amount === -0.01){
    636634            if(is_user_logged_in() !== true){
    637                 $this->writeLog( '----- createCheckoutArray [user is not logged in] -----', 'debug' );
    638                 $this->writeLog( $amount, 'debug' );
     635                $this->writeLog( '----- createCheckoutArray [user is not logged in with amount:'.$amount.'] -----', null, 'debug' );
    639636                return false;
    640637            }
     
    647644            if($this->createRegistration === true && is_user_logged_in() === true){
    648645                if($registrationId !== false){
    649                     $this->writeLog( '----- createCheckoutArray [registration id = ' . $registrationId . '] -----', 'debug' );
     646                    $this->writeLog( '----- createCheckoutArray [registration id = ' . $registrationId . '] -----', null, 'debug' );
    650647                    $registrationIds = [$registrationId];
    651648                } else {
    652                     $this->writeLog( '----- createCheckoutArray [generating tokens] -----', 'debug' );
    653649                    $registrationIds = $this->retrieveUnlimitedTokens( get_current_user_id(), $this->id, $this->platformBase );
    654                     $this->writeLog( $registrationIds, 'info' );
     650                    $this->writeLog( '----- createCheckoutArray [generating tokens] -----', $registrationIds, 'debug' );
    655651                }
    656652                if(count($registrationIds) > 0){
     
    679675        }
    680676        $response = wp_remote_request( $remoteUrl , $array);
    681         $this->writeLog( '----- createCheckoutArray [calling to generate checkout id] -----', 'debug' );
    682         $this->writeLog( ['requestURL' => $remoteUrl, 'payload' => $array, 'response' => $response], 'info' );
    683         //$this->shouldLogResponseHandler($response, [$array, $payload]);
    684         //return false;
     677        $this->writeLog( '----- createCheckoutArray [calling to generate checkout id] -----', ['params' => $array, 'response' => $response], 'debug' );
     678       
    685679        if( is_wp_error( $response ) ){
    686680            $errorMessage        = $response->get_error_message();
    687             $this->writeLog( '----- createCheckoutArray [returned wp_error -> url:'.$remoteUrl.'] -----', 'critical' );
    688             $this->writeLog( $errorMessage, 'critical' );
    689             $this->writeLog( '----- createCheckoutArray [params] -----', 'critical' );
    690             $this->writeLog( $array, 'critical' );
    691             $this->writeLog( '----- createCheckoutArray [response] -----', 'critical' );
    692             $this->writeLog( $response, 'critical' );
     681            $this->writeLog( '----- createCheckoutArray [returned wp_error -> url:'.$remoteUrl.'] -----', $errorMessage, 'critical' );
    693682            return false;
    694683        }
     
    714703                    ];
    715704                    WC()->session->set('tp_checkoutData', $checkoutDataArray);
    716                     $this->writeLog( '----- createCheckoutArray [success in getting checout id and saved in session] -----', 'debug' );
    717                     $this->writeLog( $checkoutDataArray, 'info' );
     705                    $this->writeLog( '----- createCheckoutArray [success in getting checout id and saved in session] -----', $checkoutDataArray, 'debug' );
    718706                    return (string)$responseData->id;
    719707                }
    720708            }
    721709        } else {
    722             $this->writeLog( '----- createCheckoutArray [failed in getting checout id] -----', 'debug' );
     710            $this->writeLog( '----- createCheckoutArray [failed in getting checout id] -----', null, 'debug' );
    723711            WC()->session->set('tp_checkoutData', null);
    724712        }
     
    727715   
    728716    public function genCheckoutId(){
    729         $this->writeLog( '----- genCheckoutId [initiating Create Checkout ID with amount -0.01]-----', 'debug' );
     717        $this->writeLog( '----- genCheckoutId [initiating Create Checkout ID with amount -0.01]-----', null, 'debug' );
    730718        $responseData = $this->createCheckoutArray(false,-0.01);
    731719
    732720        if($responseData){
    733             $this->writeLog( '----- genCheckoutId [success in calling Create Checkout ID with amount -0.01]-----', 'debug' );
     721            $this->writeLog( '----- genCheckoutId [success in calling Create Checkout ID with amount -0.01]-----', null, 'debug' );
    734722            wp_send_json_success($responseData);
    735723        } else {
    736             $this->writeLog( '----- genCheckoutId [failed in calling Create Checkout ID with amount -0.01]-----', 'debug' );
     724            $this->writeLog( '----- genCheckoutId [failed in calling Create Checkout ID with amount -0.01]-----', null, 'debug' );
    737725            wp_send_json_error();
    738726        }
     
    743731     */
    744732    public function genCheckoutIdOrder(){
    745         $this->writeLog( '----- genCheckoutIdOrder [initiating Create Checkout ID] -----', 'debug' );
     733        $this->writeLog( '----- genCheckoutIdOrder [initiating Create Checkout ID] -----', null, 'debug' );
    746734        $responseData = $this->createCheckoutArray();
    747735
     
    750738                if(isset($responseData->result->code)){
    751739                    if(in_array($responseData->result->code,['000.200.000','000.200.100','000.200.101'])){
    752                         $this->writeLog( '----- genCheckoutIdOrder [success in Create Checkout ID -> '.$responseData->id.'] -----', 'debug' );
     740                        $this->writeLog( '----- genCheckoutIdOrder [success in Create Checkout ID -> '.$responseData->id.'] -----', null, 'debug' );
    753741                        wp_send_json_success([
    754742                            'uuid' => $responseData->id,
     
    759747            }
    760748        }
    761         $this->writeLog( '----- genCheckoutIdOrder [failed in Create Checkout ID] -----', 'debug' );
     749        $this->writeLog( '----- genCheckoutIdOrder [failed in Create Checkout ID] -----', null, 'debug' );
    762750        wp_send_json_error();
    763751    }
     
    780768                    if(is_array($levelData)){
    781769                        if(isset($levelData[1])){
    782                             $this->writeLog('--------shouldLogResponseHandler -------', 'debug');
    783                             $this->writeLog($array,$levelData[1]);
    784                             $this->writeLog($responseData,$levelData[1]);
    785770                            return true;
    786771                        }
     
    809794                       $level = 'info';
    810795                }
    811                
    812                 $this->writeLog('--------shouldLogResponseHandler -------', 'debug');
    813                 $this->writeLog($array,$level);
    814                 $this->writeLog($responseData,$level);
    815796            }
    816797        }
     
    828809                    $level = $postArr['level'];
    829810                }
    830                 $this->writeLog('------------feLogger---------','debug');
    831                 $this->writeLog($array,'error');
     811                $this->writeLog('------------feLogger---------', $array,'debug');
    832812                wp_send_json_success($postArr);
    833813            } else {
     
    842822    public function tpOrderPay(){
    843823        global $woocommerce;
     824        $this->writeLog('------------tpOrderPay initiated---------', null,'debug');
    844825        $payment_method = wc_get_post_data_by_key('payment_method',false);
    845826        $terms_field = wc_get_post_data_by_key('terms-field',false);
     
    908889        }
    909890        $validate['result'] = 'failure';
     891        $this->writeLog('------------tpOrderPay initiated---------', $validate,'debug');
    910892        wp_send_json_error($validate);
    911893    }
     
    936918        }
    937919        if(count($validation['errors']) > 0){
     920            $this->writeLog('------------validatePayForOrder error---------', $validation,'debug');
    938921            return $validation;
    939922        }
    940923        if(!wp_verify_nonce($postArr['tp_payment_nonce'],'tp_payment_nonce')){
    941924            $validation['errors'][] = 'nonce validation failed';
     925            $this->writeLog('------------validatePayForOrder nonce error---------', $validation,'debug');
    942926            return $validation;
    943927        }
     
    954938        }
    955939        if(count($validation['errors']) > 0){
     940            $this->writeLog('------------validatePayForOrder error---------', $validation,'debug');
    956941            return $validation;
    957942        }
     
    959944        if(!isset($parseUrl['query'])){
    960945            $validation['errors'][] = 'no query args';
     946            $this->writeLog('------------validatePayForOrder no query error---------', $validation,'debug');
    961947            return $validation;
    962948        }
     
    964950        if(!isset($parseStr['key'])){
    965951            $validation['errors'][] = 'no key in query args';
     952            $this->writeLog('------------validatePayForOrder no query error---------', $validation,'debug');
    966953            return $validation;
    967954        }
     
    991978            }
    992979        }
     980        $this->writeLog('------------validatePayForOrder finished ---------', $validation,'debug');
    993981        return $validation;
    994982    }
     
    10311019        $order_id                 = wc_get_post_data_by_key( 'order_id', false );
    10321020        $resourcePath             = sanitize_text_field( $resourcePath );
     1021        $this->writeLog('------------checkTransactionStatus init [time:'.time().'] ---------', null,'debug');
    10331022        $responseObject           = $this->verifyTransactionStatus( $resourcePath, $order_id );
     1023        $this->writeLog('------------checkTransactionStatus request done [time:'.time().'] ---------', null,'debug');
    10341024        $transaction_id           = (int)( isset( $responseObject->merchantTransactionId ) ? $responseObject->merchantTransactionId : 0 );
    10351025        $payment_id               = isset( $responseObject->id ) ? $responseObject->id : "";
     
    10471037            )
    10481038        );
     1039        $this->writeLog('------------checkTransactionStatus db tnxtbl updated with response [time:'.time().', orderid:'.$order_id.'] ---------', null,'debug');
    10491040
    10501041        if( !empty( $payment_code ) ){
     
    10631054    public function lookupTransaction(){
    10641055        global $wpdb;
    1065         $this->writeLog('------------lookupTransaction initiated ---------','debug');
     1056        $this->writeLog('------------lookupTransaction initiated [orderid:'.$order_id.'] ---------', null,'debug');
     1057        $checkoutHash                = WC()->cart->get_cart_hash();
    10661058        $url                         = wc_get_checkout_url();
    10671059        $resourcePath                = wc_get_post_data_by_key('resourcePath',false);
     
    10711063        $debugArray['time'][0]       = time();
    10721064        if($order_id && $order_id > 0){
    1073             $this->writeLog('------------lookupTransaction [requesting transaction status] ---------','debug');
    1074             $this->writeLog(['resourcepath' => $resourcePath, 'order_id' => $order_id],'debug');
    10751065            $ordertnxData = $wpdb->get_row(
    10761066                $wpdb->prepare(
     
    10801070                ARRAY_A
    10811071            );
     1072            $this->writeLog('------------lookupTransaction [requesting transaction status from db tnxtbl] ---------', null,'debug');
    10821073            $responseObject    = json_decode( $ordertnxData['result_json'] );
    10831074            //$responseObject = $this->requestTransactionStatus( $this->platformBase, false, $resourcePath, $order_id );
     
    10891080                            if(isset($responseObject->registrationId)){
    10901081                                $id  = (string)$responseObject->registrationId;
    1091                                 $this->writeLog('------------lookupTransaction [requested transaction status again] ---------','debug');
     1082                                $this->writeLog('------------lookupTransaction [requested transaction status again] ---------', null,'debug');
    10921083                                $responseObject = $this->requestTransactionStatus( $this->platformBase, $id, false, $order_id );
    10931084                                $debugArray['time'][2]   = time();
     
    10971088                }
    10981089                $responseResult = $this->parseResponseData($responseObject);
    1099                 $this->writeLog('------------lookupTransaction [responseResult] ---------','debug');
     1090                $this->writeLog('------------lookupTransaction [responseResult] ---------', null,'debug', $checkoutHash);
    11001091                $order_id = (int)$responseObject->merchantTransactionId;
    11011092                $payment_id   = $responseObject->id;
     
    11101101                }
    11111102               
    1112                 $this->writeLog('------------lookupTransaction 1 ---------','debug');
    1113                 $this->writeLog($debugArray,'info');
     1103                $this->writeLog('------------lookupTransaction 1 ---------', $debugArray,'debug', $checkoutHash);
    11141104                wp_send_json_success(['valid' => true, /*'resourcePath'=> $resourcePath,*/ 'responseObject' => $responseObject, "responseResult" => $responseResult, "url" => $url]);
    11151105            } else {
    1116                 $this->writeLog('------------lookupTransaction 2 ---------','debug');
    1117                 $this->writeLog($debugArray,'info');
     1106                $this->writeLog('------------lookupTransaction 2 ---------', $debugArray,'debug', $checkoutHash);
    11181107                wp_send_json_error(['error' => 'responseObject','message' => 'is not object', 'data' => $ordertnxData]);
    11191108            }
    11201109        }
    11211110               
    1122         $this->writeLog('------------lookupTransaction 3 ---------','debug');
    1123         $this->writeLog($debugArray,'info');
     1111        $this->writeLog('------------lookupTransaction 3 ---------', $debugArray,'debug', $checkoutHash);
    11241112        wp_send_json_error(['error' => 'resourcePath error','message' => 'error']);
    11251113    }
     
    11741162    public function verifyTransactionStatus( $resourcePath, $order_id ){
    11751163        if( empty( $resourcePath ) ){
    1176             $this->writeLog( '----- verifyTransactionStatus [no resource path] -----', 'debug' );
    1177             $this->writeLog( "Resourcepath:" . $resourcePath, 'debug' );
     1164            $this->writeLog( '----- verifyTransactionStatus [no resource path: ' . $resourcePath . '] -----', null, 'debug' );
    11781165            wc_add_notice( __('Uncertain Response. Please report this to the merchant before reattempting payment. They will need to verify if this transaction is successful. Ref:' . $resourcePath), 'error');
    11791166            return false;
    11801167        }
    11811168        if( empty( $order_id ) ){
    1182             $this->writeLog( '----- verifyTransactionStatus [no order id] -----', 'debug' );
    1183             $this->writeLog( "Order id:" . $order_id, 'debug' );
     1169            $this->writeLog( '----- verifyTransactionStatus [no order id: ' . $order_id . '] -----', null, 'debug' );
    11841170            wc_add_notice( __('Uncertain Response. Please report this to the merchant before reattempting payment. They will need to verify if this transaction is successful. Ref:' . $resourcePath), 'error');
    11851171            return false;
     
    12041190        ];
    12051191        $executionTime['verificationInit'] = time();
    1206         $this->writeLog( '------------verifyTransactionStatus [URL and Data Sent] -----------', 'debug' );
    1207         $this->writeLog( [ 'url' => $url, 'params' => $arg ], 'info' );
     1192        $this->writeLog( '------------verifyTransactionStatus [URL and Data Sent] -----------', [ 'url' => $url, 'params' => $arg ], 'debug' );
    12081193       
    12091194        $response                = wp_remote_request( $url, $arg );
     
    12121197        if( is_wp_error( $response ) ) {
    12131198            $errorMessage        = $response->get_error_message();
    1214             $this->writeLog( '----- verifyTransactionStatus [returned wp_error, url:'.$url.'] -----', 'critical' );
    1215             $this->writeLog( $errorMessage, 'critical' );
    1216             $this->writeLog( '----- verifyTransactionStatus [params] -----', 'critical' );
    1217             $this->writeLog( $arg, 'critical' );
    1218             $this->writeLog( '----- verifyTransactionStatus [response] -----', 'critical' );
    1219             $this->writeLog( $response, 'critical' );
     1199            $this->writeLog( '----- verifyTransactionStatus [returned wp_error, url:'.$url.'] -----', ['errMsg' => $errorMessage, 'response' => $response], 'critical' );
    12201200            $secondaryCall       = true;
    12211201        }elseif( !isset( $response['body'] ) ) {
    1222             $this->writeLog( '----- verifyTransactionStatus [returned no status, url:'.$url.'] -----', 'critical' );
    1223             $this->writeLog( $response, 'critical' );
     1202            $this->writeLog( '----- verifyTransactionStatus [returned no status, url:'.$url.'] -----', ['response' => $response], 'critical' );
    12241203            $secondaryCall       = true;
    12251204        }
     
    12301209            $url          .= "&merchantTransactionId=" . (int)$order_id;
    12311210           
    1232             $this->writeLog( '----- verifyTransactionStatus [secondary API call init] -----', 'debug' );
    1233             $this->writeLog( $url, 'debug' );
    1234 
    12351211            $executionTime['secondaryapiInit'] = time();
    12361212            $response      = wp_remote_request( $url, $arg );
     1213            $this->writeLog( '----- verifyTransactionStatus [secondary API call init] -----', ['url' => $url, 'args' => $arg, 'response' => $response], 'debug' );
    12371214            if( is_wp_error( $response ) ) {
    12381215                $errorMessage        = $response->get_error_message();
    1239                 $this->writeLog( '----- verifyTransactionStatus [returned wp_error, url:'.$url.'] -----', 'critical' );
    1240                 $this->writeLog( $errorMessage, 'critical' );
    1241                 $this->writeLog( '----- verifyTransactionStatus [params] -----', 'critical' );
    1242                 $this->writeLog( $args, 'critical' );
    1243                 $this->writeLog( '----- verifyTransactionStatus [response] -----', 'critical' );
    1244                 $this->writeLog( $response, 'critical' );
    1245             }
    1246             $this->writeLog( '----- verifyTransactionStatus [secondary api call response data] -----', 'debug' );
    1247             $this->writeLog( $response, 'info' );
     1216                $this->writeLog( '----- verifyTransactionStatus [returned wp_error, url:'.$url.'] -----', $errorMessage, 'critical' );
     1217            }
    12481218            $executionTime['secondaryapiResponseAt'] = time();
    12491219        }
    1250         $this->writeLog( '----- verifyTransactionStatus [API Call execution time array] -----', 'debug' );
    1251         $this->writeLog( $executionTime, 'info' );
    1252 
     1220        $this->writeLog( '----- verifyTransactionStatus [API Call execution time array] -----', $executionTime, 'debug' );
     1221       
    12531222        if( is_wp_error( $response ) ) {
    12541223            $errorMessage        = $response->get_error_message();
    1255             $this->writeLog( '----- verifyTransactionStatus [returned wp_error, url:'.$url.'] -----', 'debug' );
    1256             $this->writeLog( $errorMessage, 'debug' );
     1224            $this->writeLog( '----- verifyTransactionStatus [Uncertain response and returned wp_error, url:'.$url.'] -----', null, 'debug' );
    12571225            wc_add_notice( __('Uncertain Response. Please report this to the merchant before reattempting payment. They will need to verify if this transaction is successful. Ref:' . $resourcePath), 'error');
    12581226            return false;
    12591227        }elseif( !isset( $response['body'] ) ) {
    1260             $this->writeLog( '----- verifyTransactionStatus [returned no status] -----', 'debug' );
    1261             $this->writeLog( $response, 'info' );
     1228            $this->writeLog( '----- verifyTransactionStatus [returned no status] -----', null, 'debug' );
    12621229            wc_add_notice( __('Uncertain Response. Please report this to the merchant before reattempting payment. They will need to verify if this transaction is successful. Ref:' . $resourcePath), 'error');
    12631230            return false;
     
    12671234        $responseData     = json_decode($responseResult);
    12681235        $responseData     = ( $secondaryCall === true ) ? ( isset($responseData->payments[0]) ? $responseData->payments[ ( count( $responseData->payments ) - 1 ) ] : new stdClass) : $responseData;
    1269         $this->writeLog( '----- verifyTransactionStatus [final response data] -----', 'debug' );
    1270         $this->writeLog( ['header' => $array, 'response' => $responseData], 'info' );
     1236        $this->writeLog( '----- verifyTransactionStatus [final response data] -----', $responseData, 'debug' );
    12711237        return $responseData;
    12721238    }
     
    12741240    public function verifyTransactionStatusByIDOrOrderID( $id, $order_id ){
    12751241        if( empty( $id ) ){
    1276             $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [no payment id] -----', 'debug' );
    1277             $this->writeLog( "Resourcepath:" . $id, 'debug' );
     1242            $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [no payment id] -----', null, 'debug' );
    12781243            wc_add_notice( __('Uncertain Response. Please report this to the merchant before reattempting payment. They will need to verify if this transaction is successful.'), 'error');
    12791244            return false;
     
    12811246        //$resourcePath = "/v1/checkouts/".$id."/payment";
    12821247        if( empty( $order_id ) ){
    1283             $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [no order id] -----', 'debug' );
    1284             $this->writeLog( "Order id:" . $order_id, 'debug' );
     1248            $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [no order id] -----', null, 'debug' );
     1249
    12851250            wc_add_notice( __('Uncertain Response. Please report this to the merchant before reattempting payment. They will need to verify if this transaction is successful. Ref:' . $id), 'error');
    12861251            return false;
     
    13041269        ];
    13051270        $executionTime['verificationInit'] = time();
    1306         $this->writeLog( '------------verifyTransactionStatusByIDOrOrderID [URL and Data Sent] -----------', 'debug' );
    1307         $this->writeLog( [ 'url' => $url, 'params' => $arg ], 'info' );
     1271        $this->writeLog( '------------verifyTransactionStatusByIDOrOrderID [URL and Data Sent] -----------', [ 'url' => $url, 'params' => $arg ], 'debug' );
    13081272       
    13091273        $response                = wp_remote_request( $url, $arg );
     
    13121276        if( is_wp_error( $response ) ) {
    13131277            $errorMessage        = $response->get_error_message();
    1314             $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned wp_error] -----', 'critical' );
    1315             $this->writeLog( $errorMessage, 'critical' );
     1278            $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned wp_error] -----', ['errMsg' => $errorMessage, 'response' => $response], 'critical' );
    13161279            $secondaryCall       = true;
    13171280        }elseif( !isset( $response['body'] ) ) {
    1318             $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned no status] -----', 'warning' );
    1319             $this->writeLog( $response, 'warning' );
     1281            $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned no status] -----', $response, 'warning' );
    13201282            $secondaryCall       = true;
    13211283        }
     
    13261288            $url          .= "&merchantTransactionId=" . (int)$order_id;
    13271289           
    1328             $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [secondary API call init] -----', 'debug' );
    1329             $this->writeLog( $url, 'debug' );
     1290            $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [secondary API call init, url:' . $url . '] -----', null, 'debug' );
    13301291
    13311292            $executionTime['secondaryapiInit'] = time();
     
    13331294            if( is_wp_error( $response ) ) {
    13341295                $errorMessage        = $response->get_error_message();
    1335                 $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned wp_error] -----', 'critical' );
    1336                 $this->writeLog( $errorMessage, 'critical' );
     1296                $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned wp_error for secondary api call] -----', ['errMsg' => $errorMessage, 'response' => $response], 'critical' );
    13371297                return false;
    13381298            }
    1339             $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [secondary api call response data] -----', 'debug' );
    1340             $this->writeLog( $response, 'info' );
     1299            $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [secondary api call response data] -----', $response, 'debug' );
    13411300            $executionTime['secondaryapiResponseAt'] = time();
    13421301        }
    1343         $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [API Call execution time array] -----', 'debug' );
    1344         $this->writeLog( $executionTime, 'info' );
     1302        $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [API Call execution time array] -----', $executionTime, 'debug' );
    13451303
    13461304        if( is_wp_error( $response ) ) {
    13471305            $errorMessage        = $response->get_error_message();
    1348             $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned wp_error] -----', 'critical' );
    1349             $this->writeLog( $errorMessage, 'critical' );
     1306            $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned wp_error] -----', ['err' => $errorMessage, 'response' => $response], 'critical' );
    13501307            wc_add_notice( __('Uncertain Response. Please report this to the merchant before reattempting payment. They will need to verify if this transaction is successful. Ref:' . $id), 'error');
    13511308            return false;
    13521309        }elseif( !isset( $response['body'] ) ) {
    1353             $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned no status] -----', 'warning' );
    1354             $this->writeLog( $response, 'warning' );
     1310            $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [returned no status] -----', $response, 'warning' );
    13551311            wc_add_notice( __('Uncertain Response. Please report this to the merchant before reattempting payment. They will need to verify if this transaction is successful. Ref:' . $id), 'error');
    13561312            return false;
    13571313        }
    1358         //$this->shouldLogResponseHandler($response, $array);
    13591314        $responseResult   = $response['body'];
    13601315        $responseData     = json_decode($responseResult);
    13611316        $responseData     = ( $secondaryCall === true ) ? ( isset($responseData->payments[0]) ? $responseData->payments[ ( count( $responseData->payments ) - 1 ) ] : new stdClass) : $responseData;
    1362         $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [final response data] -----', 'debug' );
    1363         $this->writeLog( ['header' => $array, 'response' => $responseData], 'info' );
     1317        $this->writeLog( '----- verifyTransactionStatusByIDOrOrderID [final response data] -----', $responseData, 'debug' );
    13641318        return $responseData;
    13651319    }
     
    13811335            $url = $this->proxyUrl;
    13821336        }
    1383         $this->writeLog('------------prepareRemoteRequest [preparing request from API] -----------','debug');
    1384         $this->writeLog($url,'debug');
    13851337       
    13861338        $response = wp_remote_request( $url , $array);
     1339        $this->writeLog( '------------prepareRemoteRequest [preparing request from API] -----------', [
     1340            'url'      => $url,
     1341            'response' => $response,
     1342        ], 'debug' );
    13871343
    13881344        if( is_wp_error( $response ) ) {
    13891345            $errorMessage        = $response->get_error_message();
    1390             $this->writeLog( '----- prepareRemoteRequest [returned wp_error] -----', 'critical' );
    1391             $this->writeLog( $errorMessage, 'critical' );
    1392             $this->writeLog( $response, 'critical' );
    1393         }
    1394 
    1395         $this->writeLog( ['request' => $array, 'response' => $response], 'info' );
    1396 
    1397         //$this->shouldLogResponseHandler($response, $array);
    1398        
    1399         $responseData = json_decode($response['body']);       
    1400         //$this->writeLog( ['header' => $array, 'response' => $responseData], 'info' );
     1346            $this->writeLog( '----- prepareRemoteRequest [returned wp_error] -----', ['error' => $errorMessage], 'critical' );
     1347        }
     1348       
     1349        $responseData = json_decode($response['body']);
    14011350        return $responseData;
    14021351    }
     
    14571406        return $notes;
    14581407    }
    1459    
     1408
    14601409    public function parseResponseData($responseData){
    14611410        global $woocommerce;
    14621411        $debugTimeArray[0] = time();
    14631412        $array = ['notices'=>[]];
    1464         $this->writeLog('------parseResponseData ---------','debug');
    1465         $this->writeLog($responseData,'info');
     1413        $this->writeLog('------parseResponseData ---------', null,'debug');
    14661414        $paymentSuccess = false;
    14671415        if(isset($responseData->id)){
    1468             $this->writeLog('------parseResponseData [response id valid]---------','debug');
     1416            $this->writeLog('------parseResponseData [response id valid]---------', null,'debug');
    14691417            $transaction_id = (string)$responseData->id;
    14701418            if(isset($responseData->result->code)){
     
    14831431                $debugTimeArray[1] = time();
    14841432                $order = wc_get_order( $order_id );
    1485                 $this->writeLog('------parseResponseData [order_details for orderid:'.$order_id.']---------','debug');
    1486                 $this->writeLog($order,'info');
    1487                 $this->writeLog('payment status code:' . $payment_result_code,'info');
     1433                $this->writeLog( '------parseResponseData [order_details for orderid:'.$order_id.']---------', [
     1434                    'paymentstatuscode' => $payment_result_code
     1435                ], 'debug' );
     1436
    14881437                $amount = number_format($order->get_total(), 2, '.', '');
    14891438                $order_data = $order->get_data();
    1490                 if($order_data['payment_method'] !== $this->id){
     1439                /*if($order_data['payment_method'] !== $this->id){
    14911440                    $checks = false;
    14921441                    $array['notices'][] = 'payment_method not tpcards';
     
    15111460                    $checks = false;
    15121461                    $array['notices'][] = 'Cart items/amount have changed, please retry paying for this order.';
    1513                 }
     1462                }*/
    15141463                if($checks){
    15151464                    if($paymentSuccess === true){
    1516                         $this->writeLog('------parseResponseData [payment is successful] ---------','debug');
     1465                        $this->writeLog( '------parseResponseData [payment is successful] ---------', null,'debug');
    15171466                        //good to go..
    15181467                        $order->payment_complete( $transaction_id );
    1519                         $this->writeLog('------parseResponseData [set order with payment complete] ---------','debug');
     1468                        $this->writeLog('------parseResponseData [set order with payment complete] ---------', null,'debug');
    15201469                        $debugTimeArray[2] = time();
    15211470                        //if PA// capture
     
    15361485                        }
    15371486                        $order->save();
    1538                         $this->writeLog('------parseResponseData [order updated after all set of data] ---------','debug');
     1487                        $this->writeLog('------parseResponseData [order updated after all set of data] ---------', null,'debug');
    15391488                        $debugTimeArray[6] = time();
    15401489                        $array['result'] = 'success';
    15411490                        $array['redirect'] = $this->get_return_url( $order );
    15421491                        $debugTimeArray[7] = time();
     1492                        $cartHash          = WC()->cart->get_cart_hash();
    15431493                        $woocommerce->cart->empty_cart();
    15441494                        $debugTimeArray[8] = time();
    1545                         $this->writeLog('------------parseResponseData [paymentsuccess] ---------','debug');
    1546                         $this->writeLog($debugTimeArray,'info');
     1495                        $this->writeLog('------------parseResponseData [paymentsuccess] ---------', $debugTimeArray,'debug', $cartHash);
    15471496                    } else {
    1548                         $this->writeLog('------parseResponseData [payment not success] ---------','debug');
    1549                         $this->writeLog(['code' => $code, 'description' => $description],'info');
     1497                        $this->writeLog('------parseResponseData [payment not success] ---------', ['code' => $code, 'description' => $description, 'checks' => $array],'debug');
    15501498                        $order->add_order_note( $code, false );
    15511499                        $order->add_order_note( $description, false );
     
    15591507                    if( $paymentSuccess === true ){
    15601508                        $array['notices'][] = 'Payment is successful, but due to some error we can not process further. Please contact support with payment reference ' . $responseData->id;
     1509                        $this->writeLog('------parseResponseData [payment success, but after payment check failed] ---------', ['checks' => $array],'debug');
    15611510                    }else{
    15621511                        $array['notices'][] = 'Payment failed';
     1512                        $this->writeLog('------parseResponseData [payment failed and after payment check failed] ---------', ['checks' => $array],'debug');
    15631513                    }
    15641514                    $array['notices'][] = 'checks failed.';
     
    15671517                $array['notices'][] = 'No order_id found, please retry payment.';
    15681518                //perform reversal on $paymentSuccess && $responseData->id
    1569                 $this->writeLog('----------parseResponseData [no order id found] ----------','debug');
    1570                 $this->writeLog($array['notices'],'info');
     1519                $this->writeLog('----------parseResponseData [no order id found / merchantTransactionId not found] ----------', ['checks' => $array],'debug');
    15711520            }
    15721521        } else {
    15731522            $array['notices'][] = 'No transaction id found, please retry payment.';
    1574             $this->writeLog('----------parseResponseData no transaction id found------------','critical');
    1575             $this->writeLog($array['notices'],'critical');
    1576         }
    1577         $this->writeLog($array,'info');
     1523            $this->writeLog('----------parseResponseData no transaction id found------------', ['checks' => $array],'critical');
     1524        }
    15781525        wc_clear_notices();
    15791526        foreach($array['notices'] as $notice){
     
    16831630    public function process_payment($order_id){
    16841631        //first write to log if set.
    1685         $this->writeLog('-----------process_payment [POST] -----------', 'debug');
    1686         $this->writeLog($_POST,'info');
     1632        $this->writeLog('-----------process_payment [POST initiated] -----------', null, 'debug');
    16871633       
    16881634        //check the order_id exists.
    16891635        $order = wc_get_order($order_id);
    16901636        if($order===false){
    1691             $this->writeLog('-----------process_payment [Order does not exists]-----------', 'debug');
     1637            $this->writeLog('-----------process_payment [Order does not exists]-----------', null, 'debug');
    16921638            wc_add_notice('There was a problem creating your order, please try again.', 'error');
    16931639            return;
     
    17041650        if(!isset($handler['pending'])){
    17051651            if(isset($handler['messages'])){
    1706                 $this->writeLog('-----------process_payment [pending order has message issue]------------','debug');
     1652                $this->writeLog('-----------process_payment [pending order has message issue]------------', null,'debug');
    17071653                foreach($handler['messages'] as $noticeType => $noticeItems){
    17081654                    foreach($noticeItems as $notice){
     
    17111657                }
    17121658            }
    1713             $this->writeLog('-----------process_payment [if pending order does not have message] ----------','debug');
    1714             $this->writeLog($handler,'info');
     1659            $this->writeLog('-----------process_payment [if pending order does not have message] ----------', $handler,'debug');
    17151660            return $handler;
    17161661        }
     
    17261671        }
    17271672        $additionalParams['shopperResultUrl'] = $shopperResultUrl;
    1728         $this->writeLog('-----------process_payment [shopperResultUrl as additionalParameters] ----------','debug');
    1729         $this->writeLog($additionalParams,'info');
     1673        $this->writeLog('-----------process_payment [shopperResultUrl as additionalParameters] ----------', $additionalParams,'debug');
    17301674
    17311675        //check for RG slick
     
    17481692        }
    17491693        if($checkoutId === false){
    1750             $this->writeLog('-----------process_payment [checkout id missing and create new checkout id] -----------','debug');
     1694            $this->writeLog('-----------process_payment [checkout id missing and create new checkout id] -----------', null,'debug');
    17511695            $checkoutId = $this->createCheckoutArray(false,false,$registrationId);
    17521696        }
     
    17551699            $handler['uuid'] = $checkoutId;
    17561700            $handler['pay_url'] = $order->get_checkout_payment_url( false );
    1757             $this->writeLog('-----------process_payment [checkout id not missing]----------', 'debug');
    1758             $this->writeLog($handler,'info');
     1701            $this->writeLog('-----------process_payment [checkout id not missing]----------', null, 'debug');
    17591702        } else {
    1760             $this->writeLog('-----------process_payment [still checkoutid missing]-----------','debug');
     1703            $this->writeLog('-----------process_payment [still checkoutid missing]-----------', null,'debug');
    17611704            wc_add_notice($responseUpdate->result->description, 'error');
    17621705            $handler['refresh'] = true;
     
    17791722        $checkoutJson = json_encode($payload);
    17801723       
    1781         $this->writeLog('-----------process_payment [after payload is prepared]----------','debug');
    1782         $this->writeLog($payload,'info');
     1724        $this->writeLog('-----------process_payment [after payload is prepared]----------', $payload,'debug');
    17831725       
    17841726        if($this->jsLogging === true){
     
    17911733            $handler['responseUpdate'] = $responseUpdate;
    17921734        }
    1793         $this->writeLog('----------process_payment [after transaction data updated]--------','debug');
    1794         $this->writeLog($responseUpdate,'info');
     1735        $this->writeLog('----------process_payment [after transaction data updated]--------', $responseUpdate,'debug');
    17951736        if(isset($responseUpdate->result->code)){
    17961737            $checkoutCode = $responseUpdate->result->code;
     
    18001741            } else {
    18011742                if($updateCheckout === true){
    1802                     $this->writeLog('-------process_payment [successfully transaction data updated on successfull payment]---------','debug');
     1743                    $this->writeLog('-------process_payment [successfully transaction data updated on successfull payment]---------', null,'debug');
    18031744                    $handler['execute'] = true;
    18041745                } else {
     
    18071748            }
    18081749        } else {
    1809             $this->writeLog('-------process_payment [Could not update checkout]---------','debug');
     1750            $this->writeLog('-------process_payment [Could not update checkout]---------', null,'debug');
    18101751            wc_add_notice('Could not update checkout', 'error');
    18111752            $handler['refresh']=true;
     
    18161757        $handler['sqlRes'] = $this->insTxDbRecord($order_data,$this->platformBase,$checkoutId,$checkoutCode,$checkoutJson);
    18171758       
    1818         $this->writeLog('---------process_payment [insTxDbRecord called] -----------','debug');
    1819         $this->writeLog($handler,'info');
     1759        $this->writeLog('---------process_payment [insTxDbRecord called] -----------', $handler,'debug');
    18201760       
    18211761        return $handler;
  • totalprocessing-card-payments/trunk/includes/tp-payment-gateway-helper-trait.php

    r2862579 r2900759  
    335335        $order->save();
    336336    }
    337    
    338     protected function writeLog( $obj, $level = false ){
     337
     338    protected function writeLog( $label, $obj, $level = false, $uuid = null ){
    339339        $debug     = $this->get_option( 'serversidedebug' );
    340340        if( $debug != 'yes' ){
     
    345345            return;
    346346        }
    347        
    348         $logger     = wc_get_logger();
    349        
     347
     348        $logger                   = wc_get_logger();
     349        $GLOBALS['logcounter']    = isset( $GLOBALS['logcounter'] ) ? $GLOBALS['logcounter'] + 1 : 1;
     350
    350351        $context    = array( 'source' => TP_CONSTANTS::GATEWAY_ID );
     352        $cartHash   = !empty( $uuid ) ? $uuid : WC()->cart->get_cart_hash();
     353        $logMessage = '['.$cartHash.'] Stack #' . $GLOBALS['logcounter'] . " : " . $label . ( $obj != null ? "\n" . wc_print_r( $obj, true ) : '' );
    351354
    352355        switch ( $level ) {
    353356            case 'critical':
    354                 $logger->critical( wc_print_r( $obj , true ) , $context );
     357                $logger->critical( $logMessage, $context );
    355358                break;
    356359            case 'debug':
    357                 $logger->debug( wc_print_r( $obj , true ) , $context );
     360                $logger->debug( $logMessage, $context );
    358361                break;
    359362            case 'emergency':
    360                 $logger->emergency( wc_print_r( $obj , true ) , $context );
     363                $logger->emergency( $logMessage, $context );
    361364                break;
    362365            case 'error':
    363                 $logger->error( wc_print_r( $obj , true ) , $context );
     366                $logger->error( $logMessage, $context );
    364367                break;
    365368            case 'warning':
    366                 $logger->warning( wc_print_r( $obj , true ) , $context );
     369                $logger->warning( $logMessage, $context );
    367370                break;
    368371            default:
    369                $logger->info( wc_print_r( $obj , true ) , $context );
    370         }
    371        
     372               $logger->info( $logMessage, $context );
     373        }
     374
    372375        return true;
    373376    }
  • totalprocessing-card-payments/trunk/readme.txt

    r2888976 r2900759  
    44Requires at least: 5.2.0
    55Tested up to: 6.1.1
    6 Stable tag: 5.3.2
     6Stable tag: 5.3.3
    77Requires PHP: 7.0
    88License: GPLv3
     
    4848== Changelog ==
    4949
     50= 5.3.3 - 18-04-2023 19:30 =
     51
     52* Optimized log system
     53* removed unwanted validations
     54
    5055= 5.3.2 - 29-03-2023 14:00 =
    5156
  • totalprocessing-card-payments/trunk/totalprocessing-card-payments-and-gateway-woocommerce.php

    r2888976 r2900759  
    1010 * Plugin URI:           https://www.totalprocessing.com/woocommerce/cards
    1111 * Description:          Accept all major credit and debit cards. Fast, seamless, and flexible.
    12  * Version:              5.3.2
     12 * Version:              5.3.3
    1313 * Author:               Total Processing Limited
    1414 * Copyright:            2022 Total Processing Limited.
Note: See TracChangeset for help on using the changeset viewer.