/** * Get Transaction Status * @param string $code * @param CredentialsInterface $credential * @return array|boolean Array with transaction info or FALSE on failure */ public function getStatus($code, CredentialsInterface $credential) { $url = $this->getUrlTo('transactions'); $completeUrl = "{$url}/{$code}"; $request = $this->getRequest(); $credentialData = $this->getCredentialData($credential); $response = $request->get($completeUrl, $credentialData); if (!$response) { throw new \RuntimeException('Transaction check failure'); } $body = $response->getRawBody(); if ($response->getHttpStatus() !== 200) { $error = 'Error on getStatus: ' . $response->getHttpStatus() . '-' . $body; throw new \RuntimeException($error); } $parser = new Xml($body); return $parser->toArray(); }
/** * Send Checkout * @param CheckoutInterface $checkout * @param CredentialsInterface $credential * @return array|boolean Array with transaction info or FALSE on failure */ public function send(CheckoutInterface $checkout, CredentialsInterface $credential) { $url = $this->getUrlTo('checkout'); $request = $this->getRequest(); $this->prepareStatement($checkout, $request); $credentialData = $this->getCredentialData($credential); $response = $request->post($url, $credentialData); if (!$response) { throw new \RuntimeException('Checkout send failure'); } $body = $response->getRawBody(); if ($response->getHttpStatus() !== 200) { $error = 'Error on send: ' . $response->getHttpStatus() . '-' . $body; throw new \RuntimeException($error); } $parser = new Xml($body); $data = $parser->toArray(); if (array_key_exists('code', $data)) { $paymentUrl = str_replace('ws.', '', $url) . '/payment.html?code='; $data['link'] = $paymentUrl . $data['code']; } return $data; }
public function testOneItemParse() { $str = $this->getOneItemTest(); $xml = new Xml($str); $this->assertEquals(['items' => ['item' => ['id' => '0002', 'description' => 'Notebook']]], $xml->toArray()); }