Skip to content

Commit b5635bf

Browse files
authored
Merge pull request #34 from MakarovIgor/master
Change delivery
2 parents c36ef39 + 4bf9a40 commit b5635bf

File tree

6 files changed

+79
-24
lines changed

6 files changed

+79
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ nbproject/*
77
index.php
88
/build/logs/*
99
.phpunit.result.cache
10+
test.php
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace igorbunov\Checkbox\Mappers\Receipts;
4+
5+
use igorbunov\Checkbox\Models\Receipts\Delivery;
6+
7+
class DeliveryMapper
8+
{
9+
/**
10+
* @param Delivery $delivery
11+
* @return array<string, mixed>
12+
*/
13+
public function objectToJson(Delivery $delivery): array
14+
{
15+
$output = [];
16+
17+
if (!empty($delivery->emails())) {
18+
$output['emails'] = $delivery->emails();
19+
}
20+
21+
if (!empty($delivery->phone())) {
22+
$output['phone'] = $delivery->phone();
23+
}
24+
25+
return $output;
26+
}
27+
}

src/Mappers/Receipts/SellReceiptMapper.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,11 @@ class SellReceiptMapper
1515
*/
1616
public function objectToJson(SellReceipt $receipt): array
1717
{
18-
$delivery = [];
19-
20-
if (!empty($receipt->deliveryEmail)) {
21-
$delivery['email'] = $receipt->deliveryEmail;
22-
}
23-
24-
if (!empty($receipt->deliveryPhone)) {
25-
$delivery['phone'] = $receipt->deliveryPhone;
26-
}
27-
2818
$output = [
2919
'cashier_name' => $receipt->cashier_name,
3020
'departament' => $receipt->departament,
3121
'goods' => (new GoodsMapper())->objectToJson($receipt->goods),
32-
'delivery' => $delivery,
22+
'delivery' => (new DeliveryMapper())->objectToJson($receipt->delivery),
3323
'discounts' => (new DiscountsMapper())->objectToJson($receipt->discounts),
3424
'payments' => (new PaymentsMapper())->objectToJson($receipt->payments),
3525
'header' => $receipt->header,

src/Models/Receipts/Delivery.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace igorbunov\Checkbox\Models\Receipts;
4+
5+
class Delivery
6+
{
7+
/** @var string $phone */
8+
private string $phone;
9+
/** @var array<string> $emails */
10+
private array $emails;
11+
12+
/**
13+
* Constructor
14+
*
15+
* @param array<string> $emails
16+
* @param string $phone
17+
*
18+
*/
19+
public function __construct(array $emails = [], string $phone = '')
20+
{
21+
$this->phone = $phone;
22+
$this->emails = $emails;
23+
}
24+
25+
/**
26+
* @return string[]
27+
*/
28+
public function emails(): array
29+
{
30+
return $this->emails;
31+
}
32+
33+
/**
34+
* @return string
35+
*/
36+
public function phone(): string
37+
{
38+
return $this->phone;
39+
}
40+
}

src/Models/Receipts/SellReceipt.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ class SellReceipt
1414
public $departament;
1515
/** @var Goods $goods */
1616
public $goods;
17-
/** @var string $deliveryEmail */
18-
public $deliveryEmail;
19-
/** @var string $deliveryPhone */
20-
public $deliveryPhone;
17+
/** @var Delivery $delivery */
18+
public Delivery $delivery;
2119
/** @var Discounts|null $discounts */
2220
public $discounts;
2321
/** @var Payments $payments */
@@ -40,21 +38,19 @@ public function __construct(
4038
string $cashier_name,
4139
string $departament,
4240
Goods $goods,
43-
string $deliveryEmail,
41+
Delivery $delivery,
4442
Payments $payments,
4543
?Discounts $discounts = null,
4644
string $header = '',
4745
string $footer = '',
4846
string $barcode = '',
49-
string $id = '',
50-
string $deliveryPhone = '',
47+
string $id = ''
5148
) {
5249
$this->id = $id;
5350
$this->cashier_name = $cashier_name;
5451
$this->departament = $departament;
5552
$this->goods = $goods;
56-
$this->deliveryEmail = $deliveryEmail;
57-
$this->deliveryPhone = $deliveryPhone;
53+
$this->delivery = $delivery;
5854
$this->discounts = $discounts;
5955
$this->payments = $payments;
6056
$this->header = $header;

tests/Mappers/SellReceiptTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use igorbunov\Checkbox\Mappers\Receipts\ReceiptMapper;
88
use igorbunov\Checkbox\Mappers\Receipts\SellReceiptMapper;
99
use igorbunov\Checkbox\Mappers\Receipts\Taxes\GoodTaxMapper;
10+
use igorbunov\Checkbox\Models\Receipts\Delivery;
1011
use igorbunov\Checkbox\Models\Receipts\Goods\GoodItemModel;
1112
use igorbunov\Checkbox\Models\Receipts\Goods\GoodModel;
1213
use igorbunov\Checkbox\Models\Receipts\Goods\Goods;
@@ -34,7 +35,7 @@ public function setUp(): void
3435
'er":"","footer":"","price":5000,"tax":["123123"],"uktzed":""},"quantity":1000,"is_return":false,' .
3536
'"discounts":[]},{"good":{"code":"vm-124","name":"\u0411\u0438\u043e\u0432\u0430\u043a 2",' .
3637
'"barcode":"","header":"","footer":"","price":2000,"tax":["123123"],"uktzed":""},' .
37-
'"quantity":2000,"is_return":false,"discounts":[]}],"delivery":{"email":"[email protected]"},' .
38+
'"quantity":2000,"is_return":false,"discounts":[]}],"delivery":{"emails":["[email protected]"]},' .
3839
'"discounts":[],"payments":[{"type":"CASHLESS","value":"4000","la' .
3940
'bel":"\u0411\u0435\u0437\u0433\u043e\u0442\u0456\u0432\u043a\u043e\u0432\u0438\u0439"},{"ty' .
4041
'pe":"CASH","value":"5000","label":"\u0413\u043e\u0442\u0456\u0432\u043a\u043e\u044e"}],"head' .
@@ -405,7 +406,7 @@ public function testMap(): void
405406
)
406407
]
407408
),
408-
409+
new Delivery(['[email protected]']),
409410
new Payments([
410411
new CardPaymentPayload(
411412
"4000" // 40 грн
@@ -472,7 +473,7 @@ public function testMapWithId()
472473
)
473474
]
474475
),
475-
476+
new Delivery(['[email protected]']),
476477
new Payments([
477478
new CardPaymentPayload(
478479
"4000" // 40 грн
@@ -496,7 +497,7 @@ public function testMapWithId()
496497
$this->assertEquals(json_encode($mappedJsonString), $result);
497498
}
498499

499-
public function testMapReceiptReuslt()
500+
public function testMapReceiptResult()
500501
{
501502
$jsonResponse = json_decode($this->jsonString, true);
502503

0 commit comments

Comments
 (0)