"; //print_r($json_string); //echo ""; header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: access"); header("Access-Control-Allow-Methods: POST"); header("Access-Control-Allow-Credentials: true"); header('Content-Type: application/json'); /* echo "
";
print_r($_POST);
print_r($_GET);
print_r($_REQUEST);
echo "
"; */ $api_json = '{"OrderNumber":"249","signature":"base64 code"}'; $api_data_decode[] = json_decode($api_json,true); if($_POST){ $order_number = $_POST['OrderNumber']; $signature = $_POST['signature']; } if(empty($signature) && empty($order_number)){ $json = array('error'=>'E001','message'=>'Order number and signature is empty'); } elseif(empty($order_number)){ $json = array('error'=>'E002','message'=>'Order number empty'); } elseif(empty($signature)){ $json = array('error'=>'E003','message'=>'Signature is empty'); } elseif($order_number && $signature){ $query = new WC_Order_Query( array('limit'=> -1,'orderby' => 'date','order' => 'DESC') ); $orders = $query->get_orders(); $order_array = array(); foreach($orders as $order){ $order_id = $order->ID; $order_array[] = $order->ID; $order = new WC_Order( $order_id ); $order_status = $order->get_status(); //echo $order_id.' '.$order_status.'
'; foreach($api_data_decode as $api_data_decodes){ if($order_number == $order_id){ $json = array('error'=>'E004','message'=>'Successful'); update_post_meta( $order_number, 'api_signature', $signature ); $order->update_status('completed', 'order_note'); } } } if(!in_array($order_number,$order_array)){ $json = array('error'=>'E005','message'=>'Order Not Found'); } } else{ $json = array('error'=>'E006','message'=>'Failed'); } echo $json_encode = json_encode($json); ?>