Plugin Directory

Changeset 2636352


Ignore:
Timestamp:
11/27/2021 05:37:40 PM (4 years ago)
Author:
oife
Message:

added Konga Kxpress Delivery company

Location:
shiip/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • shiip/trunk/README.txt

    r2633437 r2636352  
    55Requires at least: 4.7
    66Tested up to: 5.8
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.3
    88Requires PHP: 5.6
    99License: GPLv2 or later
  • shiip/trunk/includes/shiipFunctions.php

    r2633437 r2636352  
    6161    $body = wp_remote_retrieve_body( $response );
    6262   
    63     error_log("resp1.".$body);
     63    // error_log("resp1.".$body);
    6464   
    6565   
     
    116116    $phone = get_option("wc_shiip_settings_contactnumber");
    117117   
    118     $base_uri  = "https://delivery.apiideraos.com/api/tariffs/getquotes/".$provider;
     118    $base_uri  = "https://delivery.apiideraos.com/api/v2/tariffs/getquotes/".$provider;
    119119   
    120120    $url = $base_uri.'?type=local&delivery_weight_id=2&
     
    176176    $body = wp_remote_retrieve_body( $response );
    177177   
    178     // error_log("resp22.".$body);
     178    error_log("resp22.".$body);
    179179
    180180    if ( is_wp_error( $response ) ) {
     
    182182        $message = $response->get_error_message();
    183183       
    184         error_log("Messsresp22.".$message);
     184        // error_log("Messsresp22.".$message);
    185185    }
    186186
  • shiip/trunk/shiip.php

    r2633437 r2636352  
    1717* Plugin URI:        https://app.goshiip.com/
    1818* Description:       The only shipping app you will ever need for your business. You can “Shiip” with top logistics companies at half their standard rates
    19 * Version:           1.0.1
     19* Version:           1.0.3
    2020* Author:            Shiip LLC
    2121* Author URI:        https://goshiip.com/
     
    4040* Rename this for your plugin and update it as you release new versions.
    4141*/
    42 define( 'SHIIP_VERSION', '1.0.1' );
     42define( 'SHIIP_VERSION', '1.0.3' );
    4343
    4444
     
    6666            'id'   => 'wc_shiip_settings_titleregister'
    6767        );
    68 
     68       
    6969        $settings_catalog_options[] = array(
    7070            'name' => __( 'Shiip Login details', 'text-domain' ),
     
    144144*/
    145145function deactivate_shiip() {
    146 
     146   
    147147    delete_option("wc_shiip_user");
    148148    delete_option("wc_shiip_user_token");
    149149    delete_option("wc_shiip_user_name");
    150 
    151 
     150   
     151   
    152152}
    153153
     
    196196        $shipping_metadata  = $item_data['meta_data'];
    197197    }
    198                
    199                 $jsonString  = json_encode($shipping_metadata);
    200                
    201                 $someObject = json_decode($jsonString);
    202                 $rateId =  $someObject[0]->value;
    203                 $redisKey =  $someObject[1]->value;
    204 
    205                 $userData = get_option("wc_shiip_user");
    206                 $someObject = json_decode($userData);
    207                 $id = $someObject->data->user->id;
    208 
    209                 $data  =  '{
    210                     "redis_key": "'.$redisKey.'",
    211                     "user_id": '.$id.',
    212                     "platform": "wordpress - '.get_option('blogname').'",
    213                     "rate_id": "'.$rateId.'"
    214                 }';
    215 
    216                 $data = str_replace("\n\t\t\t\t\t","",$data);
    217                 $data = str_replace(array("\r", "\n","\t"), '', $data);
    218                 error_log($data);
    219            
    220                
    221                 $options = [
    222                     'body'        => $data,
    223                     'headers'     => [
    224                         'Content-Type' => 'application/json',
    225                     ],
    226                     'timeout'     => 60,
    227                     'redirection' => 5,
    228                     'blocking'    => true,
    229                     'httpversion' => '1.0',
    230                     'sslverify'   => false,
    231                     'data_format' => 'body',
    232                 ];
    233                
    234                 $response = wp_remote_post( "https://delivery.apiideraos.com/api/v2/shipments", $options );
    235                 $responseBody = wp_remote_retrieve_body( $response );
    236            
    237                
    238                
    239                
    240                
    241                
    242             }
    243            
    244             if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    245                
    246                 add_filter( 'woocommerce_get_sections_shipping', 'shiip_add_loginsection' );
    247                 add_filter( 'woocommerce_get_settings_shipping', 'shiip_add_loginsettings', 10, 2 );
    248                
    249                 add_action( 'woocommerce_review_order_after_submit', 'shiip_showrates' );
    250                 add_action( 'woocommerce_shipping_init', 'shiip_shiping_init' );
    251                
    252                 add_action('woocommerce_thankyou', 'shiip_bookshipment', 10, 1);
    253                
    254             }
    255            
    256            
    257             if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    258                
    259                 function your_shipping_method_init() {
    260                         class WC_ShiipMethod extends WC_Shipping_Method {
     198   
     199    $jsonString  = json_encode($shipping_metadata);
     200   
     201    $someObject = json_decode($jsonString);
     202    $rateId =  $someObject[0]->value;
     203    $redisKey =  $someObject[1]->value;
     204   
     205    $userData = get_option("wc_shiip_user");
     206    $someObject = json_decode($userData);
     207    $id = $someObject->data->user->id;
     208   
     209    $data  =  '{
     210        "redis_key": "'.$redisKey.'",
     211        "user_id": '.$id.',
     212        "platform": "wordpress - '.get_option('blogname').'",
     213        "rate_id": "'.$rateId.'"
     214    }';
     215   
     216    $data = str_replace("\n\t\t\t\t\t","",$data);
     217    $data = str_replace(array("\r", "\n","\t"), '', $data);
     218    error_log($data);
     219   
     220   
     221    $options = [
     222        'body'        => $data,
     223        'headers'     => [
     224            'Content-Type' => 'application/json',
     225        ],
     226        'timeout'     => 60,
     227        'redirection' => 5,
     228        'blocking'    => true,
     229        'httpversion' => '1.0',
     230        'sslverify'   => false,
     231        'data_format' => 'body',
     232    ];
     233   
     234    $response = wp_remote_post( "https://delivery.apiideraos.com/api/v2/shipments", $options );
     235    $responseBody = wp_remote_retrieve_body( $response );
     236   
     237   
     238   
     239   
     240   
     241   
     242}
     243
     244if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
     245   
     246    add_filter( 'woocommerce_get_sections_shipping', 'shiip_add_loginsection' );
     247    add_filter( 'woocommerce_get_settings_shipping', 'shiip_add_loginsettings', 10, 2 );
     248   
     249    add_action( 'woocommerce_review_order_after_submit', 'shiip_showrates' );
     250    add_action( 'woocommerce_shipping_init', 'shiip_shiping_init' );
     251   
     252    add_action('woocommerce_thankyou', 'shiip_bookshipment', 10, 1);
     253   
     254}
     255
     256
     257if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
     258   
     259    function your_shipping_method_init() {
     260        class WC_ShiipMethod extends WC_Shipping_Method {
     261           
     262           
     263            /**
     264            * Constructor for your shipping class
     265            *
     266            * @access public
     267            * @return void
     268            */
     269            public function __construct() {
     270                $this->id = 'kwik_shipping';
     271            }
     272           
     273            /**
     274            * Init your settings
     275            *
     276            * @access public
     277            * @return void
     278            */
     279            public function init() {
     280               
     281            }
     282            /**
     283            * calculate_shipping function.
     284            *
     285            * @access public
     286            * @param mixed $package
     287            * @return void
     288            */
     289            public function calculate_shipping($package = array()) {
     290               
     291               
     292               
     293                $rates = getRates("kwik",$package);
     294               
     295                $parse =  json_decode($rates);
     296               
     297                $kwikamt = "0";
     298                $estDays = "Same Day Delivery";
     299                $rateId = "";
     300                $redisKey = "";
     301               
     302                if(strcasecmp($parse->message, "OK") == 0 && $parse->status == true ){
     303                   
     304                    $count = 1;
     305                   
     306                    // //check number of companies providing rates
     307                    // $rateSize = sizeof($parse->data->rates);
     308                   
     309                    if($parse->data->rates == null){
     310                        return ;
     311                    }
     312                   
     313                    $redisKey = $parse->data->kwik_key;
     314                   
     315                   
     316                    $rate = $parse->data->rates;
     317                   
     318                   
     319                    if($rate->currency == "NGN"){//only show ngn
     320                       
     321                        $estDays = "Same Day Delivery";
     322                       
     323                       
     324                        if($rate->estimated_days == null){
     325                            $kwikamt = $rate->amount;
    261326                           
    262                            
    263                             /**
    264                             * Constructor for your shipping class
    265                             *
    266                             * @access public
    267                             * @return void
    268                             */
    269                             public function __construct() {
    270                                 $this->id = 'kwik_shipping';
    271                             }
    272                            
    273                             /**
    274                             * Init your settings
    275                             *
    276                             * @access public
    277                             * @return void
    278                             */
    279                             public function init() {
    280                            
    281                             }
    282                             /**
    283                             * calculate_shipping function.
    284                             *
    285                             * @access public
    286                             * @param mixed $package
    287                             * @return void
    288                             */
    289                             public function calculate_shipping($package = array()) {
    290                                
    291                                
    292                                
    293                                 $rates = getRates("kwik",$package);
    294                                
    295                                 $parse =  json_decode($rates);
    296                                
    297                                 $kwikamt = "0";
    298                                 $estDays = "Same Day Delivery";
    299                                 $rateId = "";
    300                                 $redisKey = "";
    301                                
    302                                 if(strcasecmp($parse->message, "OK") == 0 && $parse->status == true ){
    303                                    
    304                                     $count = 1;
    305                                    
    306                                     //check number of companies providing rates
    307                                     $rateSize = sizeof($parse->data->rates);
    308                                    
    309                                     $redisKey = $parse->data->kwik_key;
    310                                    
    311                                
    312                                    
    313                                     foreach ($parse->data->rates as $rateServer) {
    314                                         if(!isset($rateServer->status)){//if status does not exist then we have data to show
    315                                            
    316                                             $rate = $rateServer;
    317                                            
    318                                             if($rate->currency == "NGN"){//only show ngn
    319                                                
    320                                                 $estDays = "Same Day Delivery";
    321                                                
    322                                                
    323                                                 if($rate->estimated_days == null){
    324                                                     $kwikamt = $rate->amount;
    325                                                    
    326                                                 }else{
    327                                                     $estDays = $rate->estimated_days;
    328                                                     $kwikamt = $rate->amount;
    329                                                 }
    330                                                
    331                                                 $rateId = $rate->courier->id;
    332                                                
    333                                             }
    334                                            
    335                                         }else{//status does exist
    336                                             error_log("status does exist -".$rateServer->type);
    337                                            
    338                                         }
    339                                     }
    340                                    
    341                                    
    342                                    
    343                                 }else{
    344                                    
    345                                 }
    346                                
    347                                
    348                                 $rate2 = array(
    349                                     'id' => "kwik_shipping",
    350                                     'label' => "Kwik - ".$estDays,
    351                                     'cost' => $kwikamt,
    352                                     'calc_tax' => 'per_item',
    353                                     'method_id' => $redisKey,
    354                                     'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
    355                                 );
    356                                
    357                                
    358                                 // Register the rate
    359                                 if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
    360                                     $this->add_rate($rate2);
    361                                 }
    362                                
    363                             }
     327                        }else{
     328                            $estDays = $rate->estimated_days;
     329                            $kwikamt = $rate->amount;
    364330                        }
    365331                       
    366                         class WC_ShiipMethod_GIG extends WC_Shipping_Method {
    367                             /**
    368                             * Constructor for your shipping class
    369                             *
    370                             * @access public
    371                             * @return void
    372                             */
    373                             public function __construct() {
    374                                 $this->id = 'gig_shipping';
    375                                 $this->init();
    376                             }
    377                            
    378                             /**
    379                             * Init your settings
    380                             *
    381                             * @access public
    382                             * @return void
    383                             */
    384                             public function init() {
    385                                
    386                             }
    387                             /**
    388                             * calculate_shipping function.
    389                             *
    390                             * @access public
    391                             * @param mixed $package
    392                             * @return void
    393                             */
    394                             public function calculate_shipping($package = array()) {
    395                                 $rates = getRates("gig",$package);
    396                                
    397                                 $parse =  json_decode($rates);
    398                                
    399                                 $kwikamt = "0";
    400                                 $estDays = "Same Day Delivery";
    401                                 $rateId = "";
    402                                 $redisKey = "";
    403                                
    404                                 if(strcasecmp($parse->message, "OK") == 0 && $parse->status == true ){
    405                                    
    406                                     $count = 1;
    407                                    
    408                                     //check number of companies providing rates
    409                                     $rateSize = sizeof($parse->data->rates);
    410                                    
    411                                     $redisKey = $parse->data->redis_key;
    412                                    
    413                                     foreach ($parse->data->rates as $rateServer) {
    414                                         if(!isset($rateServer->status)){//if status does not exist then we have data to show
    415                                            
    416                                             $rate = $rateServer;
    417                                            
    418                                             if($rate->currency == "NGN"){//only show ngn
    419                                                
    420                                                 $estDays = "Same Day Delivery";
    421                                                
    422                                                
    423                                                 if($rate->estimated_days == null){
    424                                                
    425                                                     $kwikamt = $rate->amount;
    426                                                 }else{
    427                                                     $estDays = $rate->estimated_days;
    428                                                     $kwikamt = $rate->amount;
    429                                                 }
    430                                                
    431                                                 $rateId = $rate->courier->id;
    432                                                
    433                                             }
    434                                            
    435                                         }else{//status does exist
    436                                             error_log("status does exist -".$rateServer->type);
    437                                            
    438                                         }
    439                                     }
    440                                    
    441                                    
    442                                    
    443                                 }else{
    444                                    
    445                                 }
    446                                 $rate = array(
    447                                     'id' => "gig_shipping",
    448                                     'label' => "GIG - ".$estDays,
    449                                     'cost' => $kwikamt,
    450                                     'calc_tax' => 'per_item',
    451                                     'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
    452                                 );
    453                                
    454                                
    455                                 // Register the rate
    456                                 if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
    457                                     $this->add_rate($rate);
    458                                 }
    459                                
    460                             }
    461                         }
     332                        $rateId = $rate->courier->id;
    462333                       
     334                    }
     335                   
     336                }else{//status does exist
     337                    error_log("status does exist -".$rateServer->type);
     338                   
     339                }
     340               
     341               
     342               
     343               
     344                $rate2 = array(
     345                    'id' => "kwik_shipping",
     346                    'label' => "Kwik - ".$estDays,
     347                    'cost' => $kwikamt,
     348                    'calc_tax' => 'per_item',
     349                    'method_id' => $redisKey,
     350                    'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
     351                );
     352               
     353               
     354                // Register the rate
     355                if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
     356                    $this->add_rate($rate2);
     357                }
     358               
     359            }
     360        }
     361       
     362        class WC_ShiipMethod_GIG extends WC_Shipping_Method {
     363            /**
     364            * Constructor for your shipping class
     365            *
     366            * @access public
     367            * @return void
     368            */
     369            public function __construct() {
     370                $this->id = 'gig_shipping';
     371                $this->init();
     372            }
     373           
     374            /**
     375            * Init your settings
     376            *
     377            * @access public
     378            * @return void
     379            */
     380            public function init() {
     381               
     382            }
     383            /**
     384            * calculate_shipping function.
     385            *
     386            * @access public
     387            * @param mixed $package
     388            * @return void
     389            */
     390            public function calculate_shipping($package = array()) {
     391                $rates = getRates("gig",$package);
     392               
     393                $parse =  json_decode($rates);
     394               
     395                $kwikamt = "0";
     396                $estDays = "Same Day Delivery";
     397                $rateId = "";
     398                $redisKey = "";
     399               
     400               
     401                if($parse->data->rates == null){
     402                    return ;
     403                }
     404               
     405                $redisKey = $parse->data->redis_key;
     406               
     407               
     408                $rate = $parse->data->rates;
     409               
     410                if($rate->currency == "NGN"){//only show ngn
     411                   
     412                    $estDays = "Same Day Delivery";
     413                   
     414                   
     415                    if($rate->estimated_days == null){
    463416                       
    464                         class WC_ShiipMethod_FEDEX extends WC_Shipping_Method {
    465                             /**
    466                             * Constructor for your shipping class
    467                             *
    468                             * @access public
    469                             * @return void
    470                             */
    471                             public function __construct() {
    472                                 $this->id = 'fedex_shipping';
    473                                 $this->init();
    474                             }
    475                            
    476                             /**
    477                             * Init your settings
    478                             *
    479                             * @access public
    480                             * @return void
    481                             */
    482                             public function init() {
    483                             }
    484                             /**
    485                             * calculate_shipping function.
    486                             *
    487                             * @access public
    488                             * @param mixed $package
    489                             * @return void
    490                             */
    491                             public function calculate_shipping($package = array()) {
    492                                
    493                                 $rates = getRates("fedex",$package);
    494                                
    495                                 $parse =  json_decode($rates);
    496                                
    497                                 $kwikamt = "0";
    498                                 $estDays = "Same Day Delivery";
    499                                
    500                                 $rateId = "";
    501                                 $redisKey = "";
    502                                
    503                                 if(strcasecmp($parse->message, "OK") == 0 && $parse->status == true ){
    504                                    
    505                                     $count = 1;
    506                                    
    507                                     //check number of companies providing rates
    508                                     $rateSize = sizeof($parse->data->rates);
    509                                    
    510                                     $redisKey = $parse->data->redis_key;
    511                                    
    512                                     foreach ($parse->data->rates as $rateServer) {
    513                                         if(!isset($rateServer->status)){//if status does not exist then we have data to show
    514                                            
    515                                             $rate = $rateServer;
    516                                            
    517                                             if($rate->currency == "NGN"){//only show ngn
    518                                                
    519                                                 $estDays = "Same Day Delivery";
    520                                                
    521                                                
    522                                                 if($rate->estimated_days == null){
    523                                                     $kwikamt = $rate->amount;
    524                                                 }else{
    525                                                     $estDays = $rate->estimated_days;
    526                                                     $kwikamt = $rate->amount;
    527                                                 }
    528                                                
    529                                                 $rateId = $rate->courier->id;
    530                                                
    531                                             }
    532                                            
    533                                         }else{//status does exist
    534                                             error_log("status does exist -".$rateServer->type);
    535                                            
    536                                         }
    537                                     }
    538                                    
    539                                    
    540                                    
    541                                 }else{
    542                                    
    543                                 }
    544                                
    545                                 $rate = array(
    546                                     'id' => "fedex_shipping",
    547                                     'label' => "Fedex - ".$estDays,
    548                                     'cost' => $kwikamt,
    549                                     'calc_tax' => 'per_item',
    550                                     'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
    551                                 );
    552                                
    553                                
    554                                 // Register the rate
    555                                 if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
    556                                     $this->add_rate($rate);
    557                                 }
    558                                
    559                             }
    560                         }
     417                        $kwikamt = $rate->amount;
     418                    }else{
     419                        $estDays = $rate->estimated_days;
     420                        $kwikamt = $rate->amount;
     421                    }
     422                   
     423                    $rateId = $rate->courier->id;
     424                   
     425                }
     426               
     427               
     428                $rate = array(
     429                    'id' => "gig_shipping",
     430                    'label' => "GIG - ".$estDays,
     431                    'cost' => $kwikamt,
     432                    'calc_tax' => 'per_item',
     433                    'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
     434                );
     435               
     436               
     437                // Register the rate
     438                if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
     439                    $this->add_rate($rate);
     440                }
     441               
     442            }
     443        }
     444       
     445       
     446        class WC_ShiipMethod_FEDEX extends WC_Shipping_Method {
     447            /**
     448            * Constructor for your shipping class
     449            *
     450            * @access public
     451            * @return void
     452            */
     453            public function __construct() {
     454                $this->id = 'fedex_shipping';
     455                $this->init();
     456            }
     457           
     458            /**
     459            * Init your settings
     460            *
     461            * @access public
     462            * @return void
     463            */
     464            public function init() {
     465            }
     466            /**
     467            * calculate_shipping function.
     468            *
     469            * @access public
     470            * @param mixed $package
     471            * @return void
     472            */
     473            public function calculate_shipping($package = array()) {
     474               
     475                $rates = getRates("fedex",$package);
     476               
     477                $parse =  json_decode($rates);
     478               
     479                $kwikamt = "0";
     480                $estDays = "Same Day Delivery";
     481               
     482                $rateId = "";
     483                $redisKey = "";
     484               
     485                if($parse->data->rates == null){
     486                    return ;
     487                }
     488               
     489                $redisKey = $parse->data->redis_key;
     490               
     491               
     492                $rate = $parse->data->rates;
     493               
     494                if($rate->currency == "NGN"){//only show ngn
     495                   
     496                    $estDays = "Same Day Delivery";
     497                   
     498                   
     499                    if($rate->estimated_days == null){
     500                        $kwikamt = $rate->amount;
     501                    }else{
     502                        $estDays = $rate->estimated_days;
     503                        $kwikamt = $rate->amount;
     504                    }
     505                   
     506                    $rateId = $rate->courier->id;
     507                   
     508                }
     509               
     510               
     511                $rate = array(
     512                    'id' => "fedex_shipping",
     513                    'label' => "Fedex - ".$estDays,
     514                    'cost' => $kwikamt,
     515                    'calc_tax' => 'per_item',
     516                    'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
     517                );
     518               
     519               
     520                // Register the rate
     521                if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
     522                    $this->add_rate($rate);
     523                }
     524               
     525            }
     526        }
     527       
     528       
     529        class WC_ShiipMethod_SHIPPO extends WC_Shipping_Method {
     530            /**
     531            * Constructor for your shipping class
     532            *
     533            * @access public
     534            * @return void
     535            */
     536            public function __construct() {
     537                $this->id = 'shippo_shipping';
     538                $this->init();
     539            }
     540           
     541            /**
     542            * Init your settings
     543            *
     544            * @access public
     545            * @return void
     546            */
     547            public function init() {
     548            }
     549            /**
     550            * calculate_shipping function.
     551            *
     552            * @access public
     553            * @param mixed $package
     554            * @return void
     555            */
     556            public function calculate_shipping($package = array()) {
     557               
     558                $rate = array(
     559                    'id' => "shippo_shipping",
     560                    'label' => "SHIPPO",
     561                    'cost' => '122.99',
     562                    'calc_tax' => 'per_item'
     563                );
     564               
     565               
     566                // Register the rate
     567                $this->add_rate($rate);
     568            }
     569        }
     570       
     571       
     572        class WC_ShiipMethod_DHL extends WC_Shipping_Method {
     573            /**
     574            * Constructor for your shipping class
     575            *
     576            * @access public
     577            * @return void
     578            */
     579            public function __construct() {
     580                $this->id = 'dhl_shipping';
     581                $this->init();
     582            }
     583           
     584            /**
     585            * Init your settings
     586            *
     587            * @access public
     588            * @return void
     589            */
     590            public function init() {
     591            }
     592            /**
     593            * calculate_shipping function.
     594            *
     595            * @access public
     596            * @param mixed $package
     597            * @return void
     598            */
     599            public function calculate_shipping($package = array()) {
     600               
     601               
     602                $rates = getRates("dhl",$package);
     603               
     604                $parse =  json_decode($rates);
     605               
     606                $kwikamt = "0";
     607                $estDays = "Same Day Delivery";
     608               
     609                $redisKey = "";
     610                $rateId = "";
     611               
     612               
     613                if($parse->data->rates == null){
     614                    return ;
     615                }
     616               
     617                $redisKey = $parse->data->redis_key;
     618               
     619               
     620                $rate = $parse->data->rates;
     621               
     622                if($rate->currency == "NGN"){//only show ngn
     623                   
     624                    $estDays = "Same Day Delivery";
     625                   
     626                   
     627                    if($rate->estimated_days == null){
    561628                       
    562                        
    563                         class WC_ShiipMethod_SHIPPO extends WC_Shipping_Method {
    564                             /**
    565                             * Constructor for your shipping class
    566                             *
    567                             * @access public
    568                             * @return void
    569                             */
    570                             public function __construct() {
    571                                 $this->id = 'shippo_shipping';
    572                                 $this->init();
    573                             }
    574                            
    575                             /**
    576                             * Init your settings
    577                             *
    578                             * @access public
    579                             * @return void
    580                             */
    581                             public function init() {
    582                             }
    583                             /**
    584                             * calculate_shipping function.
    585                             *
    586                             * @access public
    587                             * @param mixed $package
    588                             * @return void
    589                             */
    590                             public function calculate_shipping($package = array()) {
    591                                
    592                                 $rate = array(
    593                                     'id' => "shippo_shipping",
    594                                     'label' => "SHIPPO",
    595                                     'cost' => '122.99',
    596                                     'calc_tax' => 'per_item'
    597                                 );
    598                                
    599                                
    600                                 // Register the rate
    601                                 $this->add_rate($rate);
    602                             }
    603                         }
    604                        
    605                        
    606                         class WC_ShiipMethod_DHL extends WC_Shipping_Method {
    607                             /**
    608                             * Constructor for your shipping class
    609                             *
    610                             * @access public
    611                             * @return void
    612                             */
    613                             public function __construct() {
    614                                 $this->id = 'dhl_shipping';
    615                                 $this->init();
    616                             }
    617                            
    618                             /**
    619                             * Init your settings
    620                             *
    621                             * @access public
    622                             * @return void
    623                             */
    624                             public function init() {
    625                             }
    626                             /**
    627                             * calculate_shipping function.
    628                             *
    629                             * @access public
    630                             * @param mixed $package
    631                             * @return void
    632                             */
    633                             public function calculate_shipping($package = array()) {
    634                                
    635                                
    636                                 $rates = getRates("dhl",$package);
    637                                
    638                                 $parse =  json_decode($rates);
    639                                
    640                                 $kwikamt = "0";
    641                                 $estDays = "Same Day Delivery";
    642                                
    643                                 $redisKey = "";
    644                                 $rateId = "";
    645                                
    646                                
    647                                 if(strcasecmp($parse->message, "OK") == 0 && $parse->status == true ){
    648                                    
    649                                     $count = 1;
    650                                    
    651                                     //check number of companies providing rates
    652                                     $rateSize = sizeof($parse->data->rates);
    653                                    
    654                                     $redisKey = $parse->data->redis_key;
    655                                    
    656                                    
    657                                     foreach ($parse->data->rates as $rateServer) {
    658                                         if(!isset($rateServer->status)){//if status does not exist then we have data to show
    659                                            
    660                                             $rate = $rateServer;
    661                                            
    662                                             if($rate->currency == "NGN"){//only show ngn
    663                                                
    664                                                 $estDays = "Same Day Delivery";
    665                                                
    666                                                
    667                                                 if($rate->estimated_days == null){
    668                                                
    669                                                     $kwikamt = $rate->amount;
    670                                                 }else{
    671                                                     $estDays = $rate->estimated_days;
    672                                                     $kwikamt = $rate->amount;
    673                                                 }
    674                                                
    675                                                 $rateId = $rate->courier->id;
    676                                                
    677                                             }
    678                                            
    679                                         }else{//status does exist
    680                                             error_log("status does exist -".$rateServer->type);
    681                                            
    682                                         }
    683                                     }
    684                                    
    685                                    
    686                                    
    687                                 }else{
    688                                    
    689                                 }
    690                                
    691                                
    692                                 $rate = array(
    693                                     'id' => "dhl_shipping",
    694                                     'label' => "DHL - ".$estDays,
    695                                     'cost' => $kwikamt,
    696                                     'calc_tax' => 'per_item',
    697                                     'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
    698                                 );
    699                                
    700                                
    701                                 // Register the rate
    702                                 if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
    703                                     $this->add_rate($rate);
    704                                 }
    705                             }
    706                         }
    707                        
    708                        
    709                        
    710                         class WC_ShiipMethod_GOKADA extends WC_Shipping_Method {
    711                             /**
    712                             * Constructor for your shipping class
    713                             *
    714                             * @access public
    715                             * @return void
    716                             */
    717                             public function __construct() {
    718                                 $this->id = 'gokada_shipping';
    719                                 $this->init();
    720                             }
    721                            
    722                             /**
    723                             * Init your settings
    724                             *
    725                             * @access public
    726                             * @return void
    727                             */
    728                             public function init() {
    729                             }
    730                             /**
    731                             * calculate_shipping function.
    732                             *
    733                             * @access public
    734                             * @param mixed $package
    735                             * @return void
    736                             */
    737                             public function calculate_shipping($package = array()) {
    738                                
    739                                
    740                                 $rates = getRates("gokada",$package);
    741                                
    742                                 $parse =  json_decode($rates);
    743                                
    744                                 $kwikamt = "0";
    745                                 $estDays = "Same Day Delivery";
    746                                
    747                                 $redisKey = "";
    748                                 $rateId = "";
    749                                
    750                                
    751                                
    752                                 if(strcasecmp($parse->message, "OK") == 0 && $parse->status == true ){
    753                                    
    754                                     $count = 1;
    755                                    
    756                                     //check number of companies providing rates
    757                                     $rateSize = sizeof($parse->data->rates);
    758                                    
    759                                    
    760                                     $redisKey = $parse->data->gokada_key;
    761                                    
    762                                     foreach ($parse->data->rates as $rateServer) {
    763                                         if(!isset($rateServer->status)){//if status does not exist then we have data to show
    764                                            
    765                                             $rate = $rateServer;
    766                                            
    767                                             if($rate->currency == "NGN"){//only show ngn
    768                                                
    769                                                 $estDays = "Same Day Delivery";
    770                                                
    771                                                
    772                                                 if($rate->estimated_days == null){
    773                                                     $kwikamt = $rate->amount;
    774                                                 }else{
    775                                                     $estDays = $rate->estimated_days;
    776                                                     $kwikamt = $rate->amount;
    777                                                 }
    778                                                
    779                                                 $rateId = $rate->courier->id;
    780                                                
    781                                             }
    782                                            
    783                                            
    784                                            
    785                                            
    786                                            
    787                                            
    788                                         }else{//status does exist
    789                                             error_log("status does exist -".$rateServer->type);
    790                                            
    791                                         }
    792                                     }
    793                                    
    794                                    
    795                                    
    796                                 }else{
    797                                    
    798                                 }
    799                                
    800                                 $rate = array(
    801                                     'id' => "gokada_shipping",
    802                                     'label' => "Gokada - " .$estDays,
    803                                     'cost' => $kwikamt,
    804                                     'calc_tax' => 'per_item',
    805                                     'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
    806                                 );
    807                                
    808                                
    809                                 // Register the rate
    810                                 if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
    811                                     $this->add_rate($rate);
    812                                 }
    813                             }
    814                         }
    815                        
    816                         // }
     629                        $kwikamt = $rate->amount;
     630                    }else{
     631                        $estDays = $rate->estimated_days;
     632                        $kwikamt = $rate->amount;
    817633                    }
    818634                   
    819                     add_action( 'woocommerce_shipping_init', 'your_shipping_method_init' );
    820                     function shiip_shipping_methods( $methods ) {
    821                        
    822                         if(get_option('woocommerce_currency') == "NGN"){
    823                             //only work if the platform is using naira
    824                             //for now this plugin is for only nigerian vendors
    825                            
    826                             $methods['shiip'] = 'WC_ShiipMethod';
    827                             $methods['shiipDHL'] = 'WC_ShiipMethod_DHL';
    828                             $methods['shiipFEDEX'] = 'WC_ShiipMethod_FEDEX';
    829                             //  remove gokada for now $methods['shiipGOKADA'] = 'WC_ShiipMethod_GOKADA';
    830                    
    831                            
    832                         }else{
    833                            
    834                         }
    835                        
    836                        
    837                        
    838                         return $methods;
     635                    $rateId = $rate->courier->id;
     636                   
     637                }
     638               
     639               
     640               
     641                $rate = array(
     642                    'id' => "dhl_shipping",
     643                    'label' => "DHL - ".$estDays,
     644                    'cost' => $kwikamt,
     645                    'calc_tax' => 'per_item',
     646                    'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
     647                );
     648               
     649               
     650                // Register the rate
     651                if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
     652                    $this->add_rate($rate);
     653                }
     654            }
     655        }
     656       
     657       
     658       
     659        class WC_ShiipMethod_GOKADA extends WC_Shipping_Method {
     660            /**
     661            * Constructor for your shipping class
     662            *
     663            * @access public
     664            * @return void
     665            */
     666            public function __construct() {
     667                $this->id = 'gokada_shipping';
     668                $this->init();
     669            }
     670           
     671            /**
     672            * Init your settings
     673            *
     674            * @access public
     675            * @return void
     676            */
     677            public function init() {
     678            }
     679            /**
     680            * calculate_shipping function.
     681            *
     682            * @access public
     683            * @param mixed $package
     684            * @return void
     685            */
     686            public function calculate_shipping($package = array()) {
     687               
     688               
     689                $rates = getRates("gokada",$package);
     690               
     691                $parse =  json_decode($rates);
     692               
     693                $kwikamt = "0";
     694                $estDays = "Same Day Delivery";
     695               
     696                $redisKey = "";
     697                $rateId = "";
     698               
     699               
     700               
     701                if($parse->data->rates == null){
     702                    return ;
     703                }
     704               
     705                $redisKey = $parse->data->gokada_key;
     706               
     707               
     708                $rate = $parse->data->rates;
     709               
     710                if($rate->currency == "NGN"){//only show ngn
     711                   
     712                    $estDays = "Same Day Delivery";
     713                   
     714                   
     715                    if($rate->estimated_days == null){
     716                        $kwikamt = $rate->amount;
     717                    }else{
     718                        $estDays = $rate->estimated_days;
     719                        $kwikamt = $rate->amount;
    839720                    }
    840721                   
    841                     add_filter( 'woocommerce_shipping_methods', 'shiip_shipping_methods' );
    842                    
    843                    
    844                 }
    845                
    846                 /**
    847                 * The core plugin class that is used to define internationalization,
    848                 * admin-specific hooks, and public-facing site hooks.
    849                 */
    850                
    851                 /**
    852                 * Begins execution of the plugin.
    853                 *
    854                 * Since everything within the plugin is registered via hooks,
    855                 * then kicking off the plugin from this point in the file does
    856                 * not affect the page life cycle.
    857                 *
    858                 * @since    1.0.0
    859                 */
    860                
    861                    
     722                    $rateId = $rate->courier->id;
     723                   
     724                }
     725               
     726               
     727               
     728               
     729                $rate = array(
     730                    'id' => "gokada_shipping",
     731                    'label' => "Gokada - " .$estDays,
     732                    'cost' => $kwikamt,
     733                    'calc_tax' => 'per_item',
     734                    'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
     735                );
     736               
     737               
     738                // Register the rate
     739                if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
     740                    $this->add_rate($rate);
     741                }
     742            }
     743        }
     744       
     745       
     746       
     747        class WC_ShiipMethod_KONGAVAN extends WC_Shipping_Method {
     748            /**
     749            * Constructor for your shipping class
     750            *
     751            * @access public
     752            * @return void
     753            */
     754            public function __construct() {
     755                $this->id = 'KXPRESS_VAN';
     756                $this->init();
     757            }
     758           
     759            /**
     760            * Init your settings
     761            *
     762            * @access public
     763            * @return void
     764            */
     765            public function init() {
     766            }
     767            /**
     768            * calculate_shipping function.
     769            *
     770            * @access public
     771            * @param mixed $package
     772            * @return void
     773            */
     774            public function calculate_shipping($package = array()) {
     775               
     776               
     777                $rates = getRates("kongavan",$package);
     778               
     779                $parse =  json_decode($rates);
     780               
     781                $kwikamt = "0";
     782                $estDays = "Same Day Delivery";
     783               
     784                $redisKey = "";
     785                $rateId = "";
     786               
     787               
     788               
     789                if($parse->data->rates == null){
     790                    return ;
     791                }
     792               
     793                $redisKey = $parse->data->redis_key;
     794               
     795               
     796                $rate = $parse->data->rates;
     797               
     798                if($rate->currency == "NGN"){//only show ngn
     799                   
     800                    $estDays = "Same Day Delivery";
     801                   
     802                   
     803                    if($rate->estimated_days == null){
     804                        $kwikamt = $rate->amount;
     805                    }else{
     806                        $estDays = $rate->estimated_days;
     807                        $kwikamt = $rate->amount;
     808                    }
     809                   
     810                    $rateId = $rate->courier->id;
     811                   
     812                }
     813               
     814               
     815                $rate = array(
     816                    'id' => "KXPRESS_VAN",
     817                    'label' => "KXPRESS VAN - " .$estDays,
     818                    'cost' => $kwikamt,
     819                    'calc_tax' => 'per_item',
     820                    'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
     821                );
     822               
     823               
     824                // Register the rate
     825                if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
     826                    $this->add_rate($rate);
     827                }
     828            }
     829        }
     830       
     831       
     832       
     833        class WC_ShiipMethod_KONGABIKE extends WC_Shipping_Method {
     834            /**
     835            * Constructor for your shipping class
     836            *
     837            * @access public
     838            * @return void
     839            */
     840            public function __construct() {
     841                $this->id = 'KXPRESS_BIKE';
     842                $this->init();
     843            }
     844           
     845            /**
     846            * Init your settings
     847            *
     848            * @access public
     849            * @return void
     850            */
     851            public function init() {
     852            }
     853            /**
     854            * calculate_shipping function.
     855            *
     856            * @access public
     857            * @param mixed $package
     858            * @return void
     859            */
     860            public function calculate_shipping($package = array()) {
     861               
     862               
     863                $rates = getRates("kongabike",$package);
     864               
     865                $parse =  json_decode($rates);
     866               
     867                $kwikamt = "0";
     868                $estDays = "Same Day Delivery";
     869               
     870                $redisKey = "";
     871                $rateId = "";
     872               
     873               
     874               
     875                if($parse->data->rates == null){
     876                    return ;
     877                }
     878               
     879                $redisKey = $parse->data->redis_key;
     880               
     881               
     882                $rate = $parse->data->rates;
     883               
     884                if($rate->currency == "NGN"){//only show ngn
     885                   
     886                    $estDays = "Same Day Delivery";
     887                   
     888                   
     889                    if($rate->estimated_days == null){
     890                        $kwikamt = $rate->amount;
     891                    }else{
     892                        $estDays = $rate->estimated_days;
     893                        $kwikamt = $rate->amount;
     894                    }
     895                   
     896                    $rateId = $rate->courier->id;
     897                   
     898                }
     899               
     900               
     901                $rate = array(
     902                    'id' => "KXPRESS_BIKE",
     903                    'label' => "KXPRESS BIKE - " .$estDays,
     904                    'cost' => $kwikamt,
     905                    'calc_tax' => 'per_item',
     906                    'meta_data' => array("rateId" => $rateId,"redisKey" => $redisKey)
     907                );
     908               
     909               
     910                // Register the rate
     911                if(isset($kwikamt) && $kwikamt != NULL && $kwikamt > 0){
     912                    $this->add_rate($rate);
     913                }
     914            }
     915        }
     916       
     917    }
     918   
     919    add_action( 'woocommerce_shipping_init', 'your_shipping_method_init' );
     920    function shiip_shipping_methods( $methods ) {
     921       
     922        if(get_option('woocommerce_currency') == "NGN"){
     923            //only work if the platform is using naira
     924            //for now this plugin is for only nigerian vendors
     925           
     926            $methods['shiip'] = 'WC_ShiipMethod';
     927            $methods['shiipDHL'] = 'WC_ShiipMethod_DHL';
     928            $methods['shiipFEDEX'] = 'WC_ShiipMethod_FEDEX';
     929            // $methods['shiipGIG'] = 'WC_ShiipMethod_GIG';
     930            $methods['shiipKXPRESSBIKE'] = 'WC_ShiipMethod_KONGABIKE';
     931            $methods['shiipKXPRESSVAN'] = 'WC_ShiipMethod_KONGAVAN';
     932            //  remove gokada for now $methods['shiipGOKADA'] = 'WC_ShiipMethod_GOKADA';
     933           
     934           
     935        }else{
     936           
     937        }
     938       
     939       
     940       
     941        return $methods;
     942    }
     943   
     944    add_filter( 'woocommerce_shipping_methods', 'shiip_shipping_methods' );
     945   
     946   
     947}
     948
     949/**
     950* The core plugin class that is used to define internationalization,
     951* admin-specific hooks, and public-facing site hooks.
     952*/
     953
     954/**
     955* Begins execution of the plugin.
     956*
     957* Since everything within the plugin is registered via hooks,
     958* then kicking off the plugin from this point in the file does
     959* not affect the page life cycle.
     960*
     961* @since    1.0.0
     962*/
     963
Note: See TracChangeset for help on using the changeset viewer.