$value){ if(strpos(get_class($value),"SimpleXML")!==false){ $array[$key] = simpleXML2Array($value); } } return $array; } function geocode($address) { $httpAuthToken = '99dfe35fcb7de1ee'; // Call geocoding service $data = http_build_query( array( 'address' => $address, ) ); $url = "http://10.142.0.4/api/v1/geocode?" . $data; $opts = array( 'http' => array( 'method' => "GET", 'header' => "Content-Type: application/x-www-form-urlencoded\r\n" . "Accept: application/json\r\n" . "Authorization: Server-Token ${httpAuthToken}\r\n", ) ); $context = stream_context_create($opts); $body = file_get_contents($url, false, $context); $geocoded = json_decode($body,true); return $geocoded; } /* $json_params = file_get_contents("php://input"); if (strlen($json_params) <= 0 || !isValidJSON($json_params)) { http_response_code(400); echo json_encode([ "code" => 400, "error" => "Bad request" ]); exit(0); } $request = json_decode($json_params, true); */ //$_POST["originalAddress"] = "10 Amos Road, Sheffield, South Yorkshire, S9 1BX"; //$_POST["destinationAddress"] = "14 Aylesbury Crescent, Sheffield, South Yorkshire, S9 1JR"; if (isset($_POST["submit"])) { $xmlstr = << {{agent_password}} AgentRef USD Address 1563 Van Dyke Ave, San Francisco, CA 94124, USA 37.7286068 -122.3919092 Address 536 Edinburgh St, San Francisco, CA 94112, USA 37.7206606 -122.4326099 XML; $xmlstr = << {{agent_password}} AgentRef USD Address 1563 Van Dyke Ave, San Francisco, CA 94124, USA 37.7286068 -122.3919092 Address 536 Edinburgh St, San Francisco, CA 94112, USA 37.7206606 -122.4326099 XML; // $originalAddress = $_POST["originalAddress"];// || "10 Amos Road, Sheffield, South Yorkshire, S9 1BX"; // $originalLat = floatval($_POST["originalLat"]);// || 53.412535; // $originalLng = floatval($_POST["originalLng"]);// || -1.419525; // $destinationAddress = $_POST["destinationAddress"];// || "14 Aylesbury Crescent, Sheffield, South Yorkshire, S9 1JR"; // $destinationLat = floatval($_POST["destinationLat"]); // || 53.418405; // $destinationLng = floatval($_POST["destinationLng"]); // || -1.419225; $raw = false; if ($_POST["raw"]) { $raw = true; } $showRequestBody = false; if ($_POST["showRequest"]) { $showRequestBody = true; } // Check if name has been entered if (!$_POST['originalAddress']) { $errOriginalAddress = 'Please enter original address'; } else { $originalAddress = $_POST["originalAddress"];// || "10 Amos Road, Sheffield, South Yorkshire, S9 1BX"; $original = geocode($originalAddress); if (isset($original['error'])) { $errOriginalAddress = $original['error']; } else { $originalLat = $original["data"]["lat"]; $originalLng = $original["data"]["lng"]; } } if (!$_POST['destinationAddress']) { $errDestinationAddress = 'Please enter destination address'; } else { $destinationAddress = $_POST["destinationAddress"];// || "14 Aylesbury Crescent, Sheffield, South Yorkshire, S9 1JR"; $destination = geocode($destinationAddress); if (isset($destination['error'])) { $errDestinationAddress = $destination['error']; } else { $destinationLat = $destination["data"]["lat"]; $destinationLng = $destination["data"]["lng"]; } } if (!$errOriginalAddress && !$errDestinationAddress) { /* $originalAddress = "10 Amos Road, Sheffield, South Yorkshire, S9 1BX"; $originalLat = 53.412535; $originalLng = -1.419525; $destinationAddress = "14 Aylesbury Crescent, Sheffield, South Yorkshire, S9 1JR"; $destinationLat = 53.418405; $destinationLng = -1.419225;*/ $xml = new SimpleXMLElement($xmlstr); $xml->Agent->attributes()->Id = "20088"; //300999; $xml->Agent->Password = "BNyN3ee228MexQ3EzJfzOdb4"; //jEHjE5Kv; // $xml->Agent->attributes()->Id = "300999"; // $xml->Agent->Password = "jEHjE5Kv"; $xml->Agent->Time = date("Y-m-d\TH:i:s.v\Z"); $xml->BookingParameters->Journey->From->Data = $originalAddress; $xml->BookingParameters->Journey->From->Coordinate->Latitude = $originalLat; $xml->BookingParameters->Journey->From->Coordinate->Longitude = $originalLng; $xml->BookingParameters->Journey->To->Data = $destinationAddress; $xml->BookingParameters->Journey->To->Coordinate->Latitude = $destinationLat; $xml->BookingParameters->Journey->To->Coordinate->Longitude = $destinationLng; $postdata = $xml->asXML(); // $url="https://cxs.autocab.net/api/agent"; $url="https://cxs-staging.autocab.net/api/agent"; $curl = curl_init(); curl_setopt_array( $curl, array( CURLOPT_URL => $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 => $postdata, CURLOPT_HTTPHEADER => array( "Content-Type: text/xml" ), ) ); $response = curl_exec( $curl ); curl_close( $curl ); $xmlResponse = new SimpleXMLElement($response); $result = [ ]; if ((string)$xmlResponse->Result->Success == "true") { if ($raw) { $dom = new DOMDocument("1.0"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xmlResponse->asXML()); $result = $dom->saveXML(); $result = simpleXML2Array($xmlResponse); } else { $result["offers"] = []; array_push($result["offers"], [ "price" => (int)$xmlResponse->Pricing->Price, "estimatedJourney" => [ "distance" => (int) $xmlResponse->EstimatedJourney->Distance, "duration" => (int) $xmlResponse->EstimatedJourney->Duration, ], "vendor" => (string) $xmlResponse->VendorDetails->Name ]); /* foreach ($xmlResponse->Offers->Offer as $offer) { array_push($result["offers"], [ "price" => (int)$offer->Pricing->Price, "estimatedJourney" => [ "distance" => (int) $offer->EstimatedJourney->Distance, "duration" => (int) $offer->EstimatedJourney->Duration, ], "vendor" => (string) $offer->VendorDetails->Name ]); } */ } } else { $result["error"] = (string) $xmlResponse->Result->FailureReason; } $result = PHP_EOL.json_encode($result, JSON_PRETTY_PRINT); } } ?> Yellow Cab Offers

Yellow Cab Unit Test

Example: 1563 Van Dyke Ave, San Francisco, CA 94124 $errOriginalAddress

";?>
Example: 536 Edinburgh St, San Francisco, CA 94112 $errDestinationAddress

";?>

Result:

							saveXML()) : htmlentities($result); ?>
						

Request: