'application/json', 'Device-Type' => 'Web', 'Ver' => '1.0', 'ApiKey' => $api_key ); if($api_settings == 'omni'){ $headers['AccountId'] = $accountID; $data = advatix_omni_order_data( $order_id ); }else{ $data = advatix_fep_order_data( $order_id ); } $args = array( 'headers' => $headers, 'timeout' => 300000, 'body' => wp_json_encode($data) ); $res = wp_remote_post($api_url, $args ); if(simplexml_load_string($res['body'])){ $result_jd = json_decode(json_encode((array)simplexml_load_string($res['body']))); }else{ $result_jd = json_decode($res['body']); } $table_name = $wpdb->base_prefix . 'fep_api_order_resp'; $wpdb->insert( $table_name, array( 'requestJson' => wp_json_encode($data), 'order_id' => $order_id, 'responseMessage' => $result_jd->responseMessage, 'responseStatus' => $result_jd->responseStatus, 'responseStatusCode' => $result_jd->responseStatusCode, 'responseObject' => $result_jd->responseObject, 'type' => 'createOrder', 'time' => current_time( 'mysql' ), ) ); } die(); } /** * Sync Single Order Ajax */ add_action('wp_ajax_adv_sync_fep_order_details', 'adv_sync_fep_order_details_callback'); add_action('wp_ajax_nopriv_adv_sync_fep_order_details', 'adv_sync_fep_order_details_callback'); function adv_sync_fep_order_details_callback() { error_reporting(0); global $wpdb; $order_id = sanitize_text_field($_POST['order_id']); $order = wc_get_order( $order_id ); if ( !$order->has_status('on-hold') && !$order->has_status('checkout-draft') && !$order->has_status('cancelled') && !$order->has_status('pending') && !$order->has_status('refunded') ) { $base_url = advatix_api_option('input_api_url'); $api_url = $base_url.'/order/createOrder'; $api_key = advatix_api_option('input_api_key'); $accountID = advatix_api_option('account_id'); $api_settings = advatix_api_option('api_settings'); $headers = array( 'Content-Type' => 'application/json', 'Device-Type' => 'Web', 'Ver' => '1.0', 'ApiKey' => $api_key ); if($api_settings == 'omni'){ $headers['AccountId'] = $accountID; $data = advatix_omni_order_data( $order_id ); }else{ $data = advatix_fep_order_data( $order_id ); } $args = array( 'headers' => $headers, 'timeout' => 300000, 'body' => wp_json_encode($data) ); $res = wp_remote_post($api_url, $args ); if(simplexml_load_string($res['body'])){ $result_jd = json_decode(json_encode((array)simplexml_load_string($res['body']))); }else{ $result_jd = json_decode($res['body']); } $table_name = $wpdb->base_prefix . 'fep_api_order_resp'; $wpdb->insert( $table_name, array( 'requestJson' => wp_json_encode($data), 'order_id' => $order_id, 'responseMessage' => $result_jd->responseMessage, 'responseStatus' => $result_jd->responseStatus, 'responseStatusCode' => $result_jd->responseStatusCode, 'responseObject' => $result_jd->responseObject, 'type' => 'createOrder', 'time' => current_time( 'mysql' ), ) ); $array = array( 'responseCode' => $result_jd->responseStatusCode, 'responseMessage' => $result_jd->responseMessage ); }else{ $array = array( 'responseCode' => '201', 'responseMessage' => 'Order is either on-hold, draft or cancelled' ); } echo wp_json_encode($array); die(); } /** * Update Single Order Ajax */ add_action('wp_ajax_adv_update_fep_order_details', 'adv_update_fep_order_details_callback'); add_action('wp_ajax_nopriv_adv_update_fep_order_details', 'adv_update_fep_order_details_callback'); function adv_update_fep_order_details_callback() { error_reporting(0); /*global $wpdb; $order_id = sanitize_text_field($_POST['order_id']); $base_url = advatix_api_option('input_api_url'); $api_key = advatix_api_option('input_api_key'); $accountID = advatix_api_option('account_id'); $api_settings = advatix_api_option('api_settings'); $headers = array( 'Content-Type' => 'application/json', 'Device-Type' => 'Web', 'Ver' => '1.0', 'ApiKey' => $api_key ); if($api_settings == 'omni'){ $headers['AccountId'] = $accountID; $data = advatix_omni_order_data( $order_id ); $api_url = $base_url.'/order/createOrder'; $args = array( 'headers' => $headers, 'timeout' => 300000, 'body' => wp_json_encode($data), 'method' => 'POST' ); }else{ $data = advatix_fep_order_data( $order_id ); $api_url = $base_url.'/order/updateOrder'; $args = array( 'headers' => $headers, 'timeout' => 300000, 'body' => wp_json_encode($data), 'method' => 'PUT' ); } $res = wp_remote_request($api_url, $args ); if(simplexml_load_string($res['body'])){ $result_jd = json_decode(json_encode((array)simplexml_load_string($res['body']))); }else{ $result_jd = json_decode($res['body']); } $table_name = $wpdb->base_prefix . 'fep_api_order_resp'; $wpdb->insert( $table_name, array( 'requestJson' => wp_json_encode($data), 'order_id' => $order_id, 'responseMessage' => $result_jd->responseMessage, 'responseStatus' => $result_jd->responseStatus, 'responseStatusCode' => $result_jd->responseStatusCode, 'responseObject' => $result_jd->responseObject, 'type' => 'updateOrder', 'time' => current_time( 'mysql' ), ) ); $array = array( 'responseCode' => $result_jd->responseStatusCode, 'responseMessage' => $result_jd->responseMessage ); // echo wp_json_encode($res['body']); echo wp_json_encode($array); die();*/ } /** * Fetch Single Order FEP API response Ajax */ add_action('wp_ajax_adv_get_fep_api_details', 'adv_get_fep_api_details_callback'); add_action('wp_ajax_nopriv_adv_get_fep_api_details', 'adv_get_fep_api_details_callback'); function adv_get_fep_api_details_callback() { error_reporting(0); global $wpdb; $table_name = $wpdb->base_prefix . 'fep_api_order_resp'; $q = $wpdb->get_results('SELECT * FROM '.$table_name.' WHERE order_id="'.sanitize_text_field($_POST['order_id']).'" ORDER BY id DESC LIMIT 10'); if(!empty($q)){ foreach($q as $k=>$v){ echo "