Skip to content

Commit

Permalink
API 2.1.2
Browse files Browse the repository at this point in the history
+ Možnost uhradit doklad (fakturu)
+ Popora souvisejících dokladů (faktur) v odpovědích
  • Loading branch information
Dosty85 committed Sep 14, 2016
1 parent 86255fd commit d2032e7
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 25 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ Příhlady API napojení na aplikaci Vyfakturuj.cz v programovacím jazyce PHP
4. V souboru /examples/3-contact.php se nachází ukázka, jak vytvářet, updatovat, získávat a mazat kontakty
5. V souboru /examples/4-template.php se nachází ukázka, jak vytvářet, updatovat, získávat a mazat pravidelné faktury a šablony
6. V souboru /examples/5-invoice-sendMail.php se nachází ukázka, jak odeslat e-mail s fakturou
7. V souboru /examples/6-invoice-setPayment se nachází ukázka, jak provést uhrazení faktury


## Changelog

### Verze 2.1.2

+ Možnost uhradit doklad (fakturu)
+ Popora souvisejících dokladů (faktur) v odpovědích

### Verze 2.1.1

+ Možnost odeslat fakturu e-mailem přes API
Expand Down
31 changes: 31 additions & 0 deletions examples/6-invoice-setPayment.php
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;
75 changes: 50 additions & 25 deletions libs/VyfakturujAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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.'/');
}

/**
Expand All @@ -59,7 +60,7 @@ public function getInvoice($id){
* @return array
*/
public function getInvoices(){
return $this->_get('/invoice/');
return $this->_get('invoice/');
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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.'/');
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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.'/');
}

/**
Expand All @@ -130,7 +147,7 @@ public function getContact($id){
* @return array
*/
public function getContacts(){
return $this->_get('/contact/');
return $this->_get('contact/');
}

/**
Expand All @@ -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.'/');
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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.'/');
}

/**
Expand All @@ -180,7 +197,7 @@ public function getTemplate($id){
* @return array
*/
public function getTemplates(){
return $this->_get('/template/');
return $this->_get('template/');
}

/**
Expand All @@ -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.'/');
}

/**
Expand All @@ -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()){
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit d2032e7

Please sign in to comment.