Skip to content

Commit 02ec9d9

Browse files
wip
1 parent a4307b4 commit 02ec9d9

5 files changed

Lines changed: 45 additions & 43 deletions

File tree

src/Models/Orders/AppliedDiscount.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ class AppliedDiscount
4040
protected $appliedTo;
4141

4242
/**
43-
* @var array<string, string>
43+
* @var array<string, mixed>
4444
*/
45-
protected $lineItems;
45+
protected $lineItems = [];
4646

4747
/**
48-
* @var array<string, string>
48+
* @var array<string, mixed>
4949
*/
50-
protected $subLineItems;
50+
protected $subLineItems = [];
5151

5252
/**
53-
* @param array<string, string> $lineItems
54-
* @param array<string, string> $subLineItems
53+
* @param array<string, mixed> $lineItems
54+
* @param array<string, mixed> $subLineItems
5555
*/
5656
public function __construct(
5757
string $uuid,
@@ -61,8 +61,8 @@ public function __construct(
6161
string $type,
6262
string $value,
6363
string $appliedTo,
64-
array $lineItems,
65-
array $subLineItems
64+
array $lineItems = [],
65+
array $subLineItems = []
6666
) {
6767
$this->uuid = $uuid;
6868
$this->externalIdentifier = $externalIdentifier;
@@ -111,15 +111,15 @@ public function getAppliedTo(): string
111111
}
112112

113113
/**
114-
* @return array<string, string>
114+
* @return array<string, mixed>
115115
*/
116116
public function getLineItems(): array
117117
{
118118
return $this->lineItems;
119119
}
120120

121121
/**
122-
* @return array<string, string>
122+
* @return array<string, mixed>
123123
*/
124124
public function getSubLineItems(): array
125125
{

src/Models/Orders/LineItem.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class LineItem
5959
/**
6060
* @var SubLineItem[]
6161
*/
62-
protected $subLineItems;
62+
protected $subLineItems = [];
6363

6464
/** @param SubLineItem[] $subLineItems */
6565
public function __construct(
@@ -73,7 +73,7 @@ public function __construct(
7373
string $createdAt,
7474
string $updatedAt,
7575
?Product $product,
76-
array $subLineItems
76+
array $subLineItems = []
7777
) {
7878
$this->uuid = $uuid;
7979
$this->externalIdentifier = $externalIdentifier;
@@ -139,7 +139,7 @@ public function getProduct(): ?Product
139139
}
140140

141141
/**
142-
* @return array|SubLineItem[]
142+
* @return SubLineItem[]
143143
*/
144144
public function getSubLineItems(): array
145145
{

src/Models/Orders/Order.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Piggy\Api\Models\Shops\Shop;
1111
use Piggy\Api\StaticMappers\Orders\OrderMapper;
1212
use Piggy\Api\StaticMappers\Orders\OrdersMapper;
13-
use stdClass;
1413

1514
class Order
1615
{
@@ -95,17 +94,17 @@ class Order
9594
protected $shop;
9695

9796
/**
98-
* @var LineItem[] $lineItems
97+
* @var LineItem[]
9998
*/
100-
protected $lineItems;
99+
protected $lineItems = [];
101100

102101
/**
103-
* @var AppliedDiscount[] $appliedDiscounts
102+
* @var AppliedDiscount[]
104103
*/
105104
protected $appliedDiscounts = [];
106105

107106
/**
108-
* @var Charge[] $charges
107+
* @var Charge[]
109108
*/
110109
protected $charges = [];
111110

@@ -136,7 +135,7 @@ public function __construct(
136135
string $updatedAt,
137136
Contact $contact,
138137
Shop $shop,
139-
array $lineItems,
138+
array $lineItems = [],
140139
array $appliedDiscounts = [],
141140
array $charges = []
142141
) {
@@ -242,23 +241,23 @@ public function getShop(): Shop
242241
}
243242

244243
/**
245-
* @return array|LineItem[]
244+
* @return LineItem[]
246245
*/
247246
public function getLineItems(): array
248247
{
249248
return $this->lineItems;
250249
}
251250

252251
/**
253-
* @return array|AppliedDiscount[]
252+
* @return AppliedDiscount[]
254253
*/
255254
public function getAppliedDiscounts(): array
256255
{
257256
return $this->appliedDiscounts;
258257
}
259258

260259
/**
261-
* @return array|Charge[]
260+
* @return Charge[]
262261
*/
263262
public function charges(): array
264263
{
@@ -326,39 +325,42 @@ public static function create(array $body): Order
326325
* @param string $uuid
327326
* @param array<string, mixed> $body
328327
*
329-
* @return Order
328+
* @return array<string, mixed>
330329
*
331330
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
332331
*/
333-
public static function process(string $uuid, array $body): Order
332+
public static function process(string $uuid, array $body): array
334333
{
335334
$response = ApiClient::post(self::resourceUri."$uuid/process", $body);
336335

337-
return OrderMapper::map($response->getData());
336+
return $response->getData();
338337
}
339338

340339
/**
341340
* @param array<string, mixed> $body
342341
*
343-
* @return Order
342+
* @return array<string, mixed>
344343
*
345344
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
346345
*/
347-
public static function createAndProcess(array $body): Order
346+
public static function createAndProcess(array $body): array
348347
{
349348
$response = ApiClient::post(self::resourceUri."/create-and-process", $body);
350349

351-
return OrderMapper::map($response->getData());
350+
return [
351+
'order' => OrderMapper::map($response->getData()->order),
352+
'result' => $response->getData()->result,
353+
];
352354
}
353355

354356
/**
355357
* @param array<string, mixed> $body
356358
*
357-
* @return stdClass
359+
* @return array<string, mixed>
358360
*
359361
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
360362
*/
361-
public static function calculate(array $body): stdClass
363+
public static function calculate(array $body): array
362364
{
363365
$response = ApiClient::post(self::resourceUri."/calculate", $body);
364366

src/Models/Orders/SubLineItem.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,57 @@
77
class SubLineItem
88
{
99
/**
10-
* @var string $uuid
10+
* @var string
1111
*/
1212
protected $uuid;
1313

1414
/**
15-
* @var string|null $externalIdentifier
15+
* @var string|null
1616
*/
1717
protected $externalIdentifier;
1818

1919
/**
20-
* @var string|null $name
20+
* @var string|null
2121
*/
2222
protected $name;
2323

2424
/**
25-
* @var int $quantity
25+
* @var int
2626
*/
2727
protected $quantity;
2828

2929
/**
30-
* @var string $price
30+
* @var string
3131
*/
3232
protected $price;
3333

3434
/**
35-
* @var int|null $discountAmount
35+
* @var int|null
3636
*/
3737
protected $discountAmount;
3838

3939
/**
40-
* @var int $totalAmount
40+
* @var int
4141
*/
4242
protected $totalAmount;
4343

4444
/**
45-
* @var string $createdAt
45+
* @var string
4646
*/
4747
protected $createdAt;
4848

4949
/**
50-
* @var string $updatedAt
50+
* @var string
5151
*/
5252
protected $updatedAt;
5353

5454
/**
55-
* @var LineItem $lineItem
55+
* @var LineItem
5656
*/
5757
protected $lineItem;
5858

5959
/**
60-
* @var Product|null $product
60+
* @var Product|null
6161
*/
6262
protected $product;
6363

src/StaticMappers/Orders/OrderMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static function map(stdClass $data): Order
3939
(int) $data->total_discount_amount,
4040
(int) $data->total_order_amount,
4141
$data->paid_at ?? null,
42-
$data->created_at,
43-
$data->updated_at,
42+
$data->created_at ?? '',
43+
$data->updated_at ?? '',
4444
$contact,
4545
$shop,
4646
$lineItems,

0 commit comments

Comments
 (0)