forked from johnzuk/GusApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFromNip.php
90 lines (67 loc) · 2.55 KB
/
getFromNip.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
error_reporting(E_ALL);
require_once '../vendor/autoload.php';
session_start();
use GusApi\GusApi;
use GusApi\RegonConstantsInterface;
use GusApi\Exception\InvalidUserKeyException;
$key = 'abcde12345abcde12345'; // <--- your user key / twój klucz użytkownika
$gus = new GusApi(
$key,
new \GusApi\Adapter\Soap\SoapAdapter(
RegonConstantsInterface::BASE_WSDL_URL_TEST,
RegonConstantsInterface::BASE_WSDL_ADDRESS_TEST //<--- production server / serwer produkcyjny
//for test serwer use RegonConstantsInterface::BASE_WSDL_ADDRESS_TEST
//w przypadku serwera testowego użyj: RegonConstantsInterface::BASE_WSDL_ADDRESS_TEST
)
);
if (isset($_GET['reset'])) {
$_SESSION = [];
$_SESSION['checked'] = false;
}
if ($gus->serviceStatus() === RegonConstantsInterface::SERVICE_AVAILABLE) {
try {
if (!isset($_SESSION['sid']) || !$gus->isLogged($_SESSION['sid'])) {
$_SESSION['sid'] = $gus->login();
}
printNipForm();
if (isset($_POST['nip'])) {
$nip = $_POST['nip'];
try {
$gusReports = $gus->getByNip($_SESSION['sid'], $nip);
var_dump($gusReports);
$mapper = new \GusApi\ReportTypeMapper();
foreach ($gusReports as $gusReport) {
$reportType = $mapper->getReportType($gusReport);
var_dump($gus->getFullReport(
$_SESSION['sid'],
$gusReport,
$reportType
));
echo $gusReport->getName();
}
} catch (\GusApi\Exception\NotFoundException $e) {
echo 'No data found <br>';
echo 'For more information read server message belowe: <br>';
echo $gus->getResultSearchMessage($_SESSION['sid']);
}
}
} catch (InvalidUserKeyException $e) {
echo 'Bad user key!';
}
} else if ($gus->serviceStatus() === RegonConstantsInterface::SERVICE_UNAVAILABLE) {
echo 'Server is unavailable now. Please try again later <br>';
echo 'For more information read server message belowe: <br>';
echo $gus->serviceMessage();
} else {
echo 'Server technical break. Please try again later <br>';
echo 'For more information read server message belowe: <br>';
echo $gus->serviceMessage();
}
function printNipForm()
{
echo '<form action="" method="POST">';
echo '<input type="text" name="nip" >';
echo '<input type="submit" value="check">';
echo '</form>';
}