Changeset 2488399
- Timestamp:
- 03/06/2021 12:09:40 PM (5 years ago)
- Location:
- sendbox-shipping/trunk
- Files:
-
- 8 edited
-
README.txt (modified) (1 diff)
-
admin/class-wooss-admin.php (modified) (21 diffs)
-
admin/js/wooss-admin.js (modified) (1 diff)
-
includes/assets/js/script.js (modified) (8 diffs)
-
includes/class-wooss-sendbox-shipping-api.php (modified) (5 diffs)
-
includes/class-wooss-shipping-method.php (modified) (24 diffs)
-
public/class-wooss-public.php (modified) (1 diff)
-
wooss.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sendbox-shipping/trunk/README.txt
r2430842 r2488399 112 112 <p>bugs fixes and JS upgrade to use jqueryserilize</p> 113 113 114 115 116 117 114 <b>3.3.0</b> 115 <p>bug fixes </p> 118 116 119 117 -
sendbox-shipping/trunk/admin/class-wooss-admin.php
r2430827 r2488399 21 21 * @author jastrup <jhaastrup21@gmail.com> 22 22 */ 23 class Wooss_Admin 24 { 23 class Wooss_Admin { 24 25 25 26 26 … … 50 50 * @param string $version The version of this plugin. 51 51 */ 52 public function __construct($plugin_name, $version) 53 { 52 public function __construct( $plugin_name, $version ) { 54 53 55 54 $this->plugin_name = $plugin_name; … … 62 61 * @since 1.0.0 63 62 */ 64 public function enqueue_styles() 65 { 63 public function enqueue_styles() { 66 64 /** 65 * This function is provided for demonstration purposes only. 66 * 67 * An instance of this class should be passed to the run() function 68 * defined in wooss_Loader as all of the hooks are defined 69 * in that particular class. 70 * 71 * The wooss_Loader will then create the relationship 72 * between the defined hooks and the functions defined in this 73 * class. 74 */ 75 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wooss-admin.css', array(), $this->version, 'all' ); 76 wp_enqueue_style( 'wooss-select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css', array(), $this->version, 'all' ); 77 wp_enqueue_style( 'wooss_shipping_methods_css_styles', plugin_dir_url( __FILE__ ) . '../includes/assets/css/styles.css', array(), $this->version, 'all' ); 78 } 79 80 /** 81 * Register the JavaScript for the admin area. 82 * 83 * @since 1.0.0 84 */ 85 public function enqueue_scripts() { 86 /** 67 87 * This function is provided for demonstration purposes only. 68 88 * … … 75 95 * class. 76 96 */ 77 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wooss-admin.css', array(), $this->version, 'all'); 78 wp_enqueue_style('wooss_shipping_methods_css_styles', plugin_dir_url(__FILE__) . '../includes/assets/css/styles.css', array(), $this->version, 'all'); 79 } 80 81 /** 82 * Register the JavaScript for the admin area. 83 * 84 * @since 1.0.0 85 */ 86 public function enqueue_scripts() 87 { 88 /** 89 * This function is provided for demonstration purposes only. 90 * 91 * An instance of this class should be passed to the run() function 92 * defined in wooss_Loader as all of the hooks are defined 93 * in that particular class. 94 * 95 * The wooss_Loader will then create the relationship 96 * between the defined hooks and the functions defined in this 97 * class. 98 */ 99 wp_enqueue_script('jquery-ui-dialog'); 100 wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wooss-admin.js', array('jquery'), $this->version, false); 97 wp_enqueue_script( 'jquery-ui-dialog' ); 98 wp_enqueue_script( "wooss-select2", 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js', array( 'jquery' ), $this->version, false ); 99 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wooss-admin.js', array( 'jquery', 'wooss-select2' ), $this->version, false ); 100 101 101 wp_localize_script( 102 102 $this->plugin_name, 103 103 'wooss_ajax_object', 104 [105 'wooss_ajax_url' => admin_url( 'admin-ajax.php'),106 'wooss_ajax_security' => wp_create_nonce( 'wooss-ajax-security-nonce'),107 ]104 array( 105 'wooss_ajax_url' => admin_url( 'admin-ajax.php' ), 106 'wooss_ajax_security' => wp_create_nonce( 'wooss-ajax-security-nonce' ), 107 ) 108 108 ); 109 109 110 wp_enqueue_script( 'wooss_shipping_method_serilizejson_script', plugin_dir_url(__FILE__) . '../includes/assets/js/jqueryserilize.js', array('jquery'), $this->version, false);111 wp_enqueue_script( 'wooss_shipping_method_js_script', plugin_dir_url(__FILE__) . '../includes/assets/js/script.js', array('jquery','wooss_shipping_method_serilizejson_script'), $this->version, false);110 wp_enqueue_script( 'wooss_shipping_method_serilizejson_script', plugin_dir_url( __FILE__ ) . '../includes/assets/js/jqueryserilize.js', array( 'jquery' ), $this->version, false ); 111 wp_enqueue_script( 'wooss_shipping_method_js_script', plugin_dir_url( __FILE__ ) . '../includes/assets/js/script.js', array( 'jquery', 'wooss_shipping_method_serilizejson_script' ), $this->version, false ); 112 112 wp_localize_script( 113 113 'wooss_shipping_method_js_script', 114 114 'wooss_ajax_object', 115 [116 'wooss_ajax_url' => admin_url( 'admin-ajax.php'),117 'wooss_ajax_security' => wp_create_nonce( 'wooss-ajax-security-nonce'),118 ]115 array( 116 'wooss_ajax_url' => admin_url( 'admin-ajax.php' ), 117 'wooss_ajax_security' => wp_create_nonce( 'wooss-ajax-security-nonce' ), 118 ) 119 119 ); 120 120 121 121 } 122 122 … … 124 124 * Function to check if woo-commerce is installed. 125 125 */ 126 public function check_wc() 127 { 128 if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { 126 public function check_wc() { 127 if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 129 128 ?> 130 129 <div class=" notice notice-error"> 131 130 <p> 132 131 <?php 133 esc_html_e( 'Sendbox Shipping require WooCommerce for working. ', 'wooss');132 esc_html_e( 'Sendbox Shipping require WooCommerce for working. ', 'wooss' ); 134 133 ?> 135 134 </p> 136 135 </div> 137 <?php136 <?php 138 137 139 138 } … … 147 146 * @return array 148 147 */ 149 150 public function add_sendbox_metabox() 151 {152 if (!isset($_GET['post']))153 return;154 155 global $post_type;156 if ( is_admin() && "shop_order" == $post_type) {157 $order_id = $_GET['post'];158 $_order = wc_get_order($order_id);159 $method_id = "";160 foreach ( $_order->get_items('shipping') as $item_id => $shipping_item_obj) {148 //phpcs:disable 149 public function add_sendbox_metabox() { 150 if ( ! isset( $_GET['post'] ) ) { 151 return; 152 } 153 154 global $post_type; 155 if ( is_admin() && 'shop_order' == $post_type ) { 156 $order_id = $_GET['post']; 157 $_order = wc_get_order( $order_id ); 158 $method_id = ''; 159 foreach ( $_order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ) { 161 160 $method_id .= $shipping_item_obj->get_method_id(); 162 161 } 163 162 164 if ($method_id == "wooss") { 165 add_meta_box('wooss_ship_sendbox', __('Ship with Sendbox', 'wooss'), array($this, 'field_for_request_shipments'), 'shop_order', 'side', 'high'); 166 } 167 } 168 } 169 170 public function field_for_request_shipments($order) 171 { 163 if ( $method_id == 'wooss' ) { 164 add_meta_box( 'wooss_ship_sendbox', __( 'Ship with Sendbox', 'wooss' ), array( $this, 'field_for_request_shipments' ), 'shop_order', 'side', 'high' ); 165 } 166 } 167 } 168 169 public function field_for_request_shipments( $order ) { 172 170 global $post_type; 173 171 $order_id = $order->ID; 174 if ('shop_order' == $post_type) { 175 $_order = new WC_Order($order_id); 172 $shipping_methods_enabled = get_option( 'wooss_option_enable' ); 173 if ( 'shop_order' == $post_type && $shipping_methods_enabled != "no" ) { 174 $_order = new WC_Order( $order_id ); 176 175 $destination_name = $_order->get_formatted_billing_full_name(); 177 176 $destination_phone = $_order->get_billing_phone(); … … 184 183 $countries_obj = new WC_Countries(); 185 184 186 $states = $countries_obj->get_states( $destination_country);187 foreach ( $states as $state_code => $state_name) {188 if ( $destination_state == $state_code) {185 $states = $countries_obj->get_states( $destination_country ); 186 foreach ( $states as $state_code => $state_name ) { 187 if ( $destination_state == $state_code ) { 189 188 $destination_state = $state_name; 190 189 break; 191 190 } 192 } 193 194 if (empty($destination_state)){195 $destination_state = "London";196 } 197 198 $country = $countries_obj->get_countries();199 foreach ( $country as $country_code => $country_name) {200 if ( $destination_country == $country_code) {191 } 192 193 if ( empty( $destination_state ) ) { 194 $destination_state = 'London'; 195 } 196 197 $country = $countries_obj->get_countries(); 198 foreach ( $country as $country_code => $country_name ) { 199 if ( $destination_country == $country_code ) { 201 200 $destination_country = $country_code; 202 201 break; 203 202 } 204 203 } 205 206 204 207 205 $customer_products = $_order->get_items(); 208 $items_lists = [];206 $items_lists = array(); 209 207 210 208 $fee = 0; 211 209 $quantity = 0; 212 210 213 foreach ( $customer_products as $products_data) {211 foreach ( $customer_products as $products_data ) { 214 212 $product_data = $products_data->get_data(); 215 213 $product_id = $product_data['product_id']; 216 $_product = wc_get_product( $product_id);214 $_product = wc_get_product( $product_id ); 217 215 $items_data = new stdClass(); 218 216 $items_data->name = $product_data['name']; … … 221 219 $items_data->amount_to_receive = $_product->get_price(); 222 220 $items_data->package_size_code = 'medium'; 223 $items_data->item_type_code = strip_tags( wc_get_product_category_list($product_id));221 $items_data->item_type_code = strip_tags( wc_get_product_category_list( $product_id ) ); 224 222 225 223 $product_weight = $_product->get_weight(); 226 if ( null != $product_weight) {224 if ( null != $product_weight ) { 227 225 $weight = $product_weight; 228 226 } else { 229 227 $weight = 0; 230 228 } 231 232 $fee += round( $_product->get_price());229 230 $fee += round( $_product->get_price() ); 233 231 $quantity += $product_data['quantity']; 234 232 $items_data->weight = $weight * $quantity; 235 array_push( $items_lists, $items_data);236 } 237 238 $api_call = new Wooss_Sendbox_Shipping_API();239 //$auth_header = get_option('wooss_basic_auth');240 $ auth_header = Wooss_Sendbox_Shipping_API::checkAuth();233 array_push( $items_lists, $items_data ); 234 } 235 236 $api_call = new Wooss_Sendbox_Shipping_API(); 237 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 238 $sendbox_data = get_option('sendbox_data'); 241 239 $args = array( 240 'timeout' => 30, 242 241 'headers' => array( 243 242 'Content-Type' => 'application/json', … … 246 245 ); 247 246 $profile_api_url = 'https://live.sendbox.co/oauth/profile'; 248 $profile_data_response_code = $api_call->get_api_response_code( $profile_api_url, $args, 'GET');249 $profile_data_response_body = $api_call->get_api_response_body( $profile_api_url, $args, 'GET');247 $profile_data_response_code = $api_call->get_api_response_code( $profile_api_url, $args, 'GET' ); 248 $profile_data_response_body = $api_call->get_api_response_body( $profile_api_url, $args, 'GET' ); 250 249 $wooss_origin_name = ''; 251 250 $wooss_origin_email = ''; 252 251 $wooss_origin_phone = ''; 253 if ( 200 == $profile_data_response_code) {252 if ( 200 == $profile_data_response_code ) { 254 253 $wooss_origin_name = $profile_data_response_body->name; 255 254 $wooss_origin_email = $profile_data_response_body->email; 256 255 $wooss_origin_phone = $profile_data_response_body->phone; 257 256 } 258 $wc_city = get_option( 'woocommerce_store_city');259 $wc_store_address = get_option( 'woocommerce_store_address');260 $wooss_origin_city = get_option('sendbox_data')['wooss_city'];261 $wooss_origin_street = get_option('sendbox_data')['wooss_street'];262 if ( null == $wooss_origin_city) {257 $wc_city = get_option( 'woocommerce_store_city' ); 258 $wc_store_address = get_option( 'woocommerce_store_address' ); 259 $wooss_origin_city = $sendbox_data['wooss_city']; 260 $wooss_origin_street = $sendbox_data['wooss_street']; 261 if ( ! $wooss_origin_city ) { 263 262 $wooss_origin_city = $wc_city; 264 263 } 265 if ( null == $wooss_origin_street) {264 if ( ! $wooss_origin_street ) { 266 265 $wooss_origin_street = $wc_store_address; 267 266 } 268 $wooss_origin_states_selected = get_option('sendbox_data')['wooss_state_dropdown'];269 if ( null == $wooss_origin_states_selected) {267 $wooss_origin_states_selected = $sendbox_data['wooss_state_name']; 268 if ( ! $wooss_origin_states_selected ) { 270 269 $wooss_origin_states_selected = ''; 271 270 } 272 $wooss_origin_country = get_option('wooss_origin_country');273 if ( null == $wooss_origin_country) {271 $wooss_origin_country = $sendbox_data[ 'wooss_origin_country' ]; 272 if ( ! $wooss_origin_country ) { 274 273 $wooss_origin_country = 'Nigeria'; 275 274 } 276 275 277 $wooss_pickup_type = get_option('sendbox_data')['wooss_pickup_type'];278 if ( null == $wooss_pickup_type) {276 $wooss_pickup_type = $sendbox_data['wooss_pickup_type']; 277 if ( ! $wooss_pickup_type ) { 279 278 $wooss_pickup_type = 'pickup'; 280 279 } 281 280 282 $incoming_option_code = get_option('sendbox_data')['wooss_pickup_type'];283 if ( null == $incoming_option_code) {281 $incoming_option_code = $sendbox_data['wooss_pickup_type']; 282 if ( ! $incoming_option_code ) { 284 283 return; 285 284 } 286 285 287 286 $date = new DateTime(); 288 $date->modify('+1 day'); 289 $method_id = ""; 290 $pickup_date = $date->format(DateTime::ATOM); 291 292 293 294 $method_id = ""; 295 foreach ($_order->get_items('shipping') as $item_id => $shipping_item_obj) { 287 $date->modify( '+1 day' ); 288 $method_id = ''; 289 $pickup_date = $date->format( DateTime::ATOM ); 290 291 $method_id = ''; 292 foreach ( $_order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ) { 296 293 $method_id .= $shipping_item_obj->get_method_id(); 297 294 } 298 295 299 if ( $method_id == "wooss") {296 if ( $method_id == 'wooss' ) { 300 297 301 298 ?> … … 303 300 <div id="wooss_shipments_data"> 304 301 305 <span style="display:none;"><strong><?php esc_html_e( 'Origin Details : ', 'wooss'); ?></strong>302 <span style="display:none;"><strong><?php esc_html_e( 'Origin Details : ', 'wooss' ); ?></strong> 306 303 <i>This represents your store details</i> 307 304 <br /> 308 <strong><label for="wooss_origin_name"><?php esc_html_e( 'Name : ', 'wooss'); ?></label></strong>309 <input type="text" name="wooss_origin_name" id="wooss_origin_name" class="wooss-text" value="<?php echo ( esc_attr($wooss_origin_name)); ?>" readonly>305 <strong><label for="wooss_origin_name"><?php esc_html_e( 'Name : ', 'wooss' ); ?></label></strong> 306 <input type="text" name="wooss_origin_name" id="wooss_origin_name" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_name ) ); ?>" readonly> 310 307   311 <strong><label for="wooss_origin_phone"><?php esc_html_e( 'Phone : ', 'wooss'); ?></label></strong>312 <input type="text" name="wooss_origin_phone" id="wooss_origin_phone" class="wooss-text" value="<?php echo ( esc_attr($wooss_origin_phone)); ?>" readonly>308 <strong><label for="wooss_origin_phone"><?php esc_html_e( 'Phone : ', 'wooss' ); ?></label></strong> 309 <input type="text" name="wooss_origin_phone" id="wooss_origin_phone" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_phone ) ); ?>" readonly> 313 310 <br />  314 311 315 <br /><strong><label for="wooss_origin_email"><?php esc_html_e( 'Email : ', 'wooss'); ?></label></strong>316 <input type="text" name="wooss_origin_email" id="wooss_origin_email" class="wooss-text" value="<?php echo ( esc_attr($wooss_origin_email)); ?>" readonly>312 <br /><strong><label for="wooss_origin_email"><?php esc_html_e( 'Email : ', 'wooss' ); ?></label></strong> 313 <input type="text" name="wooss_origin_email" id="wooss_origin_email" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_email ) ); ?>" readonly> 317 314   318 <strong><label for="wooss_origin_street"><?php esc_html_e( 'Street : ', 'wooss'); ?></label></strong>319 <input type="text" name="wooss_origin_street" id="wooss_origin_street" class="wooss-text" class="wooss-text" value="<?php echo ( esc_attr($wc_store_address)); ?>" readonly>315 <strong><label for="wooss_origin_street"><?php esc_html_e( 'Street : ', 'wooss' ); ?></label></strong> 316 <input type="text" name="wooss_origin_street" id="wooss_origin_street" class="wooss-text" class="wooss-text" value="<?php echo ( esc_attr( $wc_store_address ) ); ?>" readonly> 320 317 <br />  321 <br /><strong><label for="wooss_origin_country"><?php esc_html_e( 'Country : ', 'wooss'); ?></label></strong>322 <input type="text" name="wooss_origin_country" id="wooss_origin_country" class="wooss-text" value="<?php echo ( esc_attr($wooss_origin_country)); ?>" readonly>318 <br /><strong><label for="wooss_origin_country"><?php esc_html_e( 'Country : ', 'wooss' ); ?></label></strong> 319 <input type="text" name="wooss_origin_country" id="wooss_origin_country" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_country ) ); ?>" readonly> 323 320   324 <strong><label for="wooss_origin_state"><?php esc_html_e( 'States : ', 'wooss'); ?></label></strong>325 <input type="text" name="wooss_origin_state" id="wooss_origin_state" class="wooss-text" value="<?php echo ( esc_attr($wooss_origin_states_selected)); ?>" readonly>321 <strong><label for="wooss_origin_state"><?php esc_html_e( 'States : ', 'wooss' ); ?></label></strong> 322 <input type="text" name="wooss_origin_state" id="wooss_origin_state" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_states_selected ) ); ?>" readonly> 326 323   327 324 … … 329 326 330 327 331 <br /><strong><label for="wooss_origin_city"><?php esc_html_e( 'City : ', 'wooss'); ?></label></strong>332 <input type="text" name="wooss_origin_city" id="wooss_origin_city" class="wooss-text" value="<?php echo ( esc_attr($wooss_origin_city)); ?>" readonly>328 <br /><strong><label for="wooss_origin_city"><?php esc_html_e( 'City : ', 'wooss' ); ?></label></strong> 329 <input type="text" name="wooss_origin_city" id="wooss_origin_city" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_city ) ); ?>" readonly> 333 330 </span> 334 331 … … 336 333 <br /> 337 334 <br /> 338 <span style="display:none;"><strong><?php esc_html_e( 'Destination Details : ', 'wooss'); ?></strong>335 <span style="display:none;"><strong><?php esc_html_e( 'Destination Details : ', 'wooss' ); ?></strong> 339 336 <i>This represents your customer details</i> 340 337 <br /> 341 <strong><label for="wooss_destination_name"><?php esc_html_e( 'Name : ', 'wooss'); ?></label></strong>342 <input type="text" name="wooss_destination_name" id="wooss_destination_name" class="wooss-text" value="<?php esc_html_e( $destination_name); ?>" readonly>338 <strong><label for="wooss_destination_name"><?php esc_html_e( 'Name : ', 'wooss' ); ?></label></strong> 339 <input type="text" name="wooss_destination_name" id="wooss_destination_name" class="wooss-text" value="<?php esc_html_e( $destination_name ); ?>" readonly> 343 340   344 <label><label for="wooss_destination_phone"><?php esc_html_e( 'Phone : ', 'wooss'); ?></label></label>345 <input type="text" name="wooss_destination_phone" id="wooss_destination_phone" class="wooss-text" value="<?php esc_html_e( $destination_phone); ?>" readonly>341 <label><label for="wooss_destination_phone"><?php esc_html_e( 'Phone : ', 'wooss' ); ?></label></label> 342 <input type="text" name="wooss_destination_phone" id="wooss_destination_phone" class="wooss-text" value="<?php esc_html_e( $destination_phone ); ?>" readonly> 346 343 <br />  347 344 348 <br /><strong><label for="wooss_destination_email"><?php esc_html_e( 'Email : ', 'wooss'); ?></label></strong>349 <input type="text" name="wooss_destination_email" id="wooss_destination_email" class="wooss-text" value="<?php esc_html_e( $destination_email); ?>" readonly>345 <br /><strong><label for="wooss_destination_email"><?php esc_html_e( 'Email : ', 'wooss' ); ?></label></strong> 346 <input type="text" name="wooss_destination_email" id="wooss_destination_email" class="wooss-text" value="<?php esc_html_e( $destination_email ); ?>" readonly> 350 347   351 <strong><label for="wooss_destination_street"><?php esc_html_e( 'Street : ', 'wooss'); ?></label></strong>352 <input type="text" name="wooss_destination_street" id="wooss_destination_street" class="wooss-text" value="<?php esc_html_e( $destination_street); ?>" readonly>348 <strong><label for="wooss_destination_street"><?php esc_html_e( 'Street : ', 'wooss' ); ?></label></strong> 349 <input type="text" name="wooss_destination_street" id="wooss_destination_street" class="wooss-text" value="<?php esc_html_e( $destination_street ); ?>" readonly> 353 350 <br />  354 <br /><strong><label for="wooss_destination_country"><?php esc_html_e( 'Country : ', 'wooss'); ?></label></strong>355 <input type="text" name="wooss_destination_country" id="wooss_destination_country" class="wooss-text" value="<?php esc_html_e( $destination_country); ?>" readonly>351 <br /><strong><label for="wooss_destination_country"><?php esc_html_e( 'Country : ', 'wooss' ); ?></label></strong> 352 <input type="text" name="wooss_destination_country" id="wooss_destination_country" class="wooss-text" value="<?php esc_html_e( $destination_country ); ?>" readonly> 356 353   357 <strong><label for="wooss_destination_state"><?php esc_html_e( 'State : ', 'wooss'); ?></label></strong>358 <input type="text" name="wooss_destination_state" id="wooss_destination_state" class="wooss-text" value="<?php esc_html_e( $destination_state); ?>" readonly>354 <strong><label for="wooss_destination_state"><?php esc_html_e( 'State : ', 'wooss' ); ?></label></strong> 355 <input type="text" name="wooss_destination_state" id="wooss_destination_state" class="wooss-text" value="<?php esc_html_e( $destination_state ); ?>" readonly> 359 356 <br />  360 <br /><strong><label for="wooss_destination_city"><?php esc_html_e( 'City : ', 'wooss'); ?></label></strong>361 <input type="text" name="wooss_destination_city" id="wooss_destination_city" class="wooss-text" value="<?php esc_html_e( $destination_city); ?>" readonly>362 </span>357 <br /><strong><label for="wooss_destination_city"><?php esc_html_e( 'City : ', 'wooss' ); ?></label></strong> 358 <input type="text" name="wooss_destination_city" id="wooss_destination_city" class="wooss-text" value="<?php esc_html_e( $destination_city ); ?>" readonly> 359 </span> 363 360 364 361 <?php 365 362 $product_content = ''; 366 foreach ( $items_lists as $lists_id => $list_data) {363 foreach ( $items_lists as $lists_id => $list_data ) { 367 364 $product_name = $list_data->name; 368 365 $product_quantity = $list_data->quantity; … … 377 374 // loading the payload 378 375 379 $payload_data = new stdClass();380 $payload_data->origin_name = $wooss_origin_name;381 // $payload_data->destination_country = $destination_country;376 $payload_data = new stdClass(); 377 $payload_data->origin_name = $wooss_origin_name; 378 // $payload_data->destination_country = $destination_country; 382 379 $payload_data->destination_country_code = $destination_country; 383 //$payload_data->destination_state_code = ' '; 384 $payload_data->destination_state = $destination_state; 385 $payload_data->destination_city = $destination_city; 386 $payload_data->destination_street = $destination_street; 387 $payload_data->destination_name = $destination_name; 388 $payload_data->destination_phone = $destination_phone; 389 $payload_data->items = $items_lists; 390 $payload_data->weight = (int) $weight * $quantity; 391 $payload_data->amount_to_receive = (int) $fee; 392 $payload_data->origin_country = $wooss_origin_country; 393 $payload_data->origin_state = $wooss_origin_states_selected; 394 395 $payload_data->origin_phone = $wooss_origin_phone; 396 $payload_data->origin_street = $wc_store_address; 397 $payload_data->origin_city = $wooss_origin_city; 398 //$payload_data->deliver_priority_code = 'next_day'; 399 $payload_data->pickup_date = $pickup_date; 400 $payload_data->incoming_option_code = $incoming_option_code; 401 $payload_data->payment_option_code = 'prepaid'; 402 //$payload_data->deliver_type_code = 'last_mile'; 403 404 405 $payload_data_json = wp_json_encode($payload_data); 380 // $payload_data->destination_state_code = ' '; 381 $payload_data->destination_state = $destination_state; 382 $payload_data->destination_city = $destination_city; 383 $payload_data->destination_street = $destination_street; 384 $payload_data->destination_name = $destination_name; 385 $payload_data->destination_phone = $destination_phone; 386 $payload_data->items = $items_lists; 387 $payload_data->weight = (int) $weight * $quantity; 388 $payload_data->amount_to_receive = (int) $fee; 389 $payload_data->origin_country = $wooss_origin_country; 390 $payload_data->origin_state = $wooss_origin_states_selected; 391 392 $payload_data->origin_phone = $wooss_origin_phone; 393 $payload_data->origin_street = $wc_store_address; 394 $payload_data->origin_city = $wooss_origin_city; 395 // $payload_data->deliver_priority_code = 'next_day'; 396 $payload_data->pickup_date = $pickup_date; 397 $payload_data->incoming_option_code = $incoming_option_code; 398 $payload_data->payment_option_code = 'prepaid'; 399 // $payload_data->deliver_type_code = 'last_mile'; 400 401 $payload_data_json = wp_json_encode( $payload_data ); 406 402 $delivery_args = array( 403 'timeout' => 30, 407 404 'headers' => array( 408 405 'Content-Type' => 'application/json', 409 406 'Authorization' => $auth_header, 410 407 ), 411 'body' => $payload_data_json, 412 413 ); 414 //print_r($payload_data_json); 415 416 408 'body' => $payload_data_json, 409 410 ); 411 // print_r($payload_data_json); 412 417 413 ?> 418 414 </div> … … 420 416 <span> 421 417 <!--<label?php _e('Items : ', 'wooss'); ?></label> ---> 422 <textarea style="display:none;" cols="50" class="wooss-textarea" id="wooss_items_list" value="<?php esc_html_e( $product_content); ?>" data-id="<?php echo esc_attr($order_id); ?>"><?php trim(esc_html_e($product_content)); ?></textarea>418 <textarea style="display:none;" cols="50" class="wooss-textarea" id="wooss_items_list" value="<?php esc_html_e( $product_content ); ?>" data-id="<?php echo esc_attr( $order_id ); ?>"><?php trim( esc_html_e( $product_content ) ); ?></textarea> 423 419 <?php 424 $quote_api_url = $api_call->get_sendbox_api_url('delivery_quote');425 $quote_body = $api_call->get_api_response_body( $quote_api_url, $delivery_args, 'POST');426 // var_dump($quote_body);427 420 $quote_api_url = $api_call->get_sendbox_api_url( 'delivery_quote' ); 421 $quote_body = $api_call->get_api_response_body( $quote_api_url, $delivery_args, 'POST' ); 422 // var_dump($quote_body); 423 428 424 $quotes_rates = $quote_body->rates; 429 //print_r($quote_body); 430 431 425 // print_r($quote_body); 426 432 427 $wallet = $quote_body->wallet_balance; 433 434 foreach ( $quotes_rates as $rates_id => $rates_values) {428 429 foreach ( $quotes_rates as $rates_id => $rates_values ) { 435 430 $rates_names = $rates_values->name; 436 431 $rates_fee = $rates_values->fee; 437 $rates_id = $rates_values->id;438 // print_r($rates_values);432 $rates_id = $rates_values->id; 433 // print_r($rates_values); 439 434 } 440 435 … … 445 440 <b> 446 441 <?php 447 esc_attr_e( "WALLET BALANCE");442 esc_attr_e( 'WALLET BALANCE' ); 448 443 ?> 449 444 </b> … … 451 446 <b> 452 447 <?php 453 esc_attr_e( "₦" . $wallet);454 448 esc_attr_e( '₦' . $wallet ); 449 455 450 ?> 456 451 </b> 457 452 458 453 </div> 459 454 460 455 <select id="wooss_selected_courier" > 461 <option value=""> <?php esc_attr_e( "Select a courier... "); ?> </option>456 <option value=""> <?php esc_attr_e( 'Select a courier... ' ); ?> </option> 462 457 <?php 463 464 foreach ( $quotes_rates as $rates_id => $rates_values) {458 459 foreach ( $quotes_rates as $rates_id => $rates_values ) { 465 460 $rates_names = $rates_values->name; 466 461 $rates_fee = $rates_values->fee; 467 $rates_id = $rates_values->courier_id;462 $rates_id = $rates_values->courier_id; 468 463 469 464 ?> 470 <option data-courier-price="<?php esc_attr_e( $rates_fee, 'wooss'); ?> " value="<?php esc_attr_e($rates_id, 'wooss'); ?>" id="<?php _e($rates_id, 'wooss'); ?>"><?php esc_attr_e($rates_names)?></option>471 472 <?php465 <option data-courier-price="<?php esc_attr_e( $rates_fee, 'wooss' ); ?> " value="<?php esc_attr_e( $rates_id, 'wooss' ); ?>" id="<?php _e( $rates_id, 'wooss' ); ?>"><?php esc_attr_e( $rates_names ); ?></option> 466 467 <?php 473 468 } 474 469 ?> … … 477 472 478 473 <?php 479 474 475 // for the countries 476 477 unset( $args['headers']['Authorization'] ); 478 $countries_api_url = add_query_arg( 'page_by', '{"per_page":264}', 'https://api.sendbox.co/auth/countries' ); 479 480 $countries_data_obj = wp_remote_get( $countries_api_url, $args ); 481 482 // https://api.sendbox.co/auth/states?page_by={"per_page":10000}&country_code=NG 483 $countries_body = json_decode( wp_remote_retrieve_body( $countries_data_obj ) ); 484 ?> 485 486 <select id = "wooss_destination_country"> 487 <option data-country-code="default" value=""> 488 <?php _e( 'Please select destination country' ); ?> 489 </option> 490 491 <?php 492 foreach ( $countries_body as $key => $value ) { 493 if ( is_array( $value ) ) { 494 sort( $value ); 495 foreach ( $value as $ship_key => $ship_value ) { 496 echo "<option data-country-code='" . $ship_value->code . "' value='" . $ship_value->name . "'>" . $ship_value->name . ' </option>'; 497 498 } 499 } 500 } 501 ?> 502 </select> 480 503 481 //for the countries504 <?php // end of countries ?> 482 505 483 unset($args['headers']['Authorization']); 484 $countries_api_url = add_query_arg( 'page_by', '{"per_page":264}', 'https://api.sendbox.co/auth/countries' ); 506 <?php 507 508 $country_code_default = 'NG'; 509 510 $states_api_url = add_query_arg( 511 array( 512 'page_by' => '{"per_page":10000}', 513 'filter_by' => '{"country_code":"' . $country_code_default . '"}', 514 ), 515 'https://api.sendbox.co/auth/states' 516 ); 517 $states_data_obj = wp_remote_get( $states_api_url, $args ); 518 519 $states_body = json_decode( wp_remote_retrieve_body( $states_data_obj ) ); 520 521 ?> 485 522 486 $countries_data_obj = wp_remote_get($countries_api_url, $args); 487 488 489 490 // https://api.sendbox.co/auth/states?page_by={"per_page":10000}&country_code=NG 491 $countries_body = json_decode(wp_remote_retrieve_body($countries_data_obj)); 492 ?> 493 494 <select id = "wooss_destination_country"> 495 <option data-country-code="default" value=""> 496 <?php _e('Please select destination country'); ?> 497 </option> 498 499 <?php 500 foreach($countries_body as $key => $value){ 501 if (is_array($value)){ 502 sort($value); 503 foreach($value as $ship_key => $ship_value){ 504 echo "<option data-country-code='".$ship_value->code."' value='".$ship_value->name."'>".$ship_value->name." </option>"; 505 506 } 507 } 508 } 509 ?> 510 </select> 511 512 <?//end of countries?> 513 514 <?php 515 516 $country_code_default = "NG"; 517 518 $states_api_url = add_query_arg( array( 'page_by'=> '{"per_page":10000}' , 'filter_by' => '{"country_code":"'.$country_code_default.'"}'), 'https://api.sendbox.co/auth/states' ); 519 $states_data_obj = wp_remote_get($states_api_url, $args); 520 521 $states_body = json_decode(wp_remote_retrieve_body($states_data_obj)); 522 523 524 ?> 525 526 527 <select id = "wooss_destination_state" > 523 524 <select id = "wooss_destination_state" > 528 525 <option data-state-code="default" value = ""> 529 <?php _e('Please select destination state'); ?> 530 </option> 531 532 <?php 533 foreach($states_body as $states_key => $states_values){ 534 if (is_array($states_values)){ 535 sort($states_values); 536 537 foreach($states_values as $ship_state_key => $ship_state_value){ 538 539 if (!empty($ship_state_value)){ 540 echo "<option data-states-code='".$ship_value->code."' value=".$ship_state_value->name.">".$ship_state_value->name." </option>"; 541 } 542 } 543 } } 544 ?> 526 <?php _e( 'Please select destination state' ); ?> 527 </option> 528 529 <?php 530 foreach ( $states_body as $states_key => $states_values ) { 531 if ( is_array( $states_values ) ) { 532 sort( $states_values ); 533 534 foreach ( $states_values as $ship_state_key => $ship_state_value ) { 535 536 if ( ! empty( $ship_state_value ) ) { 537 echo "<option data-states-code='" . $ship_value->code . "' value=" . $ship_state_value->name . '>' . $ship_state_value->name . ' </option>'; 538 } 539 } 540 } 541 } 542 ?> 545 543 </select> 546 544 547 545 548 546 549 <?php 550 551 $country_code_default = "NG"; 552 if (get_option('wooss_selected_country_code_used')){ 553 $country_code_default = get_option('wooss_selected_country_code_used'); 554 } 555 556 $city_api_url = add_query_arg( array( 'page_by'=> '{"per_page":10000}' , 'filter_by' => '{"country_code":"'.$country_code_default.'"}'), 'https://api.sendbox.co/auth/cities' ); 557 $city_data_obj = wp_remote_get($city_api_url, $args); 558 559 $city_body = json_decode(wp_remote_retrieve_body($city_data_obj)); 560 561 562 ?> 563 <input id= "wooss_destination_city_name" type="text" placeholder="Enter Destination City" value="<?php esc_html_e($destination_city); ?>"> 547 <?php 548 549 $country_code_default = 'NG'; 550 if ( $sendbox_data[ 'wooss_selected_country_code_used' ] ) { 551 $country_code_default = $sendbox_data[ 'wooss_selected_country_code_used' ]; 552 } 553 554 $city_api_url = add_query_arg( 555 array( 556 'page_by' => '{"per_page":10000}', 557 'filter_by' => '{"country_code":"' . $country_code_default . '"}', 558 ), 559 'https://api.sendbox.co/auth/cities' 560 ); 561 $city_data_obj = wp_remote_get( $city_api_url, $args ); 562 563 $city_body = json_decode( wp_remote_retrieve_body( $city_data_obj ) ); 564 565 ?> 566 <input id= "wooss_destination_city_name" type="text" placeholder="Enter Destination City" value="<?php esc_html_e( $destination_city ); ?>"> 564 567 565 568 <?php 566 567 568 569 $postal_code = $_order->get_billing_postcode(); 570 571 572 if (!empty($postal_code)){ 573 574 echo "<input id= 'wooss_postal_code' type='text' value='".$postal_code."' placeholder='Enter Postal Code'>"; 569 570 $postal_code = $_order->get_billing_postcode(); 571 572 if ( ! empty( $postal_code ) ) { 573 574 echo "<input id= 'wooss_postal_code' type='text' value='" . $postal_code . "' placeholder='Enter Postal Code'>"; 575 575 } 576 576 577 577 ?> 578 578 … … 582 582 <b id="dabs"> 583 583 <?php 584 esc_attr_e( "Fee: 0.0");584 esc_attr_e( 'Fee: 0.0' ); 585 585 ?> 586 586 </b> 587 587 588 <button id="wooss_request_shipment" class="button-primary"><?php esc_html_e( 'Request Shipment'); ?></button>588 <button id="wooss_request_shipment" class="button-primary"><?php esc_html_e( 'Request Shipment' ); ?></button> 589 589 </div> 590 590 </span> 591 591 </span> 592 592 <?php 593 }594 }595 }593 } 594 } 595 } 596 596 597 597 /** … … 600 600 * @return void 601 601 */ 602 public function request_shipments() 603 { 604 if (isset($_POST['data'])) { 605 $data = wp_unslash($_POST['data']); 606 $order_id = sanitize_text_field($data['wooss_order_id']); 607 $_order = new WC_Order($order_id); 608 $customer_products = $_order->get_items(); 609 $items_lists = []; 610 611 $fee = 0; 612 $quantity = 0; 613 614 foreach ($customer_products as $products_data) { 615 $product_data = $products_data->get_data(); 616 $product_id = $product_data['product_id']; 617 $_product = wc_get_product($product_id); 618 $items_data = new stdClass(); 619 $items_data->name = $product_data['name']; 620 $items_data->quantity = $product_data['quantity']; 621 $items_data->value = $_product->get_price(); 622 $items_data->amount_to_receive = $_product->get_price(); 623 $items_data->package_size_code = 'medium'; 624 $items_data->item_type_code = strip_tags(wc_get_product_category_list($product_id)); 625 626 $product_weight = $_product->get_weight(); 627 if (null != $product_weight) { 628 $weight = $product_weight; 629 } else { 630 $weight = 0; 631 } 632 633 $fee += round($_product->get_price()); 634 $quantity += $product_data['quantity']; 635 $items_data->weight = $weight * $quantity; 636 array_push($items_lists, $items_data); 602 public function request_shipments() { 603 if ( isset( $_POST['data'] ) ) { 604 $data = wp_unslash( $_POST['data'] ); 605 $order_id = sanitize_text_field( $data['wooss_order_id'] ); 606 $_order = new WC_Order( $order_id ); 607 $customer_products = $_order->get_items(); 608 $items_lists = array(); 609 610 $fee = 0; 611 $quantity = 0; 612 613 foreach ( $customer_products as $products_data ) { 614 $product_data = $products_data->get_data(); 615 $product_id = $product_data['product_id']; 616 $_product = wc_get_product( $product_id ); 617 $items_data = new stdClass(); 618 $items_data->name = $product_data['name']; 619 $items_data->quantity = $product_data['quantity']; 620 $items_data->value = $_product->get_price(); 621 $items_data->amount_to_receive = $_product->get_price(); 622 $items_data->package_size_code = 'medium'; 623 $items_data->item_type_code = strip_tags( wc_get_product_category_list( $product_id ) ); 624 625 $product_weight = $_product->get_weight(); 626 if ( null != $product_weight ) { 627 $weight = $product_weight; 628 } else { 629 $weight = 0; 637 630 } 638 631 639 640 641 $courier_selected = sanitize_text_field($data['wooss_selected_courier']); 642 643 $destination_name = sanitize_text_field($data['wooss_destination_name']); 644 $destination_phone = sanitize_text_field($data['wooss_destination_phone']); 645 $destination_email = sanitize_text_field($data['wooss_destination_email']); 646 $destination_city = sanitize_text_field($data['wooss_destination_city']); 647 $destination_country = sanitize_text_field($data['wooss_destination_country']); 648 $destination_state = sanitize_text_field($data['wooss_destination_state']); 649 $destination_street = sanitize_text_field($data['wooss_destination_street']); 650 651 $origin_name = sanitize_text_field($data['wooss_origin_name']); 652 $origin_phone = sanitize_text_field($data['wooss_origin_phone']); 653 $origin_email = sanitize_text_field($data['wooss_origin_email']); 654 $origin_city = sanitize_text_field($data['wooss_origin_city']); 655 $origin_state = sanitize_text_field($data['wooss_origin_state']); 656 $origin_street = sanitize_text_field($data['wooss_origin_street']); 657 $origin_country = sanitize_text_field($data['wooss_origin_country']); 658 659 $destination_post_code = sanitize_text_field($data['wooss_postal_code']); 660 661 $webhook_url = get_site_url() . '/wp-json/wooss/v2/shipping'; 662 663 $payload_data = new stdClass(); 664 665 //$payload_data->selected_courier_id = $courier_selected; 666 667 $payload_data->destination_name = $destination_name; 668 $payload_data->destination_phone = $destination_phone; 669 $payload_data->destination_email = $destination_email; 670 $payload_data->destination_city = $destination_city; 671 $payload_data->destination_country = $destination_country; 672 $payload_data->destination_state = $destination_state; 673 $payload_data->destination_street = $destination_street; 674 $payload_data->weight = $product_weight; 675 $payload_data->origin_name = $origin_name; 676 $payload_data->origin_phone = $origin_phone; 677 $payload_data->origin_email = $origin_email; 678 $payload_data->origin_city = $origin_city; 679 $payload_data->origin_state = $origin_state; 680 $payload_data->origin_street = $origin_street; 681 $payload_data->origin_country = $origin_country; 682 $payload_data->items = $items_lists; 683 $payload_data->reference_code = trim(str_replace('#', '', $order_id)); 684 $payload_data->amount_to_receive = $_order->get_shipping_total(); 685 $payload_data->delivery_callback = $webhook_url; 686 $payload_data->destination_post_code = $destination_post_code; 687 688 $date = new DateTime(); 689 $date->modify('+1 day'); 690 $pickup_date = $date->format('c'); 691 692 $payload_data->deliver_priority_code = 'next_day'; 693 $payload_data->pickup_date = $pickup_date; 694 $payload_data->channel_code ='api'; 695 $payload_data->rate_code ="standard" ; 696 697 698 $api_call = new Wooss_Sendbox_Shipping_API(); 699 //$auth_header = get_option('wooss_basic_auth'); 700 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth();; 701 702 $payload_data_json = wp_json_encode($payload_data); 703 704 $shipments_args = array( 705 'headers' => array( 706 'Content-Type' => 'application/json', 707 'Authorization' => $auth_header, 708 ), 709 'body' => $payload_data_json, 710 ); 711 //var_dump($shipments_args); 712 713 $shipments_url = $api_call->get_sendbox_api_url('shipments'); 714 715 716 $shipments_details = $api_call->get_api_response_body($shipments_url, $shipments_args, 'POST'); 717 718 //var_dump($shipments_details); 719 if (isset($shipments_details)) { 720 721 $tracking_code = $shipments_details->code; 722 $status_codes = $shipments_details->status_code; 723 $successfull = 0; 724 if ('pending' == $status_codes) { 725 update_post_meta($order_id, 'wooss_tracking_code', 'Your tracking code for this order is : ' . $tracking_code); 726 $successfull = 1; 727 } elseif ('drafted' == $status_codes) { 728 $successfull = 2; 729 } else { 730 $successfull = 3; 731 } 632 $fee += round( $_product->get_price() ); 633 $quantity += $product_data['quantity']; 634 $items_data->weight = $weight * $quantity; 635 array_push( $items_lists, $items_data ); 636 } 637 638 $courier_selected = sanitize_text_field( $data['wooss_selected_courier'] ); 639 640 $destination_name = sanitize_text_field( $data['wooss_destination_name'] ); 641 $destination_phone = sanitize_text_field( $data['wooss_destination_phone'] ); 642 $destination_email = sanitize_text_field( $data['wooss_destination_email'] ); 643 $destination_city = sanitize_text_field( $data['wooss_destination_city'] ); 644 $destination_country = sanitize_text_field( $data['wooss_destination_country'] ); 645 $destination_state = sanitize_text_field( $data['wooss_destination_state'] ); 646 $destination_street = sanitize_text_field( $data['wooss_destination_street'] ); 647 648 $origin_name = sanitize_text_field( $data['wooss_origin_name'] ); 649 $origin_phone = sanitize_text_field( $data['wooss_origin_phone'] ); 650 $origin_email = sanitize_text_field( $data['wooss_origin_email'] ); 651 $origin_city = sanitize_text_field( $data['wooss_origin_city'] ); 652 $origin_state = sanitize_text_field( $data['wooss_origin_state'] ); 653 $origin_street = sanitize_text_field( $data['wooss_origin_street'] ); 654 $origin_country = sanitize_text_field( $data['wooss_origin_country'] ); 655 656 $destination_post_code = sanitize_text_field( $data['wooss_postal_code'] ); 657 658 $webhook_url = get_site_url() . '/wp-json/wooss/v2/shipping'; 659 660 $payload_data = new stdClass(); 661 662 // $payload_data->selected_courier_id = $courier_selected; 663 664 $payload_data->destination_name = $destination_name; 665 $payload_data->destination_phone = $destination_phone; 666 $payload_data->destination_email = $destination_email; 667 $payload_data->destination_city = $destination_city; 668 $payload_data->destination_country = $destination_country; 669 $payload_data->destination_state = $destination_state; 670 $payload_data->destination_street = $destination_street; 671 $payload_data->weight = $product_weight; 672 $payload_data->origin_name = $origin_name; 673 $payload_data->origin_phone = $origin_phone; 674 $payload_data->origin_email = $origin_email; 675 $payload_data->origin_city = $origin_city; 676 $payload_data->origin_state = $origin_state; 677 $payload_data->origin_street = $origin_street; 678 $payload_data->origin_country = $origin_country; 679 $payload_data->items = $items_lists; 680 $payload_data->reference_code = trim( str_replace( '#', '', $order_id ) ); 681 $payload_data->amount_to_receive = $_order->get_shipping_total(); 682 $payload_data->delivery_callback = $webhook_url; 683 $payload_data->destination_post_code = $destination_post_code; 684 685 $date = new DateTime(); 686 $date->modify( '+1 day' ); 687 $pickup_date = $date->format( 'c' ); 688 689 $payload_data->deliver_priority_code = 'next_day'; 690 $payload_data->pickup_date = $pickup_date; 691 $payload_data->channel_code = 'api'; 692 $payload_data->rate_code = 'standard'; 693 694 $api_call = new Wooss_Sendbox_Shipping_API(); 695 // $auth_header = get_option('wooss_basic_auth'); 696 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 697 698 $payload_data_json = wp_json_encode( $payload_data ); 699 700 $shipments_args = array( 701 'timeout' => 30, 702 'headers' => array( 703 'Content-Type' => 'application/json', 704 'Authorization' => $auth_header, 705 ), 706 'body' => $payload_data_json, 707 ); 708 // var_dump($shipments_args); 709 710 $shipments_url = $api_call->get_sendbox_api_url( 'shipments' ); 711 712 $shipments_details = $api_call->get_api_response_body( $shipments_url, $shipments_args, 'POST' ); 713 714 // var_dump($shipments_details); 715 if ( isset( $shipments_details ) ) { 716 717 $tracking_code = $shipments_details->code; 718 $status_codes = $shipments_details->status_code; 719 $successfull = 0; 720 if ( 'pending' == $status_codes ) { 721 update_post_meta( $order_id, 'wooss_tracking_code', 'Your tracking code for this order is : ' . $tracking_code ); 722 $successfull = 1; 723 } elseif ( 'drafted' == $status_codes ) { 724 $successfull = 2; 725 } else { 726 $successfull = 3; 732 727 } 733 echo esc_attr($successfull); 734 735 } 736 wp_die(); 737 } 728 } 729 echo esc_attr( $successfull ); 730 731 } 732 wp_die(); 733 } 738 734 739 735 /** … … 741 737 * post data back to sendbox-shipping plugin. 742 738 */ 743 public function register_routes() 744 { 745 register_rest_route( 746 'wooss/v2', 747 '/shipping', 748 array( 749 'methods' => 'POST', 750 'callback' => array($this, 'post_data'), 751 ) 752 ); 753 } 739 public function register_routes() { 740 register_rest_route( 741 'wooss/v2', 742 '/shipping', 743 array( 744 'methods' => 'POST', 745 'callback' => array( $this, 'post_data' ), 746 ) 747 ); 748 } 754 749 755 750 /** 756 751 * This function updates order status after a post has been made to the webhook url. 757 752 * 758 * @param int $order_id Order ID.753 * @param int $order_id Order ID. 759 754 * @param string $status_code Status Code. 760 755 * 761 756 * @return object 762 757 */ 763 public function update_shipment_status($order_id, $status_code) 764 { 765 $order = wc_get_order($order_id); 766 if (null === $status_code) { 767 $order->update_status('on-hold'); 768 } 769 770 if ('accepted' === $status_code) { 771 $order->update_status('processing'); 772 } 773 774 if ('delivered' === $status_code) { 775 $order->update_status('completed'); 776 } 777 if ('rejected' === $status_code) { 778 $order->update_status('failed'); 779 } 780 781 if ('cancelled' === $status_code) { 782 $order->update_status('cancelled'); 783 } 784 785 return $order; 786 } 758 public function update_shipment_status( $order_id, $status_code ) { 759 $order = wc_get_order( $order_id ); 760 if ( null === $status_code ) { 761 $order->update_status( 'on-hold' ); 762 } 763 764 if ( 'accepted' === $status_code ) { 765 $order->update_status( 'processing' ); 766 } 767 768 if ( 'delivered' === $status_code ) { 769 $order->update_status( 'completed' ); 770 } 771 if ( 'rejected' === $status_code ) { 772 $order->update_status( 'failed' ); 773 } 774 775 if ( 'cancelled' === $status_code ) { 776 $order->update_status( 'cancelled' ); 777 } 778 779 return $order; 780 } 787 781 788 782 /** … … 793 787 * @return mixed 794 788 */ 795 public function post_data(WP_REST_Request $request) 796 { 797 798 $all = $request->get_json_params(); 799 800 $order_id = $all['package']['reference_code']; 801 $status_code = $all['status_code']; 802 $shipment = $this->update_shipment_status($order_id, $status_code); 803 $payload_data_json = wp_json_encode($shipment); 804 805 return $payload_data_json; 806 } 807 789 public function post_data( WP_REST_Request $request ) { 790 791 $all = $request->get_json_params(); 792 793 $order_id = $all['package']['reference_code']; 794 $status_code = $all['status_code']; 795 $shipment = $this->update_shipment_status( $order_id, $status_code ); 796 $payload_data_json = wp_json_encode( $shipment ); 797 798 return $payload_data_json; 799 } 800 808 801 /** 809 * This function gets states from the sendbox call 810 */ 811 public function request_states(){ 812 813 814 815 // this control will check if the value gotten from ajax is really there 816 if (isset($_POST["data"]) && wp_verify_nonce( $_POST['security'], 'wooss-ajax-security-nonce' )){ 817 818 819 $country_code_default = sanitize_text_field($_POST['data']); 820 update_option('wooss_selected_country_code_used',$country_code_default); 821 $args = array( 822 'headers' => array( 823 'Content-Type' => 'application/json', 824 ), 825 ); 826 $states_api_url = add_query_arg( 827 array( 'page_by'=> '{"per_page":10000}' , 'filter_by' => '{"country_code":"'.$country_code_default.'"}'), 'https://api.sendbox.co/auth/states' ); 828 $states_data_obj = wp_remote_get($states_api_url, $args); 829 830 $states_body = json_decode(wp_remote_retrieve_body($states_data_obj)); 831 $html = ""; 832 foreach($states_body as $key => $value){ 833 if (is_array($value)){ 834 sort($value); 835 foreach($value as $ship_key => $ship_value){ 836 837 if (isset($ship_value->code) && isset($ship_value->name)){ 838 839 $html.="<option data-country-code-name='".$ship_value->code."'>".$ship_value->name."</option><br/>"; 840 841 } 842 843 } 844 } 845 } 846 847 echo $html; 848 } 849 wp_die(); 850 } 851 } 802 * This function gets states from the sendbox call 803 */ 804 public function request_states() { 805 806 // this control will check if the value gotten from ajax is really there 807 if ( isset( $_POST['data'] ) && wp_verify_nonce( $_POST['security'], 'wooss-ajax-security-nonce' ) ) { 808 809 $country_code_default = sanitize_text_field( $_POST['data'] ); 810 $sendbox_data = get_option('sendbox_data'); 811 $sendbox_data['wooss_selected_country_code_used'] = $country_code_default; 812 update_option( 'sendbox_data', $sendbox_data ); 813 $args = array( 814 'timeout' => 30, 815 'headers' => array( 816 'Content-Type' => 'application/json', 817 ), 818 ); 819 $states_api_url = add_query_arg( 820 array( 821 'page_by' => '{"per_page":10000}', 822 'filter_by' => '{"country_code":"' . $country_code_default . '"}', 823 ), 824 'https://api.sendbox.co/auth/states' 825 ); 826 $states_data_obj = wp_remote_get( $states_api_url, $args ); 827 828 $states_body = json_decode( wp_remote_retrieve_body( $states_data_obj ) ); 829 $html = ''; 830 foreach ( $states_body as $key => $value ) { 831 if ( is_array( $value ) ) { 832 sort( $value ); 833 foreach ( $value as $ship_key => $ship_value ) { 834 835 if ( isset( $ship_value->code ) && isset( $ship_value->name ) ) { 836 837 $html .= "<option data-country-code-name='" . $ship_value->code . "'>" . $ship_value->name . '</option><br/>'; 838 839 } 840 } 841 } 842 } 843 844 echo $html; 845 } 846 wp_die(); 847 } 848 } -
sendbox-shipping/trunk/admin/js/wooss-admin.js
r2430827 r2488399 1 (function ($) {2 "use strict";1 (function ($) { 2 "use strict"; 3 3 4 /**5 * All of the code for your public-facing JavaScript source6 * should reside in this file.7 *8 * Note: It has been assumed you will write jQuery code here, so the9 * $ function reference has been prepared for usage within the scope10 * of this function.11 *12 * This enables you to define handlers, for when the DOM is ready:13 *14 * $(function() {15 *16 * });17 *18 * When the window is loaded:19 *20 * $( window ).load(function() {21 *22 * });23 *24 * ...and/or other possibilities.25 *26 * Ideally, it is not considered best practise to attach more than a27 * single DOM-ready or window-load handler for a particular page.28 * Although scripts in the WordPress core, Plugins and Themes may be29 * practising this, we should strive to set a better example in our own work.30 */4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 31 31 32 /* $(window).load(function () {33 $('.loader').fadeOut();34 }); */32 /* $(window).load(function () { 33 $('.loader').fadeOut(); 34 }); */ 35 35 36 $(document).ready(function() { 37 var select_choosed = $('select[name="wc_order_action"]').val(); 38 $('select[name="wc_order_action"]').change(function() { 39 select_choosed = this.value; 40 if (select_choosed == "sendbox_shipping_action") { 41 $("button.button.wc-reload").on("click submit", function(e) { 42 e.preventDefault(); 43 $("span#wooss_shipments_data").dialog(); 36 $(document).ready(function () { 37 $('select#wooss_destination_country').select2(); 38 $('select#wooss_destination_state').select2(); 39 var select_choosed = $('select[name="wc_order_action"]').val(); 40 $('select[name="wc_order_action"]').change(function () { 41 select_choosed = this.value; 42 if (select_choosed == "sendbox_shipping_action") { 43 $("button.button.wc-reload").on("click submit", function (e) { 44 e.preventDefault(); 45 $("span#wooss_shipments_data").dialog(); 46 }); 47 } else { 48 $("span#wooss_shipments_data").hide(); 49 } 44 50 }); 45 } else { 46 $("span#wooss_shipments_data").hide(); 47 } 51 52 var request_shipment_btn = $("button#wooss_request_shipment"); 53 request_shipment_btn.on("submit click", function (e) { 54 e.preventDefault(); 55 var wooss_origin_name = $("input[name='wooss_origin_name']").val(); 56 var wooss_origin_phone = $("input[name='wooss_origin_phone']").val(); 57 var wooss_origin_email = $("input[name='wooss_origin_email']").val(); 58 var wooss_origin_country = $("input[name='wooss_origin_country']").val(); 59 var wooss_origin_street = $("input[name='wooss_origin_street']").val(); 60 var wooss_origin_state = $("input[name='wooss_origin_state']").val(); 61 var wooss_origin_city = $("input[name='wooss_origin_city']").val(); 62 63 var wooss_destination_name = $( 64 "input[name = 'wooss_destination_name']" 65 ).val(); 66 67 var wooss_destination_phone = $( 68 "input[name = 'wooss_destination_phone']" 69 ).val(); 70 var wooss_destination_email = $( 71 "input[name = 'wooss_destination_email']" 72 ).val(); 73 var wooss_destination_street = $( 74 "input[name = 'wooss_destination_street']" 75 ).val(); 76 /* var wooss_destination_country = $( 77 "input[name = 'wooss_destination_country']" 78 ).val(); 79 var wooss_destination_state = $( 80 "input[name = 'wooss_destination_state']" 81 ).val();*/ 82 83 var wooss_destination_city = $("input[name = 'wooss_destination_city']").val(); 84 var wooss_postal_code = $( 85 "input#wooss_postal_code" 86 ).val(); 87 88 var wooss_selected_courier = $("select#wooss_selected_courier").val(); 89 $("select#wooss_selected_courier").change(function () { 90 wooss_selected_courier = $(this).val(); 91 //console.log(wooss_selected_courier, "hahh"); 92 }); 93 94 var wooss_destination_country = $("select#wooss_destination_country").val(); 95 $("select#wooss_destination_country").change(function () { 96 wooss_destination_country = $(this).val(); 97 98 }) 99 100 var wooss_destination_state = $("select#wooss_destination_state").val(); 101 $("select#wooss_destination_state").change(function () { 102 wooss_destination_state = $(this).val() 103 }) 104 105 106 var wooss_country_destination_name = $("input#wooss_destination_city_name").val(); 107 108 109 var wooss_order_id = $("textarea#wooss_items_list").data("id"); 110 $.blockUI({message: 'Requesting shipment...'}); 111 var data = { 112 wooss_origin_name: wooss_origin_name, 113 wooss_origin_phone: wooss_origin_phone, 114 wooss_origin_email: wooss_origin_email, 115 wooss_origin_country: wooss_origin_country, 116 wooss_origin_state: wooss_origin_state, 117 wooss_origin_city: wooss_origin_city, 118 wooss_origin_street: wooss_origin_street, 119 120 wooss_destination_name: wooss_destination_name, 121 wooss_destination_phone: wooss_destination_phone, 122 wooss_destination_email: wooss_destination_email, 123 wooss_destination_country: wooss_destination_country, 124 wooss_destination_state: wooss_destination_state, 125 wooss_destination_street: wooss_destination_street, 126 wooss_destination_city: wooss_country_destination_name, 127 wooss_selected_courier: wooss_selected_courier, 128 wooss_postal_code: wooss_postal_code, 129 130 131 wooss_order_id: wooss_order_id 132 }; 133 //console.log(wooss_destination_state); 134 135 $.post( 136 wooss_ajax_object.wooss_ajax_url, 137 { 138 action: "request_shipments", 139 data: data, 140 security: wooss_ajax_object.wooss_ajax_security 141 }, 142 function (response) { 143 144 $.unblockUI(); 145 if (response == 0) { 146 alert("An error occured"); 147 } else if (response == 1) { 148 alert("Shipment Successful"); 149 window.location.reload(); 150 } else if (response == 2 || response == 3) { 151 alert( 152 "insufficient funds login to your sendbox account and top up your wallet" 153 ); 154 } 155 } 156 ); 157 }); 158 159 $("select#wooss_selected_courier").change(function (event) { 160 let price = 161 event.target.options[event.target.selectedIndex].dataset.courierPrice; 162 document.getElementById("dabs").innerText = "Fee: ₦" + price; 163 document.getElementById("dabs").style.color = "#ed2f59"; 164 //console.log(wooss_selected_courier, "hahh"); 165 }); 166 /***function to display rates */ 167 168 169 /***Function to get country code**/ 170 var wooss_selected_country, wooss_selected_country_code; 171 $("select#wooss_destination_country").on('change ', function () { 172 var wooss_selected_option = jQuery(this).children("option:selected"); 173 wooss_selected_country = wooss_selected_option.val(); 174 wooss_selected_country_code = wooss_selected_option.data("countryCode"); 175 $.blockUI(); 176 177 $.post(wooss_ajax_object.wooss_ajax_url, { 178 action: "request_states", 179 data: wooss_selected_country_code, 180 security: wooss_ajax_object.wooss_ajax_security 181 }, 182 function (response) { 183 if (response) { 184 $("select#wooss_destination_state option:gt(0)").remove(); 185 $('select#wooss_destination_state').append(response); 186 $.unblockUI(); 187 } 188 }); 189 190 191 }); 192 48 193 }); 49 50 var request_shipment_btn = $("button#wooss_request_shipment");51 request_shipment_btn.on("submit click", function(e) {52 e.preventDefault();53 var wooss_origin_name = $("input[name='wooss_origin_name']").val();54 var wooss_origin_phone = $("input[name='wooss_origin_phone']").val();55 var wooss_origin_email = $("input[name='wooss_origin_email']").val();56 var wooss_origin_country = $("input[name='wooss_origin_country']").val();57 var wooss_origin_street = $("input[name='wooss_origin_street']").val();58 var wooss_origin_state = $("input[name='wooss_origin_state']").val();59 var wooss_origin_city = $("input[name='wooss_origin_city']").val();60 61 var wooss_destination_name = $(62 "input[name = 'wooss_destination_name']"63 ).val();64 65 var wooss_destination_phone = $(66 "input[name = 'wooss_destination_phone']"67 ).val();68 var wooss_destination_email = $(69 "input[name = 'wooss_destination_email']"70 ).val();71 var wooss_destination_street = $(72 "input[name = 'wooss_destination_street']"73 ).val();74 /* var wooss_destination_country = $(75 "input[name = 'wooss_destination_country']"76 ).val();77 var wooss_destination_state = $(78 "input[name = 'wooss_destination_state']"79 ).val();*/80 81 var wooss_destination_city = $("input[name = 'wooss_destination_city']").val();82 var wooss_postal_code = $(83 "input#wooss_postal_code"84 ).val();85 console.log(wooss_postal_code)86 var wooss_selected_courier = $("select#wooss_selected_courier").val();87 $("select#wooss_selected_courier").change(function() {88 wooss_selected_courier = $(this).val();89 //console.log(wooss_selected_courier, "hahh");90 });91 92 var wooss_destination_country = $("select#wooss_destination_country").val();93 $("select#wooss_destination_country").change(function(){94 wooss_destination_country = $(this).val();95 96 })97 98 var wooss_destination_state = $("select#wooss_destination_state").val();99 $("select#wooss_destination_state").change(function(){100 wooss_destination_state = $(this).val()101 })102 103 104 var wooss_country_destination_name = $("input#wooss_destination_city_name").val();105 106 107 108 var wooss_order_id = $("textarea#wooss_items_list").data("id");109 $.blockUI({message:'Requesting shipment...'});110 var data = {111 wooss_origin_name: wooss_origin_name,112 wooss_origin_phone: wooss_origin_phone,113 wooss_origin_email: wooss_origin_email,114 wooss_origin_country: wooss_origin_country,115 wooss_origin_state: wooss_origin_state,116 wooss_origin_city: wooss_origin_city,117 wooss_origin_street: wooss_origin_street,118 119 wooss_destination_name: wooss_destination_name,120 wooss_destination_phone: wooss_destination_phone,121 wooss_destination_email: wooss_destination_email,122 wooss_destination_country: wooss_destination_country,123 wooss_destination_state: wooss_destination_state,124 wooss_destination_street: wooss_destination_street,125 wooss_destination_city: wooss_country_destination_name,126 wooss_selected_courier: wooss_selected_courier,127 wooss_postal_code:wooss_postal_code,128 129 130 wooss_order_id: wooss_order_id131 };132 //console.log(wooss_destination_state);133 134 $.post(135 wooss_ajax_object.wooss_ajax_url,136 {137 action: "request_shipments",138 data: data,139 security: wooss_ajax_object.wooss_ajax_security140 },141 function(response) {142 143 $.unblockUI();144 if (response == 0) {145 alert("An error occured");146 } else if (response == 1) {147 window.location.reload();148 } else if (response == 2 || response == 3 ) {149 alert(150 "insufficient funds login to your sendbox account and top up your wallet"151 );152 }153 }154 );155 });156 157 $("select#wooss_selected_courier").change(function(event) {158 let price =159 event.target.options[event.target.selectedIndex].dataset.courierPrice;160 document.getElementById("dabs").innerText = "Fee: ₦" + price;161 document.getElementById("dabs").style.color = "#ed2f59";162 //console.log(wooss_selected_courier, "hahh");163 });164 /***function to display rates */165 166 167 /***Function to get country code**/168 var wooss_selected_country, wooss_selected_country_code;169 $("select#wooss_destination_country").on('change ',function(){170 var wooss_selected_option = jQuery(this).children("option:selected");171 wooss_selected_country = wooss_selected_option.val();172 wooss_selected_country_code = wooss_selected_option.data("countryCode"); $.blockUI();173 174 $.post(wooss_ajax_object.wooss_ajax_url,{action: "request_states",175 data: wooss_selected_country_code,176 security: wooss_ajax_object.wooss_ajax_security},177 function(response){178 if (response){179 $("select#wooss_destination_state option:gt(0)").remove();180 $('select#wooss_destination_state').append(response);181 $.unblockUI();182 }183 });184 185 186 });187 188 });189 194 })(jQuery); -
sendbox-shipping/trunk/includes/assets/js/script.js
r2430941 r2488399 43 43 ) { 44 44 $("div.wooss-shipping-settings").hide(); 45 if ($(this).prop("checked")) { 45 $('p.submit').show(); 46 if ($(this).prop("checked") ) { 46 47 $("div.wooss-shipping-settings").show(); 48 $('p.submit').hide(); 47 49 } 48 50 }); … … 50 52 var wc_button_save = $("button.button-primary.woocommerce-save-button"); 51 53 wc_button_save.show(); 52 //var wooss_basic_auth;53 54 var sendbox_auth_token; 54 55 var sendbox_refresh_token; 55 56 var sendbox_app_id; 56 var sendbox_client_secret; 57 var sendbox_client_secret; 57 58 var wooss_connect_btn = $("button.wooss-connect-sendbox"); 58 59 var wooss_errors_message_span = $("span.wooss_errors_pages"); … … 63 64 64 65 wooss_connect_btn.on("click", function (e) { 65 e.preventDefault(); 66 e.preventDefault(); 66 67 var formDetails = $('form').serializeJSON(); 67 68 console.log(formDetails.wooss); 68 69 function reloadPage() { 70 $('p.submit').show(); 69 71 window.location.reload(); 70 72 } … … 87 89 ).insertAfter("br.clear"); 88 90 setTimeout(reloadPage, 10000); 91 89 92 } else if (0 == response) { 90 93 wooss_errors_message_span 91 94 .append( 92 "Invalid access and refresh token login to sendbox and get the correct tokens"95 "Invalid access and refresh token login to sendbox, please can you provide the right ones in order to get the right credentials." 93 96 ) 94 97 .show(); … … 105 108 wooss_button_save.on("submit click", function (e) { 106 109 e.preventDefault(); 107 var wooss_state_name = $("select.wooss_state_ dropdown").val();110 var wooss_state_name = $("select.wooss_state_name").val(); 108 111 var wooss_country = $("select.wooss_country_select").val(); 109 112 var wooss_city = $("input[name='wooss_city']").val(); … … 111 114 var wooss_pickup_type = $("select.wooss_pickup_type").val(); 112 115 var wooss_rates_type = $("select.wooss_rates_type").val(); 113 //wooss_basic_auth = $("input[name='wooss_basic_auth']").val();114 116 sendbox_auth_token = $("input[name='sendbox_auth_token']").val(); 115 117 sendbox_refresh_token = $("input[name='sendbox_refresh_token']").val(); … … 124 126 wooss_city: wooss_city, 125 127 wooss_street: wooss_street, 126 //wooss_basic_auth: wooss_basic_auth,127 128 sendbox_auth_token: sendbox_auth_token, 128 129 sendbox_refresh_token: sendbox_refresh_token, … … 147 148 '<div id="message" class="updated inline"><p><strong>Your settings have been synced.</strong></p></div>' 148 149 ).insertAfter("br.clear"); 150 alert('Your settings have been synced successful.'); 151 $('button.wooss_sync_changes_btn').hide(); 152 $('p.submit').show(); 149 153 } else { 150 alert("Sendbox Error !!!");154 alert("Sendbox: An error has occured, please reach our support on WordPress.org :) thank you for using our plugin."); 151 155 } 152 156 } -
sendbox-shipping/trunk/includes/class-wooss-sendbox-shipping-api.php
r2430827 r2488399 4 4 * This class makes a call to sendbox API 5 5 */ 6 class Wooss_Sendbox_Shipping_API 7 { 6 class Wooss_Sendbox_Shipping_API { 8 7 /** 9 8 * Connect_to_api. 10 9 * 11 * @param mixed $api_url API URL.12 * @param mixed $args arguments.13 * @param mixed $method_type GET|POST.10 * @param mixed $api_url API URL. 11 * @param mixed $args arguments. 12 * @param mixed $method_type GET|POST. 14 13 * 15 14 * @return mixed 16 15 */ 17 public function connect_to_api($api_url, $args, $method_type) 18 { 19 if ('GET' == $method_type) { 20 $response = wp_remote_get(esc_url_raw($api_url), $args); 21 } elseif ('POST' == $method_type) { 22 $response = wp_remote_post(esc_url_raw($api_url), $args); 16 public function connect_to_api( $api_url, $args, $method_type ) { 17 if ( 'GET' == $method_type ) { 18 $response = wp_remote_get( esc_url_raw( $api_url ), $args ); 19 } elseif ( 'POST' == $method_type ) { 20 $response = wp_remote_post( esc_url_raw( $api_url ), $args ); 23 21 } 24 22 … … 32 30 * Get_api_response_code. 33 31 * 34 * @param mixed $api_url API URL.35 * @param mixed $args Parameters, Array is required with credentials.36 * @param mixed $method (GET|POST).32 * @param mixed $api_url API URL. 33 * @param mixed $args Parameters, Array is required with credentials. 34 * @param mixed $method (GET|POST). 37 35 * 38 36 * @return object 39 37 */ 40 public function get_api_response_code( $api_url, $args, $method)41 {42 $ api_call = $this->connect_to_api($api_url, $args, $method);43 $response_code = wp_remote_retrieve_response_code($api_call); 38 public function get_api_response_code( $api_url, $args, $method ) { 39 $api_call = $this->connect_to_api( $api_url, $args, $method ); 40 $response_code = wp_remote_retrieve_response_code( $api_call ); 41 44 42 return $response_code; 45 43 } … … 48 46 * This function gets body content from api. 49 47 * 50 * @param mixed $api_url API URL.51 * @param mixed $args Parameters, Array is required with credentials.52 * @param mixed $method (GET|POST).48 * @param mixed $api_url API URL. 49 * @param mixed $args Parameters, Array is required with credentials. 50 * @param mixed $method (GET|POST). 53 51 * 54 52 * @return object 55 53 */ 56 public function get_api_response_body( $api_url, $args, $method)57 {58 $ api_call = $this->connect_to_api($api_url, $args, $method);59 $response_body = json_decode(wp_remote_retrieve_body($api_call)); 54 public function get_api_response_body( $api_url, $args, $method ) { 55 $api_call = $this->connect_to_api( $api_url, $args, $method ); 56 $response_body = json_decode( wp_remote_retrieve_body( $api_call ) ); 57 60 58 return $response_body; 61 59 } … … 64 62 * This function returns the necessary url that needs Sendbox. 65 63 * 66 * @param mixed $url_type URL Type.64 * @param mixed $url_type URL Type. 67 65 * 68 66 * @return string 69 67 */ 70 public function get_sendbox_api_url($url_type) 71 { 72 if ('delivery_quote' == $url_type) { 68 public function get_sendbox_api_url( $url_type ) { 69 if ( 'delivery_quote' == $url_type ) { 73 70 $url = 'https://live.sendbox.co/shipping/shipment_delivery_quote'; 74 } elseif ( 'countries' == $url_type) {71 } elseif ( 'countries' == $url_type ) { 75 72 $url = 'https://api.sendbox.co/auth/countries?page_by={' . '"per_page"' . ':264}'; 76 } elseif ( 'states' == $url_type) {73 } elseif ( 'states' == $url_type ) { 77 74 $url = 'https://api.sendbox.co/auth/states'; 78 } elseif ( 'shipments' == $url_type) {75 } elseif ( 'shipments' == $url_type ) { 79 76 $url = 'https://live.sendbox.co/shipping/shipments'; 80 } elseif ( 'item_type' == $url_type) {77 } elseif ( 'item_type' == $url_type ) { 81 78 $url = 'https://api.sendbox.ng/v1/item_types'; 82 } elseif ( 'profile' == $url_type) {79 } elseif ( 'profile' == $url_type ) { 83 80 $url = 'https://live.sendbox.co/oauth/profile'; 84 81 } else { 85 82 $url = ''; 86 83 } 84 87 85 return $url; 88 86 } … … 90 88 91 89 /** 92 * 93 * This function checks sendbox oauth 94 */ 95 96 public static function checkAuth(){ 97 98 $api_key = get_option('sendbox_data')['sendbox_auth_token']; 99 $profile_url = "https://live.sendbox.co/oauth/profile"; 100 101 $profile_res = wp_remote_get( $profile_url , 102 array( 'timeout' => 40, 103 'headers' => array( 'Content-Type' => 'application/json', 104 'Authorization'=> $api_key ) 105 )); 106 //var_dump($profile_res); 107 $profile_obj = json_decode($profile_res['body']); 108 109 if(isset($profile_obj->title)){ 110 111 //make a new request to oauth 112 $s_url = 'https://live.sendbox.co/oauth/access/access_token/refresh?'; 113 //('sendbox_data')['sendbox_auth_token'] 114 $app_id = get_option('sendbox_data')['sendbox_app_id']; 115 $client_secret = get_option('sendbox_data')['sendbox_client_secret']; 116 $url_oauth = $s_url.'app_id='.$app_id.'&client_secret='.$client_secret; 117 $refresh_token = get_option('sendbox_data')['sendbox_refresh_token']; 118 119 $oauth_res = wp_remote_get( $url_oauth, 120 array( 'timeout' => 10, 121 'headers' => array( 'Content-Type' => 'application/json', 122 'Refresh-Token'=> $refresh_token ) 123 )); 124 $oauth_obj = json_decode($oauth_res['body']); 125 if(isset($oauth_obj->access_token)){ 126 $new_auth = $oauth_obj->access_token; 127 $sendbox_new_auth = get_option('sendbox_data'); 128 $sendbox_new_auth['sendbox_auth_token']= $new_auth; 129 update_option('sendbox_data',$sendbox_new_auth); 130 131 } 132 if(isset($oauth_obj->refresh_token)){ 133 $new_refresh = $oauth_obj->refresh_token; 134 $sendbox_new_refresh = get_option('sendbox_data'); 135 $sendbox_new_refresh['sendbox_refresh_token'] = $new_refresh; 136 update_option('sendbox_data', $sendbox_new_refresh); 137 } 138 90 * 91 * This function checks sendbox oauth 92 */ 93 94 public static function checkAuth() { 95 96 $sendbox_data_db = get_option( 'sendbox_data' ); 97 $api_key = $sendbox_data_db['sendbox_auth_token']; 98 $profile_url = 'https://live.sendbox.co/oauth/profile'; 99 100 $profile_res = wp_remote_get( 101 $profile_url, 102 array( 103 'timeout' => 40, 104 'headers' => array( 105 'Content-Type' => 'application/json', 106 'Authorization' => $api_key, 107 ), 108 ) 109 ); 110 $class_name = 'WP_Error'; 111 if ( ! ( $profile_res instanceof $class_name ) && isset( $profile_res['body'] ) ) { 112 $profile_obj = json_decode( $profile_res['body'] ); 113 } else { 114 $profile_obj = null; 115 } 116 117 if ( isset( $profile_obj->title ) ) { 118 119 $s_url = 'https://live.sendbox.co/oauth/access/access_token/refresh?'; 120 $app_id = $sendbox_data_db['sendbox_app_id']; 121 $client_secret = $sendbox_data_db['sendbox_client_secret']; 122 $url_oauth = $s_url . 'app_id=' . $app_id . '&client_secret=' . $client_secret; 123 $refresh_token = $sendbox_data_db['sendbox_refresh_token']; 124 125 $oauth_res = wp_remote_get( 126 $url_oauth, 127 array( 128 'timeout' => 10, 129 'headers' => array( 130 'Content-Type' => 'application/json', 131 'Refresh-Token' => $refresh_token, 132 ), 133 ) 134 ); 135 $oauth_obj = json_decode( $oauth_res['body'] ); 136 if ( ! ( $oauth_res instanceof $class_name ) && ! isset( $oauth_res['body'] ) ) { 137 return $api_key; 138 } 139 140 if ( isset( $oauth_obj->access_token ) ) { 141 $new_auth = $oauth_obj->access_token; 142 $sendbox_data_db['sendbox_auth_token'] = $new_auth; 143 update_option( 'sendbox_data', $sendbox_data_db ); 144 145 } 146 if ( isset( $oauth_obj->refresh_token ) ) { 147 $new_refresh = $oauth_obj->refresh_token; 148 $sendbox_data_db['sendbox_refresh_token'] = $new_refresh; 149 update_option( 'sendbox_data', $sendbox_data_db ); 150 } 151 } 152 153 return $api_key; 154 155 } 156 157 158 /** 159 * Static function for getting nigeria states. 160 * 161 * @return array 162 */ 163 public function get_nigeria_states() { 164 $state = array( 165 'Abia', 166 'Adamawa', 167 'Akwa Ibom', 168 'Anambra', 169 'Bauchi', 170 'Benue', 171 'Borno', 172 'Bayelsa', 173 'Cross River', 174 'Delta', 175 'Ebonyi ', 176 'Edo', 177 'Ekiti', 178 'Enugu ', 179 'Federal Capital Territory', 180 'Gombe ', 181 'Jigawa ', 182 ' Imo ', 183 ' Kaduna', 184 'Kebbi ', 185 'Kano', 186 ' Kogi', 187 ' Lagos', 188 'Katsina', 189 'Kwara', 190 'Nasarawa', 191 'Niger ', 192 'Ogun', 193 'Ondo ', 194 'Rivers', 195 'Oyo', 196 'Osun', 197 'Sokoto', 198 'Plateau', 199 'Taraba', 200 'Yobe', 201 'Zamfara', 202 ); 203 204 return $state; 205 } 206 207 139 208 } 140 209 141 else{ 142 $api_key = get_option('sendbox_data')['sendbox_auth_token']; 143 } 144 145 return $api_key; 146 147 148 } 149 150 151 152 /** 153 * Static function for getting nigeria states. 154 * 155 * @return array 156 */ 157 public function get_nigeria_states() 158 { 159 $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'); 160 return $state; 161 } 162 163 164 } 165 166 210 -
sendbox-shipping/trunk/includes/class-wooss-shipping-method.php
r2430827 r2488399 6 6 * @return mixed $string 7 7 */ 8 function wooss_shipping_method() 9 { 10 if (!class_exists('Wooss_Shipping_Method')) { 8 function wooss_shipping_method() { 9 if ( ! class_exists( 'Wooss_Shipping_Method' ) ) { 11 10 /** 12 11 * WooCommerce Sendbox Shipping Method Init Class. … … 14 13 * @return mixed $string 15 14 */ 16 class Wooss_Shipping_Method extends WC_Shipping_Method 17 { 15 class Wooss_Shipping_Method extends WC_Shipping_Method { 18 16 19 17 /** … … 24 22 * @return void 25 23 */ 26 public function __construct($instance_id = 0) 27 { 28 29 $this->id = 'wooss'; 30 $this->instance_id = absint($instance_id); 31 $this->method_title = __('Sendbox Shipping', 'wooss'); 32 $this->method_description = __('Sendbox Custom Shipping Method for Woocommerce', 'wooss'); 33 $this->single_rate = 0; 34 $this->supports = array( 24 public function __construct( $instance_id = 0 ) { 25 26 $this->id = 'wooss'; 27 $this->instance_id = absint( $instance_id ); 28 $this->method_title = __( 'Sendbox Shipping', 'wooss' ); 29 $this->method_description = __( 'Sendbox Custom Shipping Method for Woocommerce', 'wooss' ); 30 $this->single_rate = 0; 31 $this->supports = array( 35 32 'shipping-zones', 36 33 'instance-settings', … … 38 35 'instance-settings-modal', 39 36 ); 40 $this->version = WOOSS_VERSION;37 $this->version = WOOSS_VERSION; 41 38 $this->init_form_fields(); 42 39 $this->init_settings(); 43 $this->enabled = isset($this->settings['enabled']) ? $this->settings['enabled'] : 'yes';40 $this->enabled = isset( $this->settings['enabled'] ) ? $this->settings['enabled'] : 'yes'; 44 41 $this->instance_form_fields = array( 45 42 'enabled' => array( 46 'title' => __( 'Enable/Disable', 'wooss'),43 'title' => __( 'Enable/Disable', 'wooss' ), 47 44 'type' => 'checkbox', 48 'label' => __( 'Enable this shipping method'),45 'label' => __( 'Enable this shipping method' ), 49 46 'default' => $this->enabled, 50 47 ), 51 48 ); 52 $this->title = isset($this->settings['title']) ? $this->settings['title'] : __('Sendbox Shipping', 'wooss');53 $this->shipping_options = 'wooss_eee';54 if ( null !== $this->enabled) {55 update_option( 'wooss_option_enable', $this->enabled);49 $this->title = isset( $this->settings['title'] ) ? $this->settings['title'] : __( 'Sendbox Shipping', 'wooss' ); 50 $this->shipping_options = 'wooss_eee'; 51 if ( null !== $this->enabled ) { 52 update_option( 'wooss_option_enable', $this->enabled ); 56 53 } 57 add_action( 'woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options'));54 add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); 58 55 } 59 60 56 61 57 /** … … 64 60 * @return void 65 61 */ 66 function init_form_fields() 67 { 68 62 function init_form_fields() { 69 63 $this->form_fields = array( 70 64 'enabled' => array( 71 'title' => __( 'Enable/Disable'),65 'title' => __( 'Enable/Disable' ), 72 66 'type' => 'checkbox', 73 'label' => __( 'Enable this shipping method'),67 'label' => __( 'Enable this shipping method' ), 74 68 'default' => 'yes', 75 69 ), 76 70 ); 77 add_action( 'woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options'));71 add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); 78 72 } 79 73 80 /* *74 /* 81 75 * Calculate fees for the shipping method on the frontend. 82 76 * … … 85 79 * @return void 86 80 */ 87 public function calculate_shipping($package = array()) 88 { 89 if (is_cart() || is_checkout()) { 81 public function calculate_shipping( $package = array() ) { 82 if ( is_cart() || is_checkout() ) { 90 83 $api_call = new Wooss_Sendbox_Shipping_API(); 91 84 $quotes_fee = 0; 92 85 $fee = 0; 93 86 $quantity = 0; 94 $items_lists = []; 95 $wooss_extra_fees = esc_attr(get_option('wooss_extra_fees')); 96 foreach ($package['contents'] as $item_id => $values) { 97 if (!empty($values['data']->get_weight())) { 87 $items_lists = array(); 88 $sendbox_data = get_option( 'sendbox_data' ); 89 $wooss_extra_fees = esc_attr( $sendbox_data[ 'wooss_extra_fees' ] ); 90 foreach ( $package['contents'] as $item_id => $values ) { 91 if ( ! empty( $values['data']->get_weight() ) ) { 98 92 $weight = $values['data']->get_weight(); 99 93 } else { 100 94 $weight = 0; 101 95 } 102 $fee += round( $values['line_total']);96 $fee += round( $values['line_total'] ); 103 97 $quantity += $values['quantity']; 104 98 … … 108 102 $outputs->package_size_code = 'medium'; 109 103 $outputs->quantity = $values['quantity']; 110 $outputs->value = round( $values['line_total']);111 $outputs->amount_to_receive = round( $values['line_total']);104 $outputs->value = round( $values['line_total'] ); 105 $outputs->amount_to_receive = round( $values['line_total'] ); 112 106 $outputs->item_type = $values['data']->get_categories(); 113 107 114 array_push( $items_lists, $outputs);115 } 116 117 //$auth_header = get_option('wooss_basic_auth'); 108 array_push( $items_lists, $outputs ); 109 } 110 111 118 112 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 119 113 120 if ( !$auth_header){121 wc_add_notice( sprintf('<strong>Unable to get shipping fees at this time.</strong>'), 'error');122 } 123 124 $origin_country = "Nigeria";//get_option('wooss_country');125 126 $origin_state = get_option('sendbox_data')['wooss_state_dropdown'];127 128 $origin_street = get_option('sendbox_data')['wooss_street'];129 130 $origin_city = get_option('sendbox_data')['wooss_city'];131 132 $incoming_option_code = get_option('sendbox_data')['wooss_pickup_type'];133 134 $profile_url = $api_call->get_sendbox_api_url( 'profile');114 if ( ! $auth_header ) { 115 wc_add_notice( sprintf( '<strong>Unable to get shipping fees at this time.</strong>' ), 'error' ); 116 } 117 118 $origin_country = 'Nigeria';// get_option('wooss_country'); 119 120 $origin_state = $sendbox_data['wooss_state_name']; 121 122 $origin_street = $sendbox_data['wooss_street']; 123 124 $origin_city = $sendbox_data['wooss_city']; 125 126 $incoming_option_code = $sendbox_data['wooss_pickup_type']; 127 128 $profile_url = $api_call->get_sendbox_api_url( 'profile' ); 135 129 $profile_args = array( 130 'timeout' => 30, 136 131 'headers' => array( 137 132 'Content-Type' => 'application/json', … … 139 134 ), 140 135 ); 141 $response_code_from_profile_api = $api_call->get_api_response_code( $profile_url, $profile_args, 'GET');142 $response_body_from_profile_api = $api_call->get_api_response_body( $profile_url, $profile_args, 'GET');143 if ( 200 === $response_code_from_profile_api) {136 $response_code_from_profile_api = $api_call->get_api_response_code( $profile_url, $profile_args, 'GET' ); 137 $response_body_from_profile_api = $api_call->get_api_response_body( $profile_url, $profile_args, 'GET' ); 138 if ( 200 === $response_code_from_profile_api ) { 144 139 $origin_name = $response_body_from_profile_api->name; 145 140 $origin_phone = $response_body_from_profile_api->phone; … … 147 142 } 148 143 $date = new DateTime(); 149 $date->modify( '+1 day');150 $pickup_date = $date->format( DateTime::ATOM);144 $date->modify( '+1 day' ); 145 $pickup_date = $date->format( DateTime::ATOM ); 151 146 152 147 $destination_state_code = $package['destination']['country']; 153 148 $destination_city = $package['destination']['city']; 154 149 $destination_street = $package['destination']['address']; 155 if (empty($destination_street)) { 156 $destination_street = __('Customer street'); 157 } 158 $destination_name = __('Customer X', 'wooss'); 159 $destination_phone = __('00000000', 'wooss'); 160 161 162 $destination_country = wooss_get_countries($package,'country'); 163 $destination_state = wooss_get_countries($package,'state'); 164 165 if (preg_match('/\s\(\w+\)/', $destination_country) == true) { 166 $destination_country = preg_replace('/\s\(\w+\)/', '', $destination_country); 167 } 168 169 if (preg_match('/(\s\(\w+\)\s)|(\s\(\w+\))|(\(\w+\)\s)|(\(\w+\))/', $destination_country) == true) { 170 $destination_country = preg_replace('/(\s\(\w+\)\s)|(\s\(\w+\))|(\(\w+\)\s)|(\(\w+\))/', '', $destination_country); 171 } 172 173 if (preg_match('/United States/', $destination_country) == true) { 174 $destination_country = "United States of America"; 175 } 176 177 if (empty($destination_state)) { 178 //$destination_state = $package['destination']['state']; 179 $destination_state = "London"; 180 } 181 if (empty($destination_city)) { 150 if ( empty( $destination_street ) ) { 151 $destination_street = __( 'Customer street' ); 152 } 153 $destination_name = __( 'Customer X', 'wooss' ); 154 $destination_phone = __( '00000000', 'wooss' ); 155 156 $destination_country = wooss_get_countries( $package, 'country' ); 157 $destination_state = wooss_get_countries( $package, 'state' ); 158 159 if ( preg_match( '/\s\(\w+\)/', $destination_country ) == true ) { 160 $destination_country = preg_replace( '/\s\(\w+\)/', '', $destination_country ); 161 } 162 163 if ( preg_match( '/(\s\(\w+\)\s)|(\s\(\w+\))|(\(\w+\)\s)|(\(\w+\))/', $destination_country ) == true ) { 164 $destination_country = preg_replace( '/(\s\(\w+\)\s)|(\s\(\w+\))|(\(\w+\)\s)|(\(\w+\))/', '', $destination_country ); 165 } 166 167 if ( preg_match( '/United States/', $destination_country ) == true ) { 168 $destination_country = 'United States of America'; 169 } 170 171 if ( empty( $destination_state ) ) { 172 // $destination_state = $package['destination']['state']; 173 $destination_state = 'London'; 174 } 175 if ( empty( $destination_city ) ) { 182 176 $destination_city = $package['destination']['city']; 183 177 } 184 178 185 // if (empty($destination_state)) { 186 // $destination_state = $destination_state; 187 // } 188 189 190 $weight = $quantity * $weight; 179 $weight = $quantity * $weight; 191 180 $payload_array_data = array( 192 'destination_name' => $destination_name,193 'destination_phone' => $destination_phone,194 'destination_country' => $destination_country,195 'destination_state' => $destination_state,196 'destination_street' => $destination_street,197 'destination_city' => $destination_city,198 'items_list' => $items_lists,199 'weight' => $weight,200 'amount_to_receive' => (int) $fee,201 'origin_country' => $origin_country,202 'origin_name' => $origin_name,203 'origin_street' => $origin_street,204 'origin_state' => $origin_state,205 'origin_phone' => $origin_phone,206 'origin_city' => $origin_city,181 'destination_name' => $destination_name, 182 'destination_phone' => $destination_phone, 183 'destination_country' => $destination_country, 184 'destination_state' => $destination_state, 185 'destination_street' => $destination_street, 186 'destination_city' => $destination_city, 187 'items_list' => $items_lists, 188 'weight' => $weight, 189 'amount_to_receive' => (int) $fee, 190 'origin_country' => $origin_country, 191 'origin_name' => $origin_name, 192 'origin_street' => $origin_street, 193 'origin_state' => $origin_state, 194 'origin_phone' => $origin_phone, 195 'origin_city' => $origin_city, 207 196 'deliver_priority_code' => 'next_day', 208 'deliver_type_code' => 'last_mile',209 'payment_option_code' => 'prepaid',210 'incoming_option_code' => $incoming_option_code,211 'pickup_date' => $pickup_date,197 'deliver_type_code' => 'last_mile', 198 'payment_option_code' => 'prepaid', 199 'incoming_option_code' => $incoming_option_code, 200 'pickup_date' => $pickup_date, 212 201 ); 213 202 214 //var_dump($payload_array_data); 215 $delivery_quotes_details = wooss_calculate_shipping($api_call,$payload_array_data,$auth_header); 216 217 // var_dump($delivery_quotes_details); 218 //die(); 219 $wooss_rates_type = get_option('sendbox_data')['wooss_rates_type']; 220 if ("maximum" == $wooss_rates_type && isset($delivery_quotes_details->max_quoted_fee) ) { 203 $delivery_quotes_details = wooss_calculate_shipping( $api_call, $payload_array_data, $auth_header ); 204 205 $wooss_rates_type = $sendbox_data['wooss_rates_type']; 206 if ( 'maximum' == $wooss_rates_type && isset( $delivery_quotes_details->max_quoted_fee ) ) { 221 207 $quotes_fee = $delivery_quotes_details->max_quoted_fee; 222 } elseif ( "minimum" == $wooss_rates_type && isset($delivery_quotes_details->min_quoted_fee) ) {208 } elseif ( 'minimum' == $wooss_rates_type && isset( $delivery_quotes_details->min_quoted_fee ) ) { 223 209 $quotes_fee = $delivery_quotes_details->min_quoted_fee; 224 210 } 225 211 226 212 $quoted_fee = $quotes_fee + $wooss_extra_fees; 227 228 229 /*$destination_country = "United States of America";213 214 /* 215 $destination_country = "United States of America"; 230 216 $destination_state = "Washington"; 231 217 $destination_city = "New York"; 232 218 $destination_postcode = "10001"; */ 233 219 $payload_array_data['destination_country'] = $destination_country; 234 $payload_array_data['destination_state'] = $destination_state; 235 $payload_array_data['destination_city'] = $destination_city; 236 237 238 if (floatval($quoted_fee) == 0){ 239 $delivery_quotes_details = wooss_calculate_shipping($api_call,$payload_array_data,$auth_header); 240 if ("maximum" == $wooss_rates_type && isset($delivery_quotes_details->max_quoted_fee) ) { 220 $payload_array_data['destination_state'] = $destination_state; 221 $payload_array_data['destination_city'] = $destination_city; 222 223 if ( (int)$quoted_fee == 0 ) { 224 $delivery_quotes_details = wooss_calculate_shipping( $api_call, $payload_array_data, $auth_header ); 225 if ( 'maximum' == $wooss_rates_type && isset( $delivery_quotes_details->max_quoted_fee ) ) { 241 226 $quotes_fee = $delivery_quotes_details->max_quoted_fee; 242 } elseif ( "minimum" == $wooss_rates_type && isset($delivery_quotes_details->min_quoted_fee) ) {227 } elseif ( 'minimum' == $wooss_rates_type && isset( $delivery_quotes_details->min_quoted_fee ) ) { 243 228 $quotes_fee = $delivery_quotes_details->min_quoted_fee; 244 229 } 245 230 246 231 $quoted_fee = $quotes_fee + $wooss_extra_fees; 247 232 } 248 233 249 234 $new_rate = array( 250 235 'id' => $this->id, … … 254 239 ); 255 240 256 $this->add_rate( $new_rate);241 $this->add_rate( $new_rate ); 257 242 } 258 243 } … … 260 245 } 261 246 } 262 add_action( 'woocommerce_shipping_init', 'wooss_shipping_method');247 add_action( 'woocommerce_shipping_init', 'wooss_shipping_method' ); 263 248 /** 264 249 * This function is responsible to display class in the settings. … … 268 253 * @return array 269 254 */ 270 function add_wooss_shipping_method($methods) 271 { 255 function add_wooss_shipping_method( $methods ) { 272 256 $methods['wooss'] = 'Wooss_Shipping_Method'; 273 257 return $methods; 274 258 } 275 add_filter( 'woocommerce_shipping_methods', 'add_wooss_shipping_method');276 277 278 279 add_action( 'woocommerce_settings_tabs_shipping', 'wooss_form_fields', 100);259 add_filter( 'woocommerce_shipping_methods', 'add_wooss_shipping_method' ); 260 261 262 263 add_action( 'woocommerce_settings_tabs_shipping', 'wooss_form_fields', 100 ); 280 264 281 265 /** … … 284 268 * @return void 285 269 */ 286 function wooss_form_fields() 287 { 288 $sendbox_auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 289 $shipping_methods_enabled = get_option('wooss_option_enable'); 290 if (isset($_GET['tab']) && $_GET['tab'] == 'shipping' && isset($_GET['section']) && $_GET['section'] == 'wooss' && $shipping_methods_enabled == 'yes') { 291 $api_call = new Wooss_Sendbox_Shipping_API(); 292 //$auth_header = esc_attr(get_option('wooss_basic_auth')); 293 //$auth_header = esc_attr(get_option('sendbox_data')['sendbox_auth_token']); 270 function wooss_form_fields() { 271 $shipping_methods_enabled = get_option( 'wooss_option_enable' ); 272 if ( isset( $_GET['tab'] ) && ( $_GET['tab'] == 'shipping' && isset( $_GET['section'] ) && $_GET['section'] == 'wooss' && $shipping_methods_enabled == 'yes' ) ) { 273 ?> 274 <style> 275 p.submit{ 276 display:none; 277 } 278 </style> 279 <?php 280 281 $sendbox_auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 282 $api_call = new Wooss_Sendbox_Shipping_API(); 283 $sendbox_data = get_option( 'sendbox_data' ); 284 294 285 $auth_header = $sendbox_auth_header; 295 286 $args = array( 296 287 'headers' => array( 288 'timeout' => 30, 297 289 'Content-Type' => 'application/json', 298 290 'Authorization' => $auth_header, … … 300 292 ); 301 293 $profile_api_url = 'https://live.sendbox.co/oauth/profile'; 302 $profile_data_response_code = $api_call->get_api_response_code( $profile_api_url, $args, 'GET');303 $profile_data_response_body = $api_call->get_api_response_body( $profile_api_url, $args, 'GET');294 $profile_data_response_code = $api_call->get_api_response_code( $profile_api_url, $args, 'GET' ); 295 $profile_data_response_body = $api_call->get_api_response_body( $profile_api_url, $args, 'GET' ); 304 296 $wooss_username = ''; 305 297 $wooss_email = ''; 306 298 $wooss_tel = ''; 307 if ( 200 == $profile_data_response_code) {299 if ( 200 == $profile_data_response_code ) { 308 300 $wooss_username = $profile_data_response_body->name; 309 301 $wooss_email = $profile_data_response_body->email; 310 302 $wooss_tel = $profile_data_response_body->phone; 311 303 } 312 $wc_city = get_option('woocommerce_store_city'); 313 $wc_store_address = get_option('woocommerce_store_address'); 314 $wooss_city = get_option('sendbox_data')['wooss_city']; 315 $wooss_store_address = get_option('wooss_store_address'); 316 //$wooss_basic_auth = get_option('wooss_basic_auth'); 317 $wc_extra_fees = (int) get_option('sendbox_data')['wooss_extra_fees']; 318 319 if (null == $wooss_city) { 304 $wc_city = get_option( 'woocommerce_store_city' ); 305 $wc_store_address = get_option( 'woocommerce_store_address' ); 306 $wooss_city = $sendbox_data['wooss_city']; 307 $wooss_store_address = $sendbox_data['wooss_store_address']; 308 $wc_extra_fees = (int) $sendbox_data['wooss_extra_fees']; 309 310 if ( ! $wooss_city ) { 320 311 $wooss_city = $wc_city; 321 312 } 322 if ( null == $wooss_store_address) {313 if ( ! $wooss_store_address ) { 323 314 $wooss_store_address = $wc_store_address; 324 315 } 325 $wooss_states_selected = get_option('wooss_states_selected');326 if ( null == $wooss_states_selected) {327 $wooss_states_selected = ' ';328 } 329 $wooss_country = get_option('wooss_country');330 if ( null == $wooss_country) {316 $wooss_states_selected = $sendbox_data['wooss_state_name']; 317 if ( is_null( $wooss_states_selected ) || ! $wooss_states_selected ) { 318 $wooss_states_selected = 'no_state'; 319 } 320 $wooss_country = $sendbox_data['wooss_country']; 321 if ( ! $wooss_country ) { 331 322 $wooss_country = 'Nigeria'; 332 323 } 333 //$wooss_connection_status = get_option('wooss_basic_auth'); 334 $wooss_connection_status = get_option('sendbox_data')['sendbox_auth_token'];335 //var_dump(); 336 $custom_styles = '';337 338 if ( null != $wooss_connection_status) {324 325 $wooss_connection_status = $sendbox_data['sendbox_auth_token']; 326 327 $custom_styles = ''; 328 329 if ( $wooss_connection_status ) { 339 330 $custom_styles = 'display:none'; 340 331 } 341 //var_dump($custom_styles); 342 $wooss_display_fields = get_option('wooss_connection_status'); 343 //var_dump($wooss_display_fields); 344 if ( $wooss_display_fields) { 345 $display_fields = 'display : inline'; 346 $hide_button = 'display : none'; 347 } 348 $wooss_pickup_type = get_option('sendbox_data')['wooss_pickup_type']; 349 if (null == $wooss_pickup_type) { 332 333 $wooss_display_fields = get_option( 'wooss_connection_status' ); 334 335 $wooss_pickup_type = $sendbox_data['wooss_pickup_type']; 336 if ( ! $wooss_pickup_type ) { 350 337 $wooss_pickup_type = 'pickup'; 351 338 } 352 339 353 if ( null == $wc_extra_fees) {340 if ( ! $wc_extra_fees ) { 354 341 $wc_extra_fees = 0; 355 342 } 356 343 357 $wooss_rates_type = get_option('sendbox_data')['wooss_rates_type'];358 if ( null == $wooss_rates_type) {344 $wooss_rates_type = $sendbox_data['wooss_rates_type']; 345 if ( ! $wooss_rates_type ) { 359 346 $wooss_rates_type = 'maximum'; 360 347 } 361 $wooss_rate_type = array( "maximum", "minimum");362 363 $wooss_pickup_types = array( 'pickup', 'drop-off');348 $wooss_rate_type = array( 'maximum', 'minimum' ); 349 350 $wooss_pickup_types = array( 'pickup', 'drop-off' ); 364 351 $nigeria_states = $api_call->get_nigeria_states(); 365 352 366 367 //var_dump($wooss_display_fields);368 353 ?> 369 354 … … 371 356 <!--Make changes and start using the new oauth---> 372 357 373 <!-- <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 /> --> 374 <div style="<?php esc_attr_e($custom_styles);?>"> 375 <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="wooss[sendbox_auth_token]" value="<?php esc_attr_e($sendbox_auth_token, 'wooss'); ?>"></strong> <br /> 376 <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="wooss[sendbox_refresh_token]" value="<?php esc_attr_e($sendbox_refresh_token, 'wooss'); ?>"></strong> <br /> 377 <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="wooss[sendbox_app_id]" value="<?php esc_attr_e($sendbox_app_id, 'wooss'); ?>"></strong> <br /> 378 <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="wooss[sendbox_client_secret]" value="<?php esc_attr_e($sendbox_client_secret, 'wooss'); ?>"></strong> <br /> 379 <button type="submit" class="button-primary wooss-connect-sendbox wooss_fields"><?php esc_attr_e('Connect to Sendbox', 'wooss'); ?></button><br /> 380 358 <div style="<?php esc_attr_e( $custom_styles ); ?>"> 359 <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="wooss[sendbox_auth_token]" value="<?php esc_attr_e( $sendbox_auth_token, 'wooss' ); ?>"></strong> <br /> 360 <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="wooss[sendbox_refresh_token]" value="<?php esc_attr_e( $sendbox_refresh_token, 'wooss' ); ?>"></strong> <br /> 361 <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="wooss[sendbox_app_id]" value="<?php esc_attr_e( $sendbox_app_id, 'wooss' ); ?>"></strong> <br /> 362 <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="wooss[sendbox_client_secret]" value="<?php esc_attr_e( $sendbox_client_secret, 'wooss' ); ?>"></strong> <br /> 363 <button type="submit" class="button-primary wooss-connect-sendbox wooss_fields"><?php esc_attr_e( 'Connect to Sendbox', 'wooss' ); ?></button><br /> 381 364 </div> 382 <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; }?>"> 365 <div class="wooss_necessary_fields" style=" 366 <?php 367 $display_fields = 'display : none'; 368 if ( $wooss_display_fields && $sendbox_data ) { 369 $display_fields = 'display : inline'; 370 } 371 echo $display_fields; 372 ?> 373 "> 383 374 <table style="width:100%"> 384 375 385 376 <tr> 386 377 <td> 387 <strong><label for="wooss_username"><?php esc_attr_e( 'Name : ', 'wooss'); ?> </label></strong>388 </td> 389 <td> 390 <input readonly type="text" class="wooss-text" placeholder="John Doe" name="wooss[wooss_username]" id="wooss_username" value="<?php esc_attr_e( $wooss_username, 'wooss'); ?>" required>391 </td> 392 </tr> 393 394 395 <tr> 396 <td> 397 <strong><label for="wooss_tel"><?php esc_attr_e( 'Phone Number : ', 'wooss'); ?> </label></strong>398 </td> 399 <td> 400 <input readonly type="tel" class="wooss-text" placeholder="+2340000000000" id="wooss_tel" name="wooss[wooss_tel]" value="<?php esc_attr_e( $wooss_tel, 'wooss'); ?>" required>401 </td> 402 </tr> 403 404 <tr> 405 <td> 406 <strong><label for="wooss_email"><?php esc_attr_e( 'Email : ', 'wooss'); ?> </label></strong>407 </td> 408 <td> 409 <input readonly type="email" class="wooss-text" placeholder="johndoe@gmail.com" id="wooss_email" name="wooss[wooss_email]" value="<?php esc_attr_e( $wooss_email, 'wooss'); ?>" required>410 </td> 411 </tr> 412 413 <tr> 414 <td> 415 <strong><label for="wooss_country"><?php esc_html_e( 'Country : ', 'wooss'); ?></label></strong>378 <strong><label for="wooss_username"><?php esc_attr_e( 'Name : ', 'wooss' ); ?> </label></strong> 379 </td> 380 <td> 381 <input readonly type="text" class="wooss-text" placeholder="John Doe" name="wooss[wooss_username]" id="wooss_username" value="<?php esc_attr_e( $wooss_username, 'wooss' ); ?>" required> 382 </td> 383 </tr> 384 385 386 <tr> 387 <td> 388 <strong><label for="wooss_tel"><?php esc_attr_e( 'Phone Number : ', 'wooss' ); ?> </label></strong> 389 </td> 390 <td> 391 <input readonly type="tel" class="wooss-text" placeholder="+2340000000000" id="wooss_tel" name="wooss[wooss_tel]" value="<?php esc_attr_e( $wooss_tel, 'wooss' ); ?>" required> 392 </td> 393 </tr> 394 395 <tr> 396 <td> 397 <strong><label for="wooss_email"><?php esc_attr_e( 'Email : ', 'wooss' ); ?> </label></strong> 398 </td> 399 <td> 400 <input readonly type="email" class="wooss-text" placeholder="johndoe@gmail.com" id="wooss_email" name="wooss[wooss_email]" value="<?php esc_attr_e( $wooss_email, 'wooss' ); ?>" required> 401 </td> 402 </tr> 403 404 <tr> 405 <td> 406 <strong><label for="wooss_country"><?php esc_html_e( 'Country : ', 'wooss' ); ?></label></strong> 416 407 </td> 417 408 <td> 418 409 <select class="wooss_country_select wooss_selected"> 419 <option value="<?php esc_attr_e( $wooss_country, 'wooss'); ?>" selected><?php esc_html_e($wooss_country, 'wooss'); ?></option>410 <option value="<?php esc_attr_e( $wooss_country, 'wooss' ); ?>" selected><?php esc_html_e( $wooss_country, 'wooss' ); ?></option> 420 411 </select> 421 412 </td> … … 424 415 <tr> 425 416 <td> 426 <strong><label for="wooss_city"><?php esc_attr_e('City : ', 'wooss'); ?></label></strong> 427 </td> 428 <td> 429 <input type="text" class="wooss-text" name="wooss[wooss_city]" value="<?php echo esc_attr_e($wc_city); ?>"> 430 </td> 431 </tr> 432 433 <tr> 434 435 <td> 436 <strong><label for="wooss_state"><?php esc_attr_e('State : ', 'wooss'); ?></label></strong> 437 </td> 438 <td> 417 <strong><label for="wooss_city"><?php esc_attr_e( 'City : ', 'wooss' ); ?></label></strong> 418 </td> 419 <td> 420 <input type="text" class="wooss-text" name="wooss[wooss_city]" value="<?php echo esc_attr_e( $wooss_city ); ?>"> 421 </td> 422 </tr> 423 424 <tr> 425 426 <td> 427 <strong><label for="wooss_state"><?php esc_attr_e( 'State : ', 'wooss' ); ?></label></strong> 428 </td> 429 <td> 430 439 431 <?php 440 echo "<select class='wooss_state_dropdown wooss_fields wooss_selected' name='wooss[wooss_state_dropdown]'>"; 441 foreach ($nigeria_states as $state) { 442 $states_selected = (preg_match("/$wooss_states_selected/", $state) == true) ? 'selected="selected"' : ''; 443 echo "<option value='$state' $states_selected>$state</option>"; 432 $p_holder = '--Select State--'; 433 echo "<select class='wooss_state_name wooss_fields wooss_selected' name='wooss[wooss_state_name]'>"; 434 echo '<option value="no_state">' . $p_holder . '</option>'; 435 foreach ( $nigeria_states as $state ) { 436 437 echo "<option value='$state'>$state</option>"; 438 444 439 } 445 440 echo '</select>'; 446 441 ?> 447 </td> 448 </tr> 449 450 <tr> 451 <td> 452 <strong><label for="wooss_state"><?php esc_attr_e('Pickup types : ', 'wooss'); ?></label></strong> 442 443 <script> 444 jQuery(document).ready(function (){ 445 jQuery("select[name = 'wooss[wooss_state_name]']").val("<?php echo $wooss_states_selected; ?>"); 446 }) 447 </script> 448 </td> 449 </tr> 450 451 <tr> 452 <td> 453 <strong><label for="wooss_state"><?php esc_attr_e( 'Pickup types : ', 'wooss' ); ?></label></strong> 453 454 </td> 454 455 <td> 455 456 <?php 456 457 echo "<select class='wooss_pickup_type wooss_fields wooss_selected' name='wooss[wooss_pickup_type]'>"; 457 foreach ( $wooss_pickup_types as $pickup_types) {458 $types_selected = ( preg_match("/$wooss_pickup_type/", $pickup_types) == true) ? 'selected="selected"' : '';458 foreach ( $wooss_pickup_types as $pickup_types ) { 459 $types_selected = ( preg_match( "/$wooss_pickup_type/", $pickup_types ) == true ) ? 'selected="selected"' : ''; 459 460 echo "<option value='$pickup_types' $types_selected>$pickup_types</option>"; 460 461 } … … 466 467 <tr> 467 468 <td> 468 <strong><label for="wooss_state"><?php esc_attr_e( 'Rates Type: ', 'wooss'); ?></label></strong>469 <strong><label for="wooss_state"><?php esc_attr_e( 'Rates Type: ', 'wooss' ); ?></label></strong> 469 470 </td> 470 471 <td> … … 472 473 echo "<select class='wooss_rates_type wooss_fields wooss_selected' name='wooss[wooss_rates_type]'>"; 473 474 474 foreach ( $wooss_rate_type as $rates_type) {475 $types_selected = ( preg_match("/$wooss_rates_type/", $rates_type) == true) ? 'selected="selected"' : '';475 foreach ( $wooss_rate_type as $rates_type ) { 476 $types_selected = ( preg_match( "/$wooss_rates_type/", $rates_type ) == true ) ? 'selected="selected"' : ''; 476 477 echo "<option value='$rates_type' $types_selected>$rates_type</option>"; 477 478 } … … 483 484 <tr> 484 485 <td> 485 <strong><label for="wooss_street"><?php esc_attr_e( 'Street : ', 'wooss'); ?></label></strong>486 </td> 487 <td> 488 <input type="text" size="100" class="wooss-text" name="wooss[wooss_street]" value="<?php esc_attr_e( $wc_store_address); ?>">489 </td> 490 </tr> 491 492 <tr> 493 <td> 494 <strong><label for="wooss_extra_fees"><?php esc_attr_e( 'Extra fees : ', 'wooss'); ?></label></strong>495 </td> 496 <td> 497 <input class="wooss-text" type="number" id="wooss_extra_fees" name="wooss[wooss_extra_fees]" value="<?php esc_attr_e( $wc_extra_fees); ?>">486 <strong><label for="wooss_street"><?php esc_attr_e( 'Street : ', 'wooss' ); ?></label></strong> 487 </td> 488 <td> 489 <input type="text" size="100" class="wooss-text" name="wooss[wooss_street]" value="<?php esc_attr_e( $wooss_store_address ); ?>"> 490 </td> 491 </tr> 492 493 <tr> 494 <td> 495 <strong><label for="wooss_extra_fees"><?php esc_attr_e( 'Extra fees : ', 'wooss' ); ?></label></strong> 496 </td> 497 <td> 498 <input class="wooss-text" type="number" id="wooss_extra_fees" name="wooss[wooss_extra_fees]" value="<?php esc_attr_e( $wc_extra_fees ); ?>"> 498 499 </td> 499 500 </tr> 500 501 </table> 501 <button type="submit" class="button-primary wooss_save_button "><?php esc_attr_e('Sync changes', 'wooss'); ?></button>502 <button type="submit" class="button-primary wooss_save_button wooss_sync_changes_btn"><?php esc_attr_e( 'Sync changes', 'wooss' ); ?></button> 502 503 503 504 </div> … … 505 506 <span class="wooss_errors_pages wooss_fields"></span> 506 507 </div> 507 <?php508 <?php 508 509 } 509 510 } 510 511 511 add_action( 'wp_ajax_connect_to_sendbox', 'connect_to_sendbox');512 add_action( 'wp_ajax_connect_to_sendbox', 'connect_to_sendbox' ); 512 513 513 514 /** … … 516 517 * @return void 517 518 */ 518 function connect_to_sendbox() 519 { 520 //var_dump($_POST); 521 $response_code = 0; 522 if (isset($_POST['data'])) { 523 $data = wp_unslash($_POST['data']); 524 //$wooss_basic_auth = $data['wooss_basic_auth']; 519 function connect_to_sendbox() { 520 $response_code = 0; 521 //phpcs:disable 522 if ( isset( $_POST['data'] ) ) { 523 $data = wp_unslash( $_POST['data'] ); 525 524 $sendbox_auth_token = $data['sendbox_auth_token']; 526 //$sendbox_refresh_token = $data['sendbox_refresh_token'];527 //$sendbox_client_secret = $data['sendbox_client_secret'];528 //$sendbox_app_id = $data['sendbox_app_id'];529 525 530 526 $api_call = new Wooss_Sendbox_Shipping_API(); 531 $api_url = $api_call->get_sendbox_api_url( 'profile');527 $api_url = $api_call->get_sendbox_api_url( 'profile' ); 532 528 $args = array( 533 529 'headers' => array( 530 'timeout' => 30, 534 531 'Content-Type' => 'application/json', 535 532 'Authorization' => $sendbox_auth_token, 536 //'Authorization' => $wooss_basic_auth,537 533 ), 538 534 ); 539 $response_code_from_api = $api_call->get_api_response_code($api_url, $args, 'GET'); 540 //$response_body_from_profile_api = $api_call->get_api_response_body($api_url, $args, 'GET'); 541 //var_dump($response_body_from_profile_api); 542 if (200 === $response_code_from_api) { 535 $response_code_from_api = $api_call->get_api_response_code( $api_url, $args, 'GET' ); 536 if ( 200 === $response_code_from_api ) { 543 537 $response_code = 1; 544 //update_option('wooss_connexion_status', $response_code); 545 update_option('wooss_connection_status', $response_code); 546 update_option('sendbox_data', $data); 547 //update_option('wooss_basic_auth', $wooss_basic_auth); 548 //update_option('sendbox_auth_token', $sendbox_auth_token); 549 //update_option('sendbox_refresh_token', $sendbox_refresh_token); 550 //update_option('sendbox_app_id', $sendbox_app_id); 551 //update_option('sendbox_client_secret', $sendbox_client_secret); 552 553 } 554 } 555 esc_attr_e($response_code); 538 update_option( 'wooss_connection_status', $response_code ); 539 update_option( 'sendbox_data', $data ); 540 } 541 } 542 esc_attr_e( $response_code ); 556 543 wp_die(); 557 544 } 558 545 559 add_action( 'wp_ajax_save_fields_by_ajax', 'save_fields_by_ajax');546 add_action( 'wp_ajax_save_fields_by_ajax', 'save_fields_by_ajax' ); 560 547 /** 561 548 * Function for saving fields into db using ajax. … … 563 550 * @return mixed $string 564 551 */ 565 function save_fields_by_ajax() 566 { 552 function save_fields_by_ajax() { 567 553 $operation_success = 0; 568 if (isset($_POST['data']) && wp_verify_nonce($_POST['security'], 'wooss-ajax-security-nonce')) { 569 $data = wp_unslash($_POST['data']); 570 $sendbox_data = get_option("sendbox_data"); 571 $new_sendbox_data = array_merge($sendbox_data, $data); 572 update_option('sendbox_data', $new_sendbox_data); 573 574 575 } 576 577 esc_attr_e($operation_success); 554 //phpcs:disable 555 if ( isset( $_POST['data'] ) && wp_verify_nonce( $_POST['security'], 'wooss-ajax-security-nonce' ) ) { 556 $data = wp_unslash( $_POST['data'] ); 557 $sendbox_data = get_option( 'sendbox_data' ); 558 $new_sendbox_data = array_merge( $sendbox_data, $data ); 559 update_option( 'sendbox_data', $new_sendbox_data ); 560 $operation_success = 1; 561 562 } 563 564 esc_attr_e( $operation_success ); 578 565 wp_die(); 579 566 } 580 567 581 568 582 /* add_filter( 'woocommerce_thankyou', 'woosb_update_order_status', 10, 1 );583 584 function woosb_update_order_status( $order_id ) {585 if ( !$order_id ){586 return;587 }588 589 $order = new WC_Order( $order_id );590 if ( 'processing' == $order->get_status() ) {591 if (!current_user_can('administrator')){592 $order->update_status( 'on-hold' );593 }594 }595 return $order_id;596 }597 */598 function action_wooss_checkout_update_order_review($array, $int){599 600 //DO SOMETHING HERE???601 602 WC()->cart->calculate_shipping();603 604 return;605 }606 //add_action('woocommerce_checkout_update_order_review','action_wooss_checkout_update_order_review', 10, 2);607 608 609 569 610 570 /** 611 * This function get the shipping fees from SendBox.571 * This function get the shipping fees from SendBox. 612 572 * 613 573 * @return object|array 614 574 */ 615 function wooss_calculate_shipping( $api_obj,$payload_array_data,$authorization_key){616 $payload_data = new stdClass();617 foreach ($payload_array_data as $key => $value){618 switch ($key){575 function wooss_calculate_shipping( $api_obj, $payload_array_data, $authorization_key ) { 576 $payload_data = new stdClass(); 577 foreach ( $payload_array_data as $key => $value ) { 578 switch ( $key ) { 619 579 case 'destination_name': 620 $payload_data->destination_name = $value;621 break;580 $payload_data->destination_name = $value; 581 break; 622 582 623 583 case 'destination_country': 624 $payload_data->destination_country = $value;625 break;626 627 case 'destination_state' :628 $payload_data->destination_state = $value;629 break;584 $payload_data->destination_country = $value; 585 break; 586 587 case 'destination_state': 588 $payload_data->destination_state = $value; 589 break; 630 590 631 591 case 'destination_city': 632 $payload_data->destination_city = $value;633 break;592 $payload_data->destination_city = $value; 593 break; 634 594 635 595 case 'destination_street': 636 $payload_data->destination_street = $value;637 break;596 $payload_data->destination_street = $value; 597 break; 638 598 639 599 case 'destination_phone': 640 $payload_data->destination_phone = $value; 641 break; 642 643 /* case 'items_list': 644 $payload_data->items = $value; 645 break; */ 646 600 $payload_data->destination_phone = $value; 601 break; 602 603 647 604 case 'weight': 648 $payload_data->weight = $value; 649 break; 650 /* 651 case 'amount_to_receive': 652 $payload_data->amount_to_receive = $value; 653 break; */ 605 $payload_data->weight = $value; 606 break; 654 607 655 608 case 'origin_country': 656 $payload_data->origin_country = $value;657 break;609 $payload_data->origin_country = $value; 610 break; 658 611 659 612 case 'origin_state': 660 $payload_data->origin_state = $value;661 break;613 $payload_data->origin_state = $value; 614 break; 662 615 663 616 case 'origin_name': 664 $payload_data->origin_name = $value; 665 break; 666 617 $payload_data->origin_name = $value; 618 break; 667 619 668 620 case 'origin_phone': 669 $payload_data->origin_phone = $value;670 break;621 $payload_data->origin_phone = $value; 622 break; 671 623 672 624 case 'origin_street': 673 $payload_data->origin_street = $value;674 break;625 $payload_data->origin_street = $value; 626 break; 675 627 676 628 case 'origin_city': 677 $payload_data->origin_city = $value; 678 break; 679 680 /* case 'deliver_priority_code': 681 $payload_data->deliver_priority_code = $value; 682 break; 683 684 685 case 'pickup_date': 686 $payload_data->pickup_date = $value; 687 break; 688 689 case 'incoming_option_code': 690 $payload_data->incoming_option_code = $value; 691 break; 692 693 case 'payment_option_code': 694 $payload_data->payment_option_code = $value; 695 break; 696 697 case 'deliver_type_code': 698 $payload_data->deliver_type_code = $value; 699 break; */ 629 $payload_data->origin_city = $value; 630 break; 700 631 701 632 default: 702 break; 703 } 704 } 705 706 707 $payload_data_json = json_encode($payload_data); 708 633 break; 634 } 635 } 636 637 $payload_data_json = json_encode( $payload_data ); 638 709 639 $delivery_args = array( 640 'timeout' => 30, 710 641 'headers' => array( 711 642 'Content-Type' => 'application/json', … … 713 644 ), 714 645 'body' => $payload_data_json, 715 ); 716 //var_dump($delivery_args); 717 718 $delivery_quotes_url = $api_obj->get_sendbox_api_url('delivery_quote'); 719 $delivery_quotes_details = $api_obj->get_api_response_body($delivery_quotes_url, $delivery_args, 'POST'); 720 721 //var_dump($delivery_quotes_details); 646 ); 647 648 $delivery_quotes_url = $api_obj->get_sendbox_api_url( 'delivery_quote' ); 649 $delivery_quotes_details = $api_obj->get_api_response_body( $delivery_quotes_url, $delivery_args, 'POST' ); 650 722 651 return $delivery_quotes_details; 723 652 } 724 653 725 654 /** 726 * This function is for getting countries or state name. 727 * 728 * @param array $package655 * This function is for getting countries or state name. 656 * 657 * @param array $package 729 658 * @param string $type 730 659 * @return string 731 660 */ 732 function wooss_get_countries( $package,$type){661 function wooss_get_countries( $package, $type ) { 733 662 734 663 $countries_obj = new WC_Countries(); 735 $destination_states = $countries_obj->get_states( $package['destination']['country']);736 $destination_country = $countries_obj->get_shipping_countries( $package['destination']['country']);737 $delivery_state = "";738 739 if ( empty($destination_states)) {740 $destination_states = array( '');741 } 742 743 if ( empty($destination_country)) {744 $destination_country = array( '');745 } 746 747 if ('state' == $type){748 foreach ( $destination_states as $states_code => $states_name) {749 if ( $package['destination']['state'] === $states_code) {664 $destination_states = $countries_obj->get_states( $package['destination']['country'] ); 665 $destination_country = $countries_obj->get_shipping_countries( $package['destination']['country'] ); 666 $delivery_state = ''; 667 668 if ( empty( $destination_states ) ) { 669 $destination_states = array( '' ); 670 } 671 672 if ( empty( $destination_country ) ) { 673 $destination_country = array( '' ); 674 } 675 676 if ( 'state' == $type ) { 677 foreach ( $destination_states as $states_code => $states_name ) { 678 if ( $package['destination']['state'] === $states_code ) { 750 679 $delivery_state = $states_name; 751 680 break; 752 681 } 753 682 } 754 } elseif('country' == $type){755 foreach ( $destination_country as $destination_country_code => $country_name) {756 if ( $package['destination']['country'] === $destination_country_code) {683 } elseif ( 'country' == $type ) { 684 foreach ( $destination_country as $destination_country_code => $country_name ) { 685 if ( $package['destination']['country'] === $destination_country_code ) { 757 686 $delivery_state = $country_name; 758 687 break; … … 761 690 } 762 691 return $delivery_state; 763 692 764 693 } -
sendbox-shipping/trunk/public/class-wooss-public.php
r2127526 r2488399 109 109 */ 110 110 public function add_extra_fees_to_order( $order_id ) { 111 112 $wooss_extra_fees = get_option( 'wooss_extra_fees' );111 $sendbox_data = get_option('sendbox_data'); 112 $wooss_extra_fees = $sendbox_data[ 'wooss_extra_fees' ]; 113 113 update_post_meta( $order_id, 'wooss_extra_fees', 'Your additionnal fees is : ' . $wooss_extra_fees . get_woocommerce_currency() ); 114 114 } -
sendbox-shipping/trunk/wooss.php
r2430838 r2488399 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.218 * Version: 3.3.0 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.2');37 define('WOOSS_VERSION', '3.3.0'); 38 38 39 39 /**
Note: See TracChangeset
for help on using the changeset viewer.