| @@ 88-107 (lines=20) @@ | ||
| 85 | * |
|
| 86 | * @return RateResponse |
|
| 87 | */ |
|
| 88 | protected function sendRequest(RateRequest $rateRequest) |
|
| 89 | { |
|
| 90 | $request = $this->createRequest($rateRequest); |
|
| 91 | ||
| 92 | $this->response = $this->getRequest()->request($this->createAccess(), $request, $this->compileEndpointUrl(self::ENDPOINT)); |
|
| 93 | $response = $this->response->getResponse(); |
|
| 94 | ||
| 95 | if (null === $response) { |
|
| 96 | throw new Exception('Failure (0): Unknown error', 0); |
|
| 97 | } |
|
| 98 | ||
| 99 | if ($response->Response->ResponseStatusCode == 0) { |
|
| 100 | throw new Exception( |
|
| 101 | "Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}", |
|
| 102 | (int)$response->Response->Error->ErrorCode |
|
| 103 | ); |
|
| 104 | } else { |
|
| 105 | return $this->formatResponse($response); |
|
| 106 | } |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Create the Rate request. |
|
| @@ 161-182 (lines=22) @@ | ||
| 158 | * @return stdClass |
|
| 159 | * @throws Exception |
|
| 160 | */ |
|
| 161 | private function getFormattedResponse() |
|
| 162 | { |
|
| 163 | $this->response = $this->getRequest()->request( |
|
| 164 | $this->createAccess(), |
|
| 165 | $this->createRequest(), |
|
| 166 | $this->compileEndpointUrl(self::ENDPOINT) |
|
| 167 | ); |
|
| 168 | $response = $this->response->getResponse(); |
|
| 169 | ||
| 170 | if (null === $response) { |
|
| 171 | throw new Exception('Failure (0): Unknown error', 0); |
|
| 172 | } |
|
| 173 | ||
| 174 | if ($response instanceof SimpleXMLElement && $response->Response->ResponseStatusCode == 0) { |
|
| 175 | throw new Exception( |
|
| 176 | "Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}", |
|
| 177 | (int)$response->Response->Error->ErrorCode |
|
| 178 | ); |
|
| 179 | } |
|
| 180 | ||
| 181 | return $this->formatResponse($response); |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * Check if tracking number is for mail innovations. |
|