Example #1
0
 /**
  * @return Response
  * @throws \Exception
  */
 public function send()
 {
     $this->xmlStr = self::generateXML();
     $ch = curl_init();
     //initiate the curl session
     curl_setopt($ch, CURLOPT_TIMEOUT, 40);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_URL, 'https://' . $this->ADRIPAddress . ":" . $this->ADRPort);
     //set to url to post to
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // tell curl to return data in a variable;
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, 'OrderXml=' . $this->xmlStr);
     // post the xml
     $xmlResponse = curl_exec($ch);
     if (!$xmlResponse) {
         throw new \Exception('Unable to connect to ADR: ' . curl_error($ch));
     }
     curl_close($ch);
     $response = new Response();
     $response->loadXML($xmlResponse);
     $response->parse();
     //Let's check for any errors
     if ($response->getError() != '0') {
         throw new \Exception('ADR ERROR: ' . $response->getError() . ' ' . $response->getErrorDescription() . PHP_EOL);
     }
     return $response;
 }