forked from wes4m/zatca-xml-js
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsample.php
executable file
·118 lines (97 loc) · 4.27 KB
/
sample.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
use ZATCA\EGS;
const ROOT_PATH = __DIR__;
enum Mode
{
case Dev;
case Sim;
case Pro;
}
const STORAGE_PATH = ROOT_PATH . '/storage';
require ROOT_PATH . '/src/EGS.php';
require ROOT_PATH . '/src/InvoiceBuilder.php';
require ROOT_PATH . '/src/API.php';
require ROOT_PATH . '/src/Logger.php';
require ROOT_PATH . '/src/helpers/helper.php';
load_helpers('qr', 'invoice');
$line_item = [
'id' => '1',
'name' => 'قلم رصاص',
'quantity' => 1,
'tax_exclusive_price' => 10,
'VAT_percent' => 0.15,
'other_taxes' => [
//['percent_amount' => 0.5]
],
'discounts' => [
['amount' => 0, 'reason' => 'A discount'],
],
];
$egs_unit = [
'uuid' => EGS::uuid(),
'custom_id' => 'EGS1-886431145',
'model' => 'IOS',
'CRN_number' => 4031006635,
'VAT_name' => 'Jabbar Nasser Al-Bishi Co. W.L.L',
'VAT_number' => 399999999900003, // 310048293400003 399999999900003
'location' => [
'city' => 'Khobar',
'city_subdivision' => 'West',
'street' => 'الامير سلطان | Prince Sultan',
'plot_identification' => '0000',
'building' => '2322',
'postal_zone' => '23333',
],
'branch_name' => 'My Branch Name',
'branch_industry' => 'Food',
'cancelation' => [
'cancelation_type' => 'INVOICE',
'canceled_invoice_number' => 'SME00002',
],
'AccountingCustomerParty' => [
'__id' => 1010010000,
'__street_name' => 'الامير سلطان | Prince Sultan',
'__building_number' => '2322',
'__plotIdentification' => '0000',
'__city_subdivision_name' => 'West',
'__city_name' => 'Khobar',
'__postal_zone' => '23333',
'__company_id' => 301121965500003,
'__tax_scheme_id' => 'VAT',
'__registration_name' => 'Wesam Alzahir',
],
];
$invoice = [
'invoice_counter_number' => 23,
'invoice_serial_number' => 'SME00023',
'issue_date' => '2022-09-07',
'issue_time' => '12:21:28',
'previous_invoice_hash' => 'NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==', // AdditionalDocumentReference/PIH
'line_items' => [
$line_item,
],
];
$egs = new EGS($egs_unit, Mode::Dev);
// New Keys & CSR for the EGS
list($private_key, $csr) = $egs->generateNewKeysAndCSR('Jabbar Nasser Al-Bishi Co. W.L.L');
// Issue a new compliance cert for the EGS
list($request_id, $binary_security_token, $secret) = $egs->issueComplianceCertificate('272826', $csr);
// build invoice
list($invoice_string, $invoice_hash, $qr) = $egs->buildInvoice01_388($invoice, $egs_unit, $binary_security_token, $private_key);
$egs->checkInvoiceCompliance($invoice_string, $invoice_hash, $binary_security_token, $secret) . PHP_EOL;
list($invoice_string, $invoice_hash, $qr) = $egs->buildInvoice02_388($invoice, $egs_unit, $binary_security_token, $private_key);
$egs->checkInvoiceCompliance($invoice_string, $invoice_hash, $binary_security_token, $secret) . PHP_EOL;
invoice_write($invoice_string, 'invoice');
list($invoice_string, $invoice_hash, $qr) = $egs->buildInvoice01_381($invoice, $egs_unit, $binary_security_token, $private_key);
$egs->checkInvoiceCompliance($invoice_string, $invoice_hash, $binary_security_token, $secret) . PHP_EOL;
list($invoice_string, $invoice_hash, $qr) = $egs->buildInvoice02_381($invoice, $egs_unit, $binary_security_token, $private_key);
$egs->checkInvoiceCompliance($invoice_string, $invoice_hash, $binary_security_token, $secret) . PHP_EOL;
list($invoice_string, $invoice_hash, $qr) = $egs->buildInvoice01_383($invoice, $egs_unit, $binary_security_token, $private_key);
$egs->checkInvoiceCompliance($invoice_string, $invoice_hash, $binary_security_token, $secret) . PHP_EOL;
list($invoice_string, $invoice_hash, $qr) = $egs->buildInvoice02_383($invoice, $egs_unit, $binary_security_token, $private_key);
$egs->checkInvoiceCompliance($invoice_string, $invoice_hash, $binary_security_token, $secret) . PHP_EOL;
// Issue production certificate
list($pro_request_id, $pro_binary_security_token, $pro_secret) = $egs->issueProductionCertificate($binary_security_token, $secret, $request_id);
// var_dump($egs->productionCSIDRenewal($csr, '123456'));
print_r($egs->reportInvoice($invoice_string, $invoice_hash, $pro_binary_security_token, $pro_secret));
echo PHP_EOL;