hjkhghtjhjjhjhjhjhjjhjhjjhrrtrtoirh
bnmbertsurrttrtrtrtrjhjhjjhjhhjhjhjhf'tdfg
/
home
/
u506006416
/
domains
/
crystalmiracle.co.in
/
public_html
/
admin
/
include
/
Upload FileeE
HOME
<?php include_once('config.php'); class shiprocket_config extends config{ public function order_by_orderID($order_id){ $query = "SELECT * FROM orders WHERE order_id = '$order_id'"; $query_run = mysqli_query($this->con, $query); $row = mysqli_fetch_array($query_run, true); if (!empty($row)) { return $row; }else{ return array(); } } public function all_orders(){ $query = "SELECT * FROM orders WHERE order_id != ''"; $query_run = mysqli_query($this->con, $query); while($row = mysqli_fetch_array($query_run, true)){ $roww[] = $row; } return $roww; } public function update_orders($table,$update_order,$order_where_condition){ $this->update($table,$update_order,$order_where_condition); } public function item_list_in_order($orderID=''){ $query = "SELECT * FROM temp_cart WHERE order_id = '$orderID' AND status='0'"; $query_run = mysqli_query($this->con, $query); while($row = mysqli_fetch_array($query_run, true)){ $roww[] = $row; } return $roww; } public function ncr_pincode_list(){ $query = "SELECT * FROM pincode"; $query_run = mysqli_query($this->con, $query); while($row = mysqli_fetch_array($query_run, true)){ $roww[] = $row; } return $roww; } public function ncr_pincode_single($pincode){ $query = "SELECT * FROM pincode WHERE pincode = '$pincode'"; $query_run = mysqli_query($this->con, $query); $row = mysqli_fetch_array($query_run, true); if (!empty($row)) { return $row; }else{ return array(); } } public function displayRecodsAl($table_name,$condition1){ return $this->display_rcd($table_name,$condition1); } public function send_to_shiprocket($order_id=''){ $get_order = $this->order_by_orderID($order_id); $get_pincode = $this->ncr_pincode_single($get_order['pincode']); $item_list = []; if (!empty($get_order) && empty($get_pincode)) { /*---- Item List ----*/ $all_item = $this->item_list_in_order($get_order['id']); foreach($all_item as $item){ $condition1="`p_id`=".$item['p_id']; $p_query=$this->display_rcd('product',$condition1); if(is_array($p_query) || !empty($p_query)) { foreach($p_query as $p_data) { } } $hsn_code = (int)$p_data['hsn_code']; if ($hsn_code=='' || $hsn_code==0) { $hsn = 1234; }else{ $hsn = $hsn_code; } $item_list[] = array( "name" => $p_data['p_name'], "sku" => $p_data['p_code'], "units" => $item['quantity'], "selling_price" => $item['d_price'], "discount" => $item['offer_discount'], "tax" => $item['gst'], "hsn" => $hsn ); } /*--------- Payment Method -----*/ if ($get_order['pay_type']==1) { $payment_method = 'COD'; }elseif ($get_order['pay_type']==2) { $payment_method = 'Prepaid'; }else{ $payment_method = ''; } /*--------- Weight -----*/ if ($get_order['weight']<=0) { $weight = 0.100; }else{ $weight = $get_order['weight']; } /*--------- length -----*/ if ($get_order['length']<=0) { $length = 10; }else{ $length = $get_order['length']; } /*--------- breadth -----*/ if ($get_order['breadth']<=0) { $breadth = 8; }else{ $breadth = $get_order['breadth']; } /*--------- height -----*/ if ($get_order['height']<=0) { $height = 2; }else{ $height = $get_order['height']; } /*----------------------*/ $jayParsedAry = [ "order_id" => $order_id, "order_date" => $get_order['order_date'], "pickup_location" => "Primary", "channel_id" => "1547485", "comment" => "Reseller: M/s Rohan", "billing_customer_name" => $get_order['f_name'], "billing_last_name" => $get_order['l_name'], "billing_address" => $get_order['str_address1'], "billing_address_2" => $get_order['str_address2'], "billing_city" => $get_order['town'], "billing_pincode" => $get_order['pincode'], "billing_state" => $get_order['state'], "billing_country" => "India", "billing_email" => $get_order['e_address'], "billing_phone" => $get_order['p_no'], "shipping_is_billing" => true, "shipping_customer_name" => "", "shipping_last_name" => "", "shipping_address" => "", "shipping_address_2" => "", "shipping_city" => "", "shipping_pincode" => "", "shipping_country" => "", "shipping_state" => "", "shipping_email" => "", "shipping_phone" => "", "order_items" => $item_list, "payment_method" => $payment_method, "shipping_charges" => 0, "giftwrap_charges" => 0, "transaction_charges" => 0, "total_discount" => 0, "sub_total" => $get_order['t_price'], "length" => $length, "breadth" => $breadth, "height" => $height, "weight" => $weight ]; // echo "<pre>"; print_r($jayParsedAry); die(); $order_data = json_encode($jayParsedAry); // echo $order_data; die(); /*============ Authenticate Login ===========*/ $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://apiv2.shiprocket.in/v1/external/auth/login', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{ "email": "rohan@a4paper.in", "password": "Stereo@1879" }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); // echo $response; $res=json_decode($response); $token = null; #Get login Authentication token $token=$res->token; // print_r($res); die(); /*======================== Create Order ==========================*/ if($res->token){ $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://apiv2.shiprocket.in/v1/external/orders/create/adhoc', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>$order_data, CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "Authorization: Bearer $token" ), )); $response = curl_exec($curl); curl_close($curl); // echo $response; $res=json_decode($response); // echo "<pre>"; print_r($res); die(); if($res->status_code==1 || $res->status_code==200){ $status="Success"; $msg="Order Placed Successfully"; $update_order = array('assign_to'=>'Shiprocket','shiprocketODR_id'=>$res->order_id, 'order_status'=>'Processed'); $order_where_condition = array('order_id'=>$order_id); $this->update("orders",$update_order,$order_where_condition); }else{ $status="Fail"; $msg = "Failed to create order"; } return $msg; } } } public function cancel_order($order_id=''){ /*--------- Check Order ID -------------*/ $get_order = $this->order_by_orderID($order_id); // echo "<pre>"; print_r($get_order); die(); if (!empty($get_order)){ /*============ Authenticate Login ===========*/ $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://apiv2.shiprocket.in/v1/external/auth/login', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{ "email": "rohan@a4paper.in", "password": "Stereo@1879" }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); // echo $response; $res=json_decode($response); $token = null; #Get login Authentication token $token=$res->token; // echo "<pre>"; print_r($res); die(); // $shiprocketODR_id = str_replace('ODR', '', $order_id); $arr_ODR = '['.$get_order['shiprocketODR_id'].']'; // echo '{ // "ids": '.$arr_ODR.' // }'; // die(); /*========= Cancel Order =============*/ $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://apiv2.shiprocket.in/v1/external/orders/cancel', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{ "ids": '.$arr_ODR.' }', CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "Authorization: Bearer $token" ), )); $response = curl_exec($curl); curl_close($curl); // echo $response; $res=json_decode($response); // echo "<pre>"; print_r($res); die(); if($res->status_code==1 || $res->status_code==200 || $res->status_code==202){ $status="Success"; $msg="Order Cancelled Successfully"; /*------- Update Order Table -------*/ $update_order = array('order_status'=>'Canceled'); $order_where_condition = array('order_id'=>$order_id, 'assign_to'=>'Shiprocket'); $this->update("orders",$update_order,$order_where_condition); }else{ $status="Fail"; $msg = "Failed to cancel order"; } return $msg; } } /*=========== Check Availability =============*/ public function check_service($delivery_postcode=''){ /*============ Authenticate Login ===========*/ $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://apiv2.shiprocket.in/v1/external/auth/login', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{ "email": "rohan@a4paper.in", "password": "Stereo@1879" }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); // echo $response; $res=json_decode($response); $token = null; $token=$res->token; // echo "<pre>"; print_r($res); die(); /*-------------- Post Data ----------------*/ $jayParsedAry = [ "pickup_postcode" => 110027, "delivery_postcode" => $delivery_postcode, "weight" => 0.5, "cod" => 0, //1 for Cash on Delivery and 0 for Prepaid orders. "is_return" => 0, //Whether the order is return order or not. 1 in case of Yes and 0 for No "declared_value" => 200 //-----Total Price of Order ]; // $jayParsedAry = [ // "pickup_postcode" => $pickup_postcode, // "delivery_postcode" => $delivery_postcode, // "weight" => $weight, // "cod" => 0, // "is_return" => 0, // "declared_value" => $declared_value // ]; // echo "<pre>"; print_r($jayParsedAry); die(); $order_data = json_encode($jayParsedAry); /*----------------------------------*/ $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://apiv2.shiprocket.in/v1/external/courier/serviceability/', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_POSTFIELDS =>$order_data, CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "Authorization: Bearer $token" ), )); $response = curl_exec($curl); curl_close($curl); // echo $response; $res=json_decode($response); // return $res; // return $res->data->available_courier_companies; if ($res->status ==200) { // return $res->data->available_courier_companies[0]->freight_charge; return $res->data->available_courier_companies; }else{ return 0; } // return $res->data->available_courier_companies[0]->freight_charge; // echo "<pre>"; print_r($res); die(); } /*==================================*/ } ?>