forked from malcanek/iDoklad-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacf.php
45 lines (42 loc) · 1.76 KB
/
acf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include_once 'src/iDoklad.php';
use malcanek\iDoklad\iDoklad;
use malcanek\iDoklad\auth\iDokladCredentials;
use malcanek\iDoklad\iDokladException;
$clientId = 'Your client ID';
$clientSecret = 'Your client secret from developer portal';
$redirectUri = 'Your redirect URI from developer portal';
try{
$iDoklad = new iDoklad($clientId, $clientSecret, $redirectUri);
$iDoklad->setCredentialsCallback(function($credentials){
file_put_contents('credentials.json', $credentials->toJson());
});
if(!file_exists('credentials.json') && empty($_GET['code'])){
echo '<a href="'.$iDoklad->getAuthenticationUrl().'">Click</a>';
} else {
if(!empty($_GET['code'])){
$iDoklad->requestCredentials($_GET['code']);
} else {
$credentials = new iDokladCredentials(file_get_contents('credentials.json'), true);
$iDoklad->setCredentials($credentials);
}
$request = new \malcanek\iDoklad\request\iDokladRequest('IssuedInvoices');
$response = $iDoklad->sendRequest($request);
echo '<pre>';
print_r($response);
echo '</pre>';
}
} catch (iDokladException $ex) {
echo $ex->getMessage();
echo $ex->getTraceAsString();
}
?>
</body>
</html>