private function send(Checkout $checkout) { $request = new Request(); $request->getHeaders()->addHeaders(array('Content-Type: application/xml; charset=ISO-8859-1')); $request->setUri($this->options->getWsUrl()); $request->setMethod(Request::METHOD_POST); $request->setContent($checkout->parseXML()); $client = new Client(); $response = $client->dispatch($request); if ($response->getBody() == 'Unauthorized') { throw new \Exception('Unauthorized access to PagSeguro'); } $xml = ''; try { $xml = simplexml_load_string($response->getBody()); } catch (\Exception $e) { throw new \Exception('Error on parse reponse xml. ' . $response->getBody(), 500, $e); } if ($xml->code) { return $xml->code; } throw new \Exception('An error has occurred: ' . $response->getBody()); }