Changeset 2341519
- Timestamp:
- 07/16/2020 11:44:41 AM (6 years ago)
- Location:
- sendbox-shipping/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (2 diffs)
-
admin/class-wooss-admin.php (modified) (11 diffs)
-
includes/assets/js/script.js (modified) (10 diffs)
-
includes/class-wooss-sendbox-shipping-api.php (modified) (4 diffs)
-
includes/class-wooss-shipping-method.php (modified) (15 diffs)
-
wooss.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sendbox-shipping/trunk/README.txt
r2335894 r2341519 59 59 60 60 61 <h3>How do i get my API Key </h3> 62 <p> To get your key, you should go to <a href = "https://sendbox.co/">sendbox</a>, create an account, navigate to 63 settings on you sendbox dashboard, scroll and find your API Key.</p> 61 <h3>How do i get my access tpken?</h3> 62 <p> To get your access token, you should go to <a href = "https://developers.sendbox.co/">sendbox</a>, create an account.</p> 63 <br/> 64 <p>Proceed to create a new app, enter app name can be your site name, description, and your site url to serve as app url. </p> 65 <p>Your access token and other important keys are generated for you. </p> 66 64 67 65 68 <h3>How do i use the API Key? </h3> … … 112 115 <p>fixed some bugs with the api</p> 113 116 117 <b>3.2.1</b> 118 <p>Updated sendbox access token for user authentication</p> 119 114 120 115 121 -
sendbox-shipping/trunk/admin/class-wooss-admin.php
r2339399 r2341519 189 189 break; 190 190 } 191 } 191 } 192 192 193 193 if(empty($destination_state)){ … … 236 236 237 237 $api_call = new Wooss_Sendbox_Shipping_API(); 238 $auth_header = get_option('wooss_basic_auth'); 238 //$auth_header = get_option('wooss_basic_auth'); 239 $auth_header = $api_call->checkAuth(); 239 240 $args = array( 240 241 'headers' => array( … … 243 244 ), 244 245 ); 245 $profile_api_url = 'https:// api.sendbox.ng/v1/merchant/profile';246 $profile_api_url = 'https://live.sendbox.co/oauth/profile'; 246 247 $profile_data_response_code = $api_call->get_api_response_code($profile_api_url, $args, 'GET'); 247 248 $profile_data_response_body = $api_call->get_api_response_body($profile_api_url, $args, 'GET'); … … 299 300 ?> 300 301 301 <div style="display:none;"id="wooss_shipments_data">302 <div id="wooss_shipments_data"> 302 303 303 304 <span style="display:none;"><strong><?php esc_html_e('Origin Details : ', 'wooss'); ?></strong> … … 334 335 <br /> 335 336 <br /> 336 <span ><strong><?php esc_html_e('Destination Details : ', 'wooss'); ?></strong>337 <span style="display:none;"><strong><?php esc_html_e('Destination Details : ', 'wooss'); ?></strong> 337 338 <i>This represents your customer details</i> 338 339 <br /> … … 409 410 410 411 ); 412 //print_r($delivery_args); 411 413 412 414 … … 420 422 $quote_api_url = $api_call->get_sendbox_api_url('delivery_quote'); 421 423 $quote_body = $api_call->get_api_response_body($quote_api_url, $delivery_args, 'POST'); 422 //print_r($delivery_args);424 // var_dump($quote_body); 423 425 424 426 $quotes_rates = $quote_body->rates; … … 633 635 } 634 636 637 638 635 639 $courier_selected = sanitize_text_field($data['wooss_selected_courier']); 636 640 … … 688 692 689 693 $api_call = new Wooss_Sendbox_Shipping_API(); 690 $auth_header = get_option('wooss_basic_auth'); 694 //$auth_header = get_option('wooss_basic_auth'); 695 $auth_header = $api_call->checkAuth(); 691 696 692 697 $payload_data_json = wp_json_encode($payload_data); … … 699 704 'body' => $payload_data_json, 700 705 ); 701 706 //var_dump($shipments_args); 702 707 703 708 $shipments_url = $api_call->get_sendbox_api_url('shipments'); … … 706 711 $shipments_details = $api_call->get_api_response_body($shipments_url, $shipments_args, 'POST'); 707 712 708 713 //var_dump($shipments_details); 709 714 if (isset($shipments_details)) { 710 715 -
sendbox-shipping/trunk/includes/assets/js/script.js
r2335894 r2341519 1 (function ($) {1 (function ($) { 2 2 "use strict"; 3 3 … … 29 29 * practising this, we should strive to set a better example in our own work. 30 30 */ 31 $(document).ready(function () {31 $(document).ready(function () { 32 32 /** 33 33 * Check if we are specially on the sendbox shipping method settings page. … … 39 39 ) { 40 40 //by The Blacker 41 $(document).on('click dbclick','#woocommerce_wooss_enabled',function(e){ 42 $('div.wooss-shipping-settings').hide(); 43 if ($(this).prop('checked')){ 44 $('div.wooss-shipping-settings').show(); 41 $(document).on("click dbclick", "#woocommerce_wooss_enabled", function ( 42 e 43 ) { 44 $("div.wooss-shipping-settings").hide(); 45 if ($(this).prop("checked")) { 46 $("div.wooss-shipping-settings").show(); 45 47 } 46 }); 47 48 49 48 }); 50 49 51 50 var wc_button_save = $("button.button-primary.woocommerce-save-button"); 52 51 wc_button_save.show(); 53 var wooss_basic_auth; 52 //var wooss_basic_auth; 53 var sendbox_auth_token; 54 var sendbox_refresh_token; 55 var sendbox_app_id; 56 var sendbox_client_secret; 54 57 var wooss_connect_btn = $("button.wooss-connect-sendbox"); 55 58 var wooss_errors_message_span = $("span.wooss_errors_pages"); … … 59 62 */ 60 63 61 wooss_connect_btn.on("click", function (e) {64 wooss_connect_btn.on("click", function (e) { 62 65 e.preventDefault(); 63 wooss_basic_auth = $("input[name='wooss_basic_auth'").val(); 64 function reloadPage() { 66 //wooss_basic_auth = $("input[name='wooss_basic_auth'").val(); 67 sendbox_auth_token = $("input[name='sendbox_auth_token']").val(); 68 sendbox_refresh_token = $("input[name='sendbox_refresh_token']").val(); 69 sendbox_app_id = $("input[name='sendbox_app_id']").val(); 70 sendbox_client_secret = $("input[name='sendbox_client_secret']").val(); 71 72 function reloadPage() { 65 73 window.location.reload(); 66 }74 } 67 75 wooss_loader.show(); 68 76 var data = { 69 wooss_basic_auth: wooss_basic_auth 77 //wooss_basic_auth: wooss_basic_auth 78 sendbox_auth_token: sendbox_auth_token, 79 sendbox_refresh_token: sendbox_refresh_token, 80 sendbox_app_id: sendbox_app_id, 81 sendbox_client_secret: sendbox_client_secret, 70 82 }; 71 83 $.post( … … 74 86 action: "connect_to_sendbox", 75 87 data: data, 76 security: wooss_ajax_object.wooss_ajax_security 88 security: wooss_ajax_object.wooss_ajax_security, 77 89 }, 78 function (response) {90 function (response) { 79 91 wooss_loader.hide(); 80 92 if (1 == response) { 81 93 $( 82 '<div id="message" class="updated inline"><p><strong>Your API keyis valid, this page will be refreshed in 10s.</strong></p></div>'94 '<div id="message" class="updated inline"><p><strong>Your access token is valid, this page will be refreshed in 10s.</strong></p></div>' 83 95 ).insertAfter("br.clear"); 84 96 setTimeout(reloadPage, 10000); … … 86 98 wooss_errors_message_span 87 99 .append( 88 "Invalid API key login to sendbox and get the correct key"100 "Invalid access and refresh token login to sendbox and get the correct tokens" 89 101 ) 90 102 .show(); … … 99 111 */ 100 112 var wooss_button_save = $("button.button-primary.wooss_save_button"); 101 wooss_button_save.on("submit click", function (e) {113 wooss_button_save.on("submit click", function (e) { 102 114 e.preventDefault(); 103 115 var wooss_state_name = $("select.wooss_state_dropdown").val(); … … 107 119 var wooss_pickup_type = $("select.wooss_pickup_type").val(); 108 120 var wooss_rates_type = $("select.wooss_rates_type").val(); 109 wooss_basic_auth = $("input[name='wooss_basic_auth'").val(); 121 //wooss_basic_auth = $("input[name='wooss_basic_auth']").val(); 122 sendbox_auth_token = $("input[name='sendbox_auth_token']").val(); 123 sendbox_refresh_token = $("input[name='sendbox_refresh_token']").val(); 124 sendbox_app_id = $("input[name='sendbox_app_id']").val(); 125 sendbox_client_secret = $("input[name='sendbox_client_secret']").val(); 110 126 var wooss_enabled = $('input[name="woocommerce_wooss_enabled"]').val(); 111 127 var wooss_extra_fees = $("input#wooss_extra_fees").val(); … … 116 132 wooss_city: wooss_city, 117 133 wooss_street: wooss_street, 118 wooss_basic_auth: wooss_basic_auth, 134 //wooss_basic_auth: wooss_basic_auth, 135 sendbox_auth_token: sendbox_auth_token, 136 sendbox_refresh_token: sendbox_refresh_token, 137 sendbox_app_id: sendbox_app_id, 138 sendbox_client_secret: sendbox_client_secret, 119 139 wooss_enabled: wooss_enabled, 120 140 wooss_pickup_type: wooss_pickup_type, 121 141 wooss_rates_type: wooss_rates_type, 122 wooss_extra_fees: wooss_extra_fees 142 wooss_extra_fees: wooss_extra_fees, 123 143 }; 124 144 … … 128 148 action: "save_fields_by_ajax", 129 149 data: data, 130 security: wooss_ajax_object.wooss_ajax_security 150 security: wooss_ajax_object.wooss_ajax_security, 131 151 }, 132 function (response) {152 function (response) { 133 153 if (1 == response) { 134 154 $( -
sendbox-shipping/trunk/includes/class-wooss-sendbox-shipping-api.php
r2226186 r2341519 71 71 { 72 72 if ('delivery_quote' == $url_type) { 73 $url = 'https:// api.sendbox.ng/v1/merchant/shipments/delivery_quote';73 $url = 'https://live.sendbox.co/shipping/shipment_delivery_quote'; 74 74 } elseif ('countries' == $url_type) { 75 75 $url = 'https://api.sendbox.co/auth/countries?page_by={' . '"per_page"' . ':264}'; … … 77 77 $url = 'https://api.sendbox.co/auth/states'; 78 78 } elseif ('shipments' == $url_type) { 79 $url = 'https:// api.sendbox.ng/v1/merchant/shipments';79 $url = 'https://live.sendbox.co/shipping/shipments'; 80 80 } elseif ('item_type' == $url_type) { 81 81 $url = 'https://api.sendbox.ng/v1/item_types'; 82 82 } elseif ('profile' == $url_type) { 83 $url = 'https:// api.sendbox.ng/v1/merchant/profile';83 $url = 'https://live.sendbox.co/oauth/profile'; 84 84 } else { 85 85 $url = ''; … … 87 87 return $url; 88 88 } 89 90 91 /** 92 * 93 * This function checks sendbox oauth 94 */ 95 96 public function checkAuth(){ 97 98 $api_key = get_option('sendbox_auth_token'); 99 $profile_url = "https://live.sendbox.co/oauth/profile"; 100 101 $profile_res = wp_remote_get( $profile_url , 102 array( 'timeout' => 10, 103 'headers' => array( 'Content-Type' => 'application/json', 104 'Authorization'=> $api_key ) 105 )); 106 $profile_obj = json_decode($profile_res['body']); 107 108 if(isset($profile_obj->title)){ 109 110 //make a new request to oauth 111 $s_url = 'https://live.sendbox.co/oauth/access/access_token/refresh?'; 112 $app_id = get_option('sendbox_app_id'); 113 $client_secret = get_option('sendbox_client_secret'); 114 $url_oauth = $s_url.'app_id='.$app_id.'&client_secret='.$client_secret; 115 $refresh_token = get_option('sendbox_refresh_token'); 116 117 $oauth_res = wp_remote_get( $url_oauth, 118 array( 'timeout' => 10, 119 'headers' => array( 'Content-Type' => 'application/json', 120 'Refresh-Token'=> $refresh_token ) 121 )); 122 $oauth_obj = json_decode($oauth_res['body']); 123 if(isset($oauth_obj->access_token)){ 124 $new_auth = $oauth_obj->access_token; 125 update_option('sendbox_auth_token', $new_auth); 126 } 127 if(isset($oauth_obj->refresh_token)){ 128 $new_refresh = $oauth_obj->refresh_token; 129 update_option('sendbox_refresh_token', $new_refresh); 130 } 131 132 } 133 134 else{ 135 $api_key = get_option('sendbox_auth_token'); 136 } 137 138 return $api_key; 139 140 141 } 142 89 143 90 144 … … 98 152 $state = array('Abia', 'Adamawa', 'Akwa Ibom', 'Anambra', 'Bauchi', 'Benue', 'Borno', 'Bayelsa', 'Cross River', 'Delta', 'Ebonyi ', 'Edo', 'Ekiti', 'Enugu ', 'Federal Capital Territory', 'Gombe ', 'Jigawa ', ' Imo ', ' Kaduna', 'Kebbi ', 'Kano', ' Kogi', ' Lagos', 'Katsina', 'Kwara', 'Nasarawa', 'Niger ', 'Ogun', 'Ondo ', 'Rivers', 'Oyo', 'Osun', 'Sokoto', 'Plateau', 'Taraba', 'Yobe', 'Zamfara'); 99 153 return $state; 100 } 101 } 154 } 155 156 157 } 158 159 -
sendbox-shipping/trunk/includes/class-wooss-shipping-method.php
r2335894 r2341519 115 115 } 116 116 117 $auth_header = get_option('wooss_basic_auth'); 117 //$auth_header = get_option('wooss_basic_auth'); 118 $auth_header = $api_call->checkAuth(); 118 119 119 120 if (!$auth_header){ … … 176 177 177 178 if (empty($destination_state)) { 178 $destination_state = $package['destination']['state']; 179 //$destination_state = $package['destination']['state']; 180 $destination_state = "London"; 179 181 } 180 182 if (empty($destination_city)) { … … 214 216 $delivery_quotes_details = wooss_calculate_shipping($api_call,$payload_array_data,$auth_header); 215 217 216 218 //var_dump($delivery_quotes_details); 219 //die(); 217 220 $wooss_rates_type = get_option('wooss_rates_type'); 218 221 if ("maximum" == $wooss_rates_type && isset($delivery_quotes_details->max_quoted_fee) ) { … … 225 228 226 229 227 $destination_country = "United States of America";230 /* $destination_country = "United States of America"; 228 231 $destination_state = "Washington"; 229 232 $destination_city = "New York"; 230 $destination_postcode = "10001"; 233 $destination_postcode = "10001"; */ 231 234 $payload_array_data['destination_country'] = $destination_country; 232 235 $payload_array_data['destination_state'] = $destination_state; … … 287 290 if (isset($_GET['tab']) && $_GET['tab'] == 'shipping' && isset($_GET['section']) && $_GET['section'] == 'wooss' && $shipping_methods_enabled == 'yes') { 288 291 $api_call = new Wooss_Sendbox_Shipping_API(); 289 $auth_header = esc_attr(get_option('wooss_basic_auth')); 292 //$auth_header = esc_attr(get_option('wooss_basic_auth')); 293 $auth_header = esc_attr(get_option('sendbox_auth_token')); 290 294 $args = array( 291 295 'headers' => array( … … 294 298 ), 295 299 ); 296 $profile_api_url = 'https:// api.sendbox.ng/v1/merchant/profile';300 $profile_api_url = 'https://live.sendbox.co/oauth/profile'; 297 301 $profile_data_response_code = $api_call->get_api_response_code($profile_api_url, $args, 'GET'); 298 302 $profile_data_response_body = $api_call->get_api_response_body($profile_api_url, $args, 'GET'); … … 326 330 $wooss_country = 'Nigeria'; 327 331 } 328 $wooss_connection_status = get_option('wooss_basic_auth'); 332 //$wooss_connection_status = get_option('wooss_basic_auth'); 333 $wooss_connection_status = get_option('sendbox_auth_token'); 329 334 $custom_styles = ''; 330 335 if (null != $wooss_connection_status) { … … 366 371 367 372 <div class="wooss-shipping-settings" > 368 369 <strong><label for="wooss_basic_auth"><?php esc_attr_e('API KEY :', 'wooss'); ?> </label><input type="text" class="wooss-text" placeholder="Basic X0000X0000000000AH" name="wooss_basic_auth" value="<?php esc_attr_e($wooss_basic_auth, 'wooss'); ?>"></strong> <br /> 370 <button type="submit" class="button-primary wooss-connect-sendbox wooss_fields" style="<?php esc_attr_e($custom_styles); ?>"><?php esc_attr_e('Connect to Sendbox', 'wooss'); ?></button><br /> 371 373 <!--Make changes and start using the new oauth---> 374 375 <!-- <strong><label for="wooss_basic_auth"><?php //esc_attr_e('API KEY :', 'wooss'); ?> </label><input type="text" class="wooss-text" placeholder="Basic X0000X0000000000AH" name="wooss_basic_auth" value="<?php //esc_attr_e($wooss_basic_auth, 'wooss'); ?>"></strong> <br /> --> 376 <div style="<?php esc_attr_e($custom_styles); ?>"> 377 <strong><label for="sendbox_auth_token"><?php esc_attr_e('Access Token :', 'wooss'); ?> </label><input type="text" class="wooss-text" placeholder="Enter Your Access Token" name="sendbox_auth_token" value="<?php esc_attr_e($sendbox_auth_token, 'wooss'); ?>"></strong> <br /> 378 <strong><label for="sendbox_refresh_token"><?php esc_attr_e('Refresh Token :', 'wooss'); ?> </label><input type="text" class="wooss-text" placeholder="Enter Your Refresh Token" name="sendbox_auth_token" value="<?php esc_attr_e($sendbox_refresh_token, 'wooss'); ?>"></strong> <br /> 379 <strong><label for="sendbox_app_id"><?php esc_attr_e('App ID :', 'wooss'); ?> </label><input type="text" class="wooss-text" placeholder="Enter Your App ID" name="sendbox_app_id" value="<?php esc_attr_e($sendbox_app_id, 'wooss'); ?>"></strong> <br /> 380 <strong><label for="sendbox_client_secret"><?php esc_attr_e('Client Secret :', 'wooss'); ?> </label><input type="text" class="wooss-text" placeholder="Enter Your Client Secret" name="sendbox_app_id" value="<?php esc_attr_e($sendbox_client_secret, 'wooss'); ?>"></strong> <br /> 381 <button type="submit" class="button-primary wooss-connect-sendbox wooss_fields"><?php esc_attr_e('Connect to Sendbox', 'wooss'); ?></button><br /> 382 383 </div> 372 384 <div class="wooss_necessary_fields" style="<?php $display_fields = 'display : none'; if ($wooss_display_fields) {$display_fields = 'display : inline'; echo $display_fields;} else { echo $display_fields; }?>"> 373 385 <table style="width:100%"> … … 511 523 if (isset($_POST['data'])) { 512 524 $data = wp_unslash($_POST['data']); 513 $wooss_basic_auth = $data['wooss_basic_auth']; 525 //$wooss_basic_auth = $data['wooss_basic_auth']; 526 $sendbox_auth_token = $data['sendbox_auth_token']; 527 $sendbox_refresh_token = $data['sendbox_refresh_token']; 528 $sendbox_client_secret = $data['sendbox_client_secret']; 529 $sendbox_app_id = $data['sendbox_app_id']; 530 514 531 $api_call = new Wooss_Sendbox_Shipping_API(); 515 532 $api_url = $api_call->get_sendbox_api_url('profile'); … … 517 534 'headers' => array( 518 535 'Content-Type' => 'application/json', 519 'Authorization' => $wooss_basic_auth, 536 'Authorization' => $sendbox_auth_token, 537 //'Authorization' => $wooss_basic_auth, 520 538 ), 521 539 ); … … 524 542 $response_code = 1; 525 543 update_option('wooss_connexion_status', $response_code); 526 update_option('wooss_basic_auth', $wooss_basic_auth); 544 //update_option('wooss_basic_auth', $wooss_basic_auth); 545 update_option('sendbox_auth_token', $sendbox_auth_token); 546 update_option('sendbox_refresh_token', $sendbox_refresh_token); 547 update_option('sendbox_app_id', $sendbox_app_id); 548 update_option('sendbox_client_secret', $sendbox_client_secret); 549 527 550 } 528 551 } … … 546 569 $wooss_city = sanitize_text_field($data['wooss_city']); 547 570 $wooss_street = sanitize_text_field($data['wooss_street']); 548 $wooss_basic_auth = sanitize_text_field($data['wooss_basic_auth']); 571 //$wooss_basic_auth = sanitize_text_field($data['wooss_basic_auth']); 572 $sendbox_auth_token = sanitize_text_field($data['sendbox_auth_token']); 573 $sendbox_refresh_token = sanitize_text_field($data['sendbox_refresh_token']); 574 $sendbox_client_secret = sanitize_text_field($data['sendbox_client_secret']); 575 $sendbox_app_id = sanitize_text_field($data['sendbox_app_id']); 576 549 577 $wooss_pickup_type = sanitize_text_field($data['wooss_pickup_type']); 550 578 $wooss_extra_fees = sanitize_text_field($data['wooss_extra_fees']); … … 571 599 $operation_success = 1; 572 600 } 573 if (isset($wooss_basic_auth)) {601 /* if (isset($wooss_basic_auth)) { 574 602 update_option('wooss_basic_auth', $wooss_basic_auth); 575 603 $operation_success = 1; 576 } 604 } */ 605 606 if (isset($sendbox_auth_token)) { 607 update_option('sendbox_auth_token', $sendbox_auth_token); 608 $operation_success = 1; 609 } 610 611 if (isset($sendbox_refresh_token)) { 612 update_option('sendbox_refresh_token', $sendbox_refresh_token); 613 $operation_success = 1; 614 } 615 616 if (isset($sendbox_client_secret)) { 617 update_option('sendbox_client_secret', $sendbox_client_secret); 618 $operation_success = 1; 619 } 620 621 if (isset($sendbox_app_id)) { 622 update_option('sendbox_app_id', $sendbox_app_id); 623 $operation_success = 1; 624 } 625 577 626 if (isset($wooss_pickup_type)) { 578 627 update_option('wooss_pickup_type', $wooss_pickup_type); 579 628 $operation_success = 1; 580 629 } 581 582 630 583 631 … … 719 767 720 768 $payload_data_json = json_encode($payload_data); 721 769 722 770 $delivery_args = array( 723 771 'headers' => array( … … 727 775 'body' => $payload_data_json, 728 776 ); 729 777 //var_dump($delivery_args); 730 778 731 779 $delivery_quotes_url = $api_obj->get_sendbox_api_url('delivery_quote'); 732 780 $delivery_quotes_details = $api_obj->get_api_response_body($delivery_quotes_url, $delivery_args, 'POST'); 733 781 734 782 //var_dump($delivery_quotes_details); 735 783 return $delivery_quotes_details; 736 784 } -
sendbox-shipping/trunk/wooss.php
r2339399 r2341519 16 16 * Plugin URI: # 17 17 * Description: This is a woocommerce plugin that enables you ship from your store in Nigeria to anywhere in the world. 18 * Version: 3.2. 018 * Version: 3.2.1 19 19 * Author: sendbox 20 20 * Author URI: https://sendbox.ng/ … … 35 35 * Rename this for your plugin and update it as you release new versions. 36 36 */ 37 define('WOOSS_VERSION', '3.2. 0');37 define('WOOSS_VERSION', '3.2.1'); 38 38 39 39 /**
Note: See TracChangeset
for help on using the changeset viewer.