-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Možnost stáhnout ukázkové PDF
- Loading branch information
Showing
3 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
include(__DIR__.'/config.php'); | ||
|
||
$vyfakturuj_api = new VyfakturujAPI(VYFAKTURUJ_API_LOGIN,VYFAKTURUJ_API_KEY); | ||
|
||
$opt = array( | ||
'customer_IC' => '123456789', | ||
'customer_DIC' => 'CZ123456789', | ||
'customer_name' => 'Ukázková Firma', | ||
'customer_street' => 'Pouliční 79/C', | ||
'customer_city' => 'Praha', | ||
'customer_zip' => '10300', | ||
'customer_country' => 'Česká republika', | ||
'items' => array( | ||
array( | ||
'text' => 'Stěrač na ponorku', | ||
'unit_price' => 990.25, | ||
'vat_rate' => 15, | ||
), | ||
array( | ||
'text' => 'Kapalina do ostřikovačů 250 ml', | ||
'unit_price' => 59, | ||
'vat_rate' => 15, | ||
), | ||
array( | ||
'text' => 'Doprava', | ||
'unit_price' => 0, | ||
'vat_rate' => 0, | ||
) | ||
) | ||
); | ||
|
||
$result = $vyfakturuj_api->test_invoice__asPdf($opt); | ||
|
||
echo '<h2>Nepodařilo se stáhnout PDF:</h2>'; | ||
echo '<pre>'.print_r($result,true).'</pre>'; | ||
|
||
|
||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Třída pro práci s API Vyfakturuj.cz | ||
* | ||
* @author Ing. Martin Dostál <[email protected]> | ||
* @version 2.1.2 | ||
* @version 2.1.3 | ||
*/ | ||
class VyfakturujAPI{ | ||
|
||
|
@@ -219,6 +219,32 @@ public function test(){ | |
return $this->_get('test/'); | ||
} | ||
|
||
/** | ||
* Test faktury v PDF. | ||
* Pošle data na server, vytvoří na serveru fakturu kterou ale neuloží a pošle zpět ve formátu PDF. | ||
* Pokud se podaří fakturu vytvořit, pak je poslána ve formátu PDF na výstup. Jinak je vráceno pole. | ||
* | ||
* @param array $data | ||
* @return array | ||
*/ | ||
public function test_invoice__asPdf($data){ | ||
$result = $this->_post('test/invoice/download/',$data); | ||
if(array_key_exists('content',$result)){ | ||
ob_end_clean(); | ||
$content = base64_decode($result['content']); | ||
header("Cache-Control: public"); | ||
$filename = $result['filename']; | ||
header("Content-Description: File Transfer"); | ||
header("Content-Disposition: attachment; filename=\"".$filename.".pdf\""); | ||
header('Content-type: application/pdf'); | ||
header("Content-Transfer-Encoding: binary"); | ||
header("Content-Length: ".strlen($content)); | ||
echo $content; | ||
exit; | ||
} | ||
return $result; | ||
} | ||
|
||
private function _connect($path,$method,$data = array()){ | ||
$curl = curl_init(); | ||
curl_setopt($curl,CURLOPT_URL,static::$URL.$path); | ||
|
@@ -246,6 +272,7 @@ private function _connect($path,$method,$data = array()){ | |
|
||
$response = curl_exec($curl); | ||
$this->lastInfo = curl_getinfo($curl); | ||
$this->lastInfo['dataSend'] = $data; | ||
curl_close($curl); | ||
|
||
$return = json_decode($response,true); | ||
|