-
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 uhradit doklad (fakturu) + Popora souvisejících dokladů (faktur) v odpovědích
- Loading branch information
Showing
3 changed files
with
87 additions
and
25 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,31 @@ | ||
<?php | ||
|
||
include(__DIR__.'/config.php'); | ||
|
||
$vyfakturuj_api = new VyfakturujAPI(VYFAKTURUJ_API_LOGIN,VYFAKTURUJ_API_KEY); | ||
|
||
|
||
|
||
|
||
# | ||
# | ||
#################################################################################### | ||
#################################################################################### | ||
##### ##### | ||
##### Uhrazení dokladu ##### | ||
##### ##### | ||
#################################################################################### | ||
#################################################################################### | ||
# | ||
# | ||
|
||
$_ID_DOKUMENTU = 54525; // zde zadejte ID dokladu, který chcete uhradit | ||
$_DATUM_UHRADY = '2016-07-25'; | ||
|
||
|
||
$res = $vyfakturuj_api->invoice_setPayment($_ID_DOKUMENTU,$_DATUM_UHRADY); // Získáme šablonu, co by se odeslalo | ||
|
||
echo '<h2>Doklad po uhrazení:</h2>'; | ||
echo '<pre>'.print_r($res,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,32 +4,33 @@ | |
* Třída pro práci s API Vyfakturuj.cz | ||
* | ||
* @author Ing. Martin Dostál <[email protected]> | ||
* @version 2.1.0 | ||
* @version 2.1.2 | ||
*/ | ||
class VyfakturujAPI{ | ||
|
||
protected $login = null; | ||
protected $apiHash = null; | ||
protected static $URL = 'https://www.vyfakturuj.cz/api/2.0/'; | ||
|
||
public function __construct($login,$apiHash){ | ||
$this->login = $login; | ||
$this->apiHash = $apiHash; | ||
} | ||
protected $lastInfo = null; | ||
|
||
const METHOD_POST = 'post', | ||
METHOD_GET = 'get', | ||
METHOD_DELETE = 'delete', | ||
METHOD_PUT = 'put'; | ||
|
||
public function __construct($login,$apiHash){ | ||
$this->login = $login; | ||
$this->apiHash = $apiHash; | ||
} | ||
|
||
/** | ||
* Vytvoření nového dokumentu | ||
* | ||
* @param array $data Data, která chceme použít při vytvoření. | ||
* @return array Vrátí kompletní informace o dokumentu | ||
*/ | ||
public function createInvoice($data){ | ||
return $this->_post('/invoice/',$data); | ||
return $this->_post('invoice/',$data); | ||
} | ||
|
||
/** | ||
|
@@ -40,7 +41,7 @@ public function createInvoice($data){ | |
* @return array Vrátí kompletní informace o dokumentu | ||
*/ | ||
public function updateInvoice($id,$data){ | ||
return $this->_put('/invoice/'.$id.'/',$data); | ||
return $this->_put('invoice/'.$id.'/',$data); | ||
} | ||
|
||
/** | ||
|
@@ -50,7 +51,7 @@ public function updateInvoice($id,$data){ | |
* @return array Vrátí kompletní informace o dokumentu | ||
*/ | ||
public function getInvoice($id){ | ||
return $this->_get('/invoice/'.$id.'/'); | ||
return $this->_get('invoice/'.$id.'/'); | ||
} | ||
|
||
/** | ||
|
@@ -59,7 +60,7 @@ public function getInvoice($id){ | |
* @return array | ||
*/ | ||
public function getInvoices(){ | ||
return $this->_get('/invoice/'); | ||
return $this->_get('invoice/'); | ||
} | ||
|
||
/** | ||
|
@@ -70,7 +71,7 @@ public function getInvoices(){ | |
*/ | ||
public function invoice_sendMail_test($id,$data){ | ||
$data['test'] = true; | ||
return $this->_post('/invoice/'.$id.'/send-mail/',$data); | ||
return $this->_post('invoice/'.$id.'/send-mail/',$data); | ||
} | ||
|
||
/** | ||
|
@@ -80,7 +81,23 @@ public function invoice_sendMail_test($id,$data){ | |
* @return array | ||
*/ | ||
public function invoice_sendMail($id,$data){ | ||
return $this->_post('/invoice/'.$id.'/send-mail/',$data); | ||
return $this->_post('invoice/'.$id.'/send-mail/',$data); | ||
} | ||
|
||
/** | ||
* Uhradí fakturu | ||
* | ||
* @param int $id id dokumentu | ||
* @param date $date Např: 2016-12-31, pokud je nastaveno na 0000-00-00 pak se zruší uhrada dokladu | ||
* @param int|float $amount Kolik bylo uhrazeno. Pokud je NULL, bude faktura uhrazena nezávisle na částce | ||
* @return array Detail dokladu po uhrazeni | ||
*/ | ||
public function invoice_setPayment($id,$date,$amount = null){ | ||
$data = array('date' => $date); | ||
if(!is_null($amount)){ | ||
$data['amount'] = $amount; | ||
} | ||
return $this->_post('invoice/'.$id.'/payment/',$data); | ||
} | ||
|
||
/** | ||
|
@@ -90,7 +107,7 @@ public function invoice_sendMail($id,$data){ | |
* @return array Vrátí stav operace | ||
*/ | ||
public function deleteInvoice($id){ | ||
return $this->_delete('/invoice/'.$id.'/'); | ||
return $this->_delete('invoice/'.$id.'/'); | ||
} | ||
|
||
/** | ||
|
@@ -100,7 +117,7 @@ public function deleteInvoice($id){ | |
* @return array Vrátí kompletní informace o kontaktu | ||
*/ | ||
public function createContact($data){ | ||
return $this->_post('/contact/',$data); | ||
return $this->_post('contact/',$data); | ||
} | ||
|
||
/** | ||
|
@@ -111,7 +128,7 @@ public function createContact($data){ | |
* @return array Vrátí kompletní informace o kontaktu | ||
*/ | ||
public function updateContact($id,$data){ | ||
return $this->_put('/contact/'.$id.'/',$data); | ||
return $this->_put('contact/'.$id.'/',$data); | ||
} | ||
|
||
/** | ||
|
@@ -121,7 +138,7 @@ public function updateContact($id,$data){ | |
* @return array Vrátí kompletní informace o kontaktu | ||
*/ | ||
public function getContact($id){ | ||
return $this->_get('/contact/'.$id.'/'); | ||
return $this->_get('contact/'.$id.'/'); | ||
} | ||
|
||
/** | ||
|
@@ -130,7 +147,7 @@ public function getContact($id){ | |
* @return array | ||
*/ | ||
public function getContacts(){ | ||
return $this->_get('/contact/'); | ||
return $this->_get('contact/'); | ||
} | ||
|
||
/** | ||
|
@@ -140,7 +157,7 @@ public function getContacts(){ | |
* @return array Vrátí stav operace | ||
*/ | ||
public function deleteContact($id){ | ||
return $this->_delete('/contact/'.$id.'/'); | ||
return $this->_delete('contact/'.$id.'/'); | ||
} | ||
|
||
/** | ||
|
@@ -150,7 +167,7 @@ public function deleteContact($id){ | |
* @return array Vrátí kompletní informace o položce | ||
*/ | ||
public function createTemplate($data){ | ||
return $this->_post('/template/',$data); | ||
return $this->_post('template/',$data); | ||
} | ||
|
||
/** | ||
|
@@ -161,7 +178,7 @@ public function createTemplate($data){ | |
* @return array Vrátí kompletní informace o položce | ||
*/ | ||
public function updateTemplate($id,$data){ | ||
return $this->_put('/template/'.$id.'/',$data); | ||
return $this->_put('template/'.$id.'/',$data); | ||
} | ||
|
||
/** | ||
|
@@ -171,7 +188,7 @@ public function updateTemplate($id,$data){ | |
* @return array Vrátí kompletní informace | ||
*/ | ||
public function getTemplate($id){ | ||
return $this->_get('/template/'.$id.'/'); | ||
return $this->_get('template/'.$id.'/'); | ||
} | ||
|
||
/** | ||
|
@@ -180,7 +197,7 @@ public function getTemplate($id){ | |
* @return array | ||
*/ | ||
public function getTemplates(){ | ||
return $this->_get('/template/'); | ||
return $this->_get('template/'); | ||
} | ||
|
||
/** | ||
|
@@ -190,7 +207,7 @@ public function getTemplates(){ | |
* @return array Vrátí stav operace | ||
*/ | ||
public function deleteTemplate($id){ | ||
return $this->_delete('/template/'.$id.'/'); | ||
return $this->_delete('template/'.$id.'/'); | ||
} | ||
|
||
/** | ||
|
@@ -199,7 +216,7 @@ public function deleteTemplate($id){ | |
* @return array | ||
*/ | ||
public function test(){ | ||
return $this->_get('/test/'); | ||
return $this->_get('test/'); | ||
} | ||
|
||
private function _connect($path,$method,$data = array()){ | ||
|
@@ -228,13 +245,21 @@ private function _connect($path,$method,$data = array()){ | |
} | ||
|
||
$response = curl_exec($curl); | ||
// $info = curl_getinfo($curl); | ||
$this->lastInfo = curl_getinfo($curl); | ||
curl_close($curl); | ||
|
||
$return = json_decode($response,true); | ||
return $return ? $return : $response; | ||
} | ||
|
||
/** | ||
* Vrati informace o poslednim spojeni | ||
* @return array|null | ||
*/ | ||
public function getInfo(){ | ||
return $this->lastInfo; | ||
} | ||
|
||
private function _get($path,$data = null){ | ||
return $this->_connect($path,self::METHOD_GET,$data); | ||
} | ||
|