Skip to content

Commit a1a0184

Browse files
committed
Add GoodTaxes::getTaxesByCode() and update README file.
1 parent 29cf206 commit a1a0184

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ $receipt = new \DigitSoft\Checkbox\Models\Receipts\SellReceipt(
275275
)
276276
]
277277
),
278-
'admin@gmail.com', // кому надсилати чек на пошту
278+
new \DigitSoft\Checkbox\Models\Receipts\Delivery(['admin@gmail.com']), // кому надсилати чек на пошту
279279
new \DigitSoft\Checkbox\Models\Receipts\Payments\Payments([
280280
new \DigitSoft\Checkbox\Models\Receipts\Payments\CardPaymentPayload( // безготівкова оплата
281281
40 * 100 // 40 грн
@@ -336,7 +336,7 @@ $receipt = new \DigitSoft\Checkbox\Models\Receipts\SellReceipt(
336336
)
337337
]
338338
),
339-
'admin@example.com', // кому надсилати чек на пошту
339+
new \DigitSoft\Checkbox\Models\Receipts\Delivery(['admin@gmail.com']), // кому надсилати чек на пошту
340340
new \DigitSoft\Checkbox\Models\Receipts\Payments\Payments([ // оплати
341341
new \DigitSoft\Checkbox\Models\Receipts\Payments\CardPaymentPayload( // безготівкова оплата
342342
400, // сума оплати 400 = 4 грн
@@ -372,7 +372,7 @@ $saleReceiptResult = $api->receipts()->createSell($receipt): \DigitSoft\Checkbox
372372
```php
373373
$allTaxes = $api->taxes()->all();
374374
$tax = $allTaxes->getTaxByLabel('Акцизний збір');
375-
$goodTaxes = $allTaxes->getTaxesByLabel('ПДВ');
375+
$goodTaxes = $allTaxes->getTaxesByCode('1'); // ПДВ 20%
376376
$taxCodes = [];
377377

378378
foreach ($goodTaxes->results as $goodTax) {
@@ -444,7 +444,7 @@ $receipt = new \DigitSoft\Checkbox\Models\Receipts\SellReceipt(
444444
)
445445
]
446446
),
447-
'admin@gmail.com',
447+
new \DigitSoft\Checkbox\Models\Receipts\Delivery(['admin@gmail.com']),
448448
new \DigitSoft\Checkbox\Models\Receipts\Payments\Payments([
449449
new \DigitSoft\Checkbox\Models\Receipts\Payments\CardPaymentPayload(
450450
4700
@@ -547,6 +547,7 @@ use DigitSoft\Checkbox\Models\Receipts\Goods\GoodModel;
547547
use DigitSoft\Checkbox\Models\Receipts\Goods\GoodItemModel;
548548
use DigitSoft\Checkbox\Models\Receipts\SellReceipt;
549549
use DigitSoft\Checkbox\Models\Receipts\ServiceReceipt;
550+
use DigitSoft\Checkbox\Models\Receipts\Delivery;
550551

551552
use DigitSoft\Checkbox\Models\Receipts\Payments\Payments;
552553
use DigitSoft\Checkbox\Models\Receipts\Payments\CardPaymentPayload;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "PHP SDK for integration with checkbox.ua API",
44
"type": "library",
55
"license": "MIT",
6-
"version": "0.2.2",
6+
"version": "0.2.3",
77
"authors": [
88
{
99
"name": "Digit",

src/Models/Receipts/Taxes/GoodTaxes.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public function __construct(array $taxes)
2424
}
2525
}
2626

27+
/**
28+
* Retrieve one tax by `label`.
29+
*
30+
* @param string $label
31+
* @return \DigitSoft\Checkbox\Models\Receipts\Taxes\GoodTax|null
32+
*/
2733
public function getTaxByLabel(string $label): ?GoodTax
2834
{
2935
foreach ($this->results as $tax) {
@@ -35,6 +41,13 @@ public function getTaxByLabel(string $label): ?GoodTax
3541
return null;
3642
}
3743

44+
/**
45+
* Retrieve taxes by `label`.
46+
*
47+
* @param string $label
48+
* @return \DigitSoft\Checkbox\Models\Receipts\Taxes\GoodTaxes|null
49+
* @throws \Exception
50+
*/
3851
public function getTaxesByLabel(string $label): ?GoodTaxes
3952
{
4053
$taxesArr = [];
@@ -47,4 +60,35 @@ public function getTaxesByLabel(string $label): ?GoodTaxes
4760

4861
return new GoodTaxes($taxesArr);
4962
}
63+
64+
/**
65+
* Retrieve one tax by `code`.
66+
*
67+
* @param string $code
68+
* @return \DigitSoft\Checkbox\Models\Receipts\Taxes\GoodTax|null
69+
*/
70+
public function getTaxByCode(string $code): ?GoodTax
71+
{
72+
foreach ($this->results as $tax) {
73+
if ($tax->code === $code) {
74+
return $tax;
75+
}
76+
}
77+
78+
return null;
79+
}
80+
81+
/**
82+
* Retrieve taxes by `code`.
83+
*
84+
* @param string $code
85+
* @return \DigitSoft\Checkbox\Models\Receipts\Taxes\GoodTaxes
86+
* @throws \Exception
87+
*/
88+
public function getTaxesByCode(string $code): GoodTaxes
89+
{
90+
$taxes = array_filter($this->results, fn (GoodTax $tax) => $tax->code === $code);
91+
92+
return new GoodTaxes(array_values($taxes));
93+
}
5094
}

0 commit comments

Comments
 (0)