public function execute()
{
// Set query data if there is any
if (count($this->fields) > 0) {
if ($this->isPost()) {
$this->setOption(CURLOPT_POSTFIELDS, $this->fields);
} else {
$url = $this->options[CURLOPT_URL] . '?' . http_build_query($this->fields);
$this->setOption(CURLOPT_URL, $url);
}
}
$this->response = curl_exec($this->curl);
if ($this->response === false) {
$this->showError();
}
// If the CURLOPT_RETURNTRANSFER option is set, get the response body and parse the headers.
if (isset($this->options[CURLOPT_RETURNTRANSFER]) && $this->options[CURLOPT_RETURNTRANSFER] == true) {
$this->headerSize = $this->getInfo(CURLINFO_HEADER_SIZE);
if ($this->options[CURLOPT_HEADER]) {
$this->header = substr($this->response, 0, $this->headerSize);
$this->body = substr($this->response, $this->headerSize);
$this->parseHeaders();
} else {
$this->body = $this->response;
}
}
return $this->response;
}
/** * Send transaction * * @param boolean $verifyPeer * @return void */ public function send($verifyPeer = true) { $this->buildRateRequest(); $options = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->accessRequest . $this->rateRequest, CURLOPT_HEADER => false); if (!$verifyPeer) { $options[CURLOPT_SSL_VERIFYPEER] = false; } $curl = new Curl($this->url, $options); $curl->execute(); $this->response = simplexml_load_string($curl->getBody()); $this->responseCode = (int) $this->response->Response->ResponseStatusCode; if ($this->responseCode == 1) { $this->responseMessage = (string) $this->response->Response->ResponseStatusDescription; foreach ($this->response->RatedShipment as $rate) { $this->rates[self::$services[(string) $rate->Service->Code]] = (string) $rate->TotalCharges->MonetaryValue; } } else { $this->responseCode = (string) $this->response->Response->Error->ErrorCode; $this->responseMessage = (string) $this->response->Response->Error->ErrorDescription; } }