/** * Execute the request to get the ebook binary string, in case of success, the file * will be outputed and forced to download. * @throws Exception */ public function download() { // GENERATE THE CURL HANDLER $request = new Server\Request(Server\Config\SysConfig::$BASE_CONNECT_URI . Server\Config\SysConfig::$BASE_DOWNLOAD . 'get.php', $this->verbose); $request->authenticate(false); $request->create(); $request->setPost($this->data); try { // SEND IT, IF OKAY, THE __TOSTRING WILL BE THE EBOOK BINARY STRING $request->execute(); } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode()); } // SET THE HEADERS, IF YOU WANT TO PUT ANOTHER NAME TO THE FILE, // HERE IS THE PLACE if (!$this->verbose) { if (!strpos($request->__toString(), "urn:uuid:")) { header('Content-Type: application/epub+zip'); header('Content-Disposition: attachment; filename="' . md5(time()) . '.epub"'); } else { header('Content-Type: application/vnd.adobe.adept+xml'); header('Content-Disposition: attachment; filename="' . md5(time()) . '.acsm"'); } header("Content-Transfer-Encoding: binary"); header('Expires: 0'); header('Pragma: no-cache'); header("Content-Length: " . strlen($request)); // EXIT THE PROGRAM WITH THE BINARY REQUEST. $request = utf8_decode($request->__toString()); exit($request); } }
/** * Execute the checkout of the purchase, indicate to us that you have already recived the "okay" * from the payment gateway and already had inserted this same transaction_key to your database. * @param $transactionKey * @param $transactionTime * * @return mixed * @throws Exception */ public function checkout($transactionKey, $transactionTime) { // SET THE DATA TO BE SENT $this->data = $this->customer; $this->data['transactionKey'] = $transactionKey; $this->data['saleDate'] = date('Y-m-d H:i:s', $transactionTime); $this->data['items'] = $this->items; // LOGIN ON OAUTH SERVER $this->autenticate(); // SEND THE REQUEST TO THE CHECKOUT $request = new Server\Request(Server\Config\SysConfig::$BASE_CONNECT_URI . Server\Config\SysConfig::$BASE_PURCHASE . 'purchase.php', $this->verbose); $request->authenticate(false); $request->create(); $request->setPost($this->data); return $request->execute(); }
/** * Get the XML STRING from our server, we do not handle the XML data, only output this * string, YOU MUST HANDLE THIS AND INSERT INTO YOUR DATABASE, see the manual if needed. * * @return String // ONIX XML STRING * @throws Exception */ public function get() { // GENERATE THE CURL HANDLER $request = new Server\Request(Server\Config\SysConfig::$BASE_CONNECT_URI . Server\Config\SysConfig::$BASE_DOWNLOAD . 'list.php', $this->verbose); $request->authenticate(false); $request->create(); // IF HAS FILTERS, ADD THEN TO THE POST if (isset($this->filter)) { $this->data['filter']['items'] = $this->filter; } $request->setPost($this->data); try { // SEND IT, IF OKAY, THE __TOSTRING WILL BE THE ONIX XML RESPONSE $request->execute(); } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode()); } return $request->__toString(); }