View file File name : insta_order_webhooks_oms_update.php Content :<?php //ini_set('display_errors', 1); //error_reporting(E_ALL); //Method to update Instacart An order was accepted in the quicklly OMS function partner_order_accepted($ic_order_id,$partner_order_id,$ticket_number="",$ready_at="",$obj="") { $icEndPoint = IC_ENDPOINT_URL; $postPayload = [ "event_type" => "partner_order_accepted", "order_id"=> $ic_order_id, "partner_order_id" => $partner_order_id, "ticket_number"=> $ticket_number, //optional if it requires a different ID to show when picking up. Defaults to partner_order_id "ready_at"=> $ready_at, //optional if ready_at time provided from partner. Defaults to current time ]; //Get Instacart access token $tokenResp = json_decode(getICAccessToken($obj)); $headers = array( 'Content-Type: application/json', 'Authorization: Bearer '.$tokenResp->access_token, ); $ch = curl_init($icEndPoint); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postPayload)); $response = curl_exec($ch); $body= json_encode( $postPayload ); $jsResp = json_encode($response); $reqIP= $_SERVER['REMOTE_ADDR']; $QCToken = $headers; $reqServerLog = $_SERVER; $reqLog = json_encode($reqServerLog); $reqHeaderJsn = json_encode($QCToken); $ic_re_log = " INSERT INTO tbl_ic_request_log set re_serve_log='$reqHeaderJsn', re_body='$reqLog' ,ic_webhook_pay_load='$body',QC_Resp='$jsResp', Created_date=now(),request_frm='$reqIP'; "; $saveICReq = $obj->query($ic_re_log); return $response; } /*$ic_order_id='291089022'; $partner_order_id='1'; $resp = partner_order_accepted($ic_order_id,$partner_order_id); $icResponse = json_decode($resp); echo "==output=accept=".'<pre>'; print_r($icResponse);*/ //Method to update Instacart An order was rejected in the quicklly OMS function partner_order_rejected($ic_order_id,$partner_order_id,$reason="",$obj="") { $icEndPoint = IC_ENDPOINT_URL; $postPayload = [ "event_type" => "partner_order_rejected", "order_id"=> $ic_order_id, "partner_order_id" => $partner_order_id, // if exists "reason"=> $reason, //optional reason why order was rejected for logs ]; //Get Instacart access token $tokenResp = json_decode(getICAccessToken($obj)); $headers = array( 'Content-Type: application/json', 'Authorization: Bearer '.$tokenResp->access_token, ); $ch = curl_init($icEndPoint); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postPayload)); $response = curl_exec($ch); $body= json_encode( $postPayload ); $jsResp = json_encode( $response ); $reqIP= $_SERVER['REMOTE_ADDR']; $QCToken = $headers; $reqServerLog = $_SERVER; $reqLog = json_encode($reqServerLog); $reqHeaderJsn = json_encode($QCToken); $ic_re_log = " INSERT INTO tbl_ic_request_log set re_serve_log='$reqHeaderJsn', re_body='$reqLog' ,ic_webhook_pay_load='$body',QC_Resp='$jsResp', Created_date=now(),request_frm='$reqIP'; "; $saveICReq = $obj->query($ic_re_log); return $response; } //Method to update Instacart An order was canceled in the OMS. The event might include the reason why the order was canceled. function partner_order_canceled($ic_order_id,$partner_order_id,$reason="",$obj="") { $icEndPoint = IC_ENDPOINT_URL; $postPayload = [ "event_type" => "partner_order_canceled", "order_id"=> $ic_order_id, "partner_order_id" => $partner_order_id, // if exists "reason"=> $reason, //optional reason why order was rejected for logs ]; //Get Instacart access token $tokenResp = json_decode(getICAccessToken($obj)); $headers = array( 'Content-Type: application/json', 'Authorization: Bearer '.$tokenResp->access_token, ); $ch = curl_init($icEndPoint); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postPayload)); $response = curl_exec($ch); $body= json_encode( $postPayload ); $jsResp = json_encode( $response ); $reqIP= $_SERVER['REMOTE_ADDR']; $QCToken = $headers; $reqServerLog = $_SERVER; $reqLog = json_encode($reqServerLog); $reqHeaderJsn = json_encode($QCToken); $ic_re_log = " INSERT INTO tbl_ic_request_log set re_serve_log='$reqHeaderJsn', re_body='$reqLog' ,ic_webhook_pay_load='$body',QC_Resp='$jsResp', Created_date=now(),request_frm='$reqIP'; "; $saveICReq = $obj->query($ic_re_log); return $response; } //Method to update Instacart (An order changed status or items were updated in the OMS. The status field is required. //The other fields are required under certain conditions.) function partner_order_update($ic_order_id,$partner_order_id,$obj="") { //echo "<pre>";print_r(orderItemInfo($ic_order_id));die; $order_update = orderItemInfo($ic_order_id); $icEndPoint = IC_ENDPOINT_URL; $postPayload = [ "event_type" => "partner_order_update", "order_id"=> $ic_order_id, "partner_order_id" => $partner_order_id, // if exists "order_update"=> $order_update, ]; //Get Instacart access token $tokenResp = json_decode(getICAccessToken($obj)); $headers = array( 'Content-Type: application/json', 'Authorization: Bearer '.$tokenResp->access_token, ); //echo "<pre>";print_r(json_encode($postPayload));die;exit; $ch = curl_init($icEndPoint); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postPayload)); $response = curl_exec($ch); $body= json_encode( $postPayload ); $jsResp = json_encode( $response ); $reqIP= $_SERVER['REMOTE_ADDR']; $QCToken = $headers; $reqServerLog = $_SERVER; $reqLog = json_encode($reqServerLog); $reqHeaderJsn = json_encode($QCToken); $ic_re_log = " INSERT INTO tbl_ic_request_log set re_serve_log='$reqHeaderJsn', re_body='$reqLog' ,ic_webhook_pay_load='$body',QC_Resp='$jsResp', Created_date=now(),request_frm='$reqIP'; "; $saveICReq = $obj->query($ic_re_log); return $response; } function getICAccessToken($obj="") { $curl = curl_init(IC_AUTH_URL); $reqBody = array('client_id' => IC_CLIENT_ID, 'client_secret' => IC_CLIENT_SECRET, 'grant_type' => 'client_credentials', 'Accept' => 'application/json', 'Content-Type' => 'application/json' ); curl_setopt_array( $curl, array( CURLOPT_URL => IC_AUTH_URL, 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 => $reqBody, CURLOPT_HTTPHEADER => array('Accept'=> 'application/json', 'Content-Type'=> 'application/json', //'Cookie: _mkra_stck=6589db80d9f5793024fa799a27ef05a8%3A1634578360.6540024', ) ) ); $response = curl_exec($curl); $body = json_encode( $reqBody ); //$jsResp = json_encode( $response ); //$ic_re_log = " INSERT INTO tbl_ic_request_log set re_body='$body',QC_Resp='$jsResp' , Created_date=now(); "; //$saveICReq = $obj->query($ic_re_log); curl_close($curl); return $response; } //Cumin club order cancel API function cumin_order_canceled($qc_order_id,$obj="",$orderFrom='') { $curl = curl_init(); //$qc_order_id = 'QDTS73056'; curl_setopt_array($curl, array( CURLOPT_URL => 'https://app.thecuminclub.com/quickllyordercancel?quicklly_order_id='.$qc_order_id, 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', )); $response = curl_exec($curl); $respArr = json_decode($response); //echo "<pre>";print_r($respArr); //echo $respArr->status; curl_close($curl); $response = curl_exec($curl); $body= json_encode( $postPayload ); $jsResp = json_encode( $response ); $reqIP= $_SERVER['REMOTE_ADDR']; //$QCToken = $headers; $reqServerLog = $_SERVER; $reqLog = json_encode($reqServerLog); $reqHeaderJsn = json_encode($QCToken); $ic_re_log = " INSERT INTO tbl_ic_request_log set re_serve_log='$reqHeaderJsn', re_body='$reqLog' ,ic_webhook_pay_load='$body',QC_Resp='$jsResp', Created_date=now(),request_frm='$reqIP'; "; $saveICReq = $obj->query($ic_re_log); if($orderFrom='INSTA'){ $item_sql="UPDATE insta_order_itmes SET order_status='7' WHERE partner_order_id='$qc_order_id' AND storeid=108 AND section=2"; } $updateData = $obj->query($item_sql); if($orderFrom='QUICKLLY'){ $item_sql="UPDATE tbl_order SET order_status='5' WHERE id='$qc_order_id' "; $updateData = $obj->query($item_sql); } return $respArr->status; } ?>