Skip to content

Commit 40b2c21

Browse files
wip
1 parent faaf880 commit 40b2c21

8 files changed

Lines changed: 539 additions & 27 deletions

File tree

src/Models/Orders/LineItem.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
namespace Piggy\Api\Models\Orders;
4+
5+
use Piggy\Api\Models\Products\Product;
6+
7+
class LineItem
8+
{
9+
/**
10+
* @var string $uuid
11+
*/
12+
protected $uuid;
13+
14+
/**
15+
* @var string|null $externalIdentifier
16+
*/
17+
protected $externalIdentifier;
18+
19+
/**
20+
* @var string|null $name
21+
*/
22+
protected $name;
23+
24+
/**
25+
* @var int $quantity
26+
*/
27+
protected $quantity;
28+
29+
/**
30+
* @var string $price
31+
*/
32+
protected $price;
33+
34+
/**
35+
* @var int|null $discountAmount
36+
*/
37+
protected $discountAmount;
38+
39+
/**
40+
* @var int $totalAmount
41+
*/
42+
protected $totalAmount;
43+
44+
/**
45+
* @var string $createdAt
46+
*/
47+
protected $createdAt;
48+
49+
/**
50+
* @var string $updatedAt
51+
*/
52+
protected $updatedAt;
53+
54+
/**
55+
* @var Product|null $product
56+
*/
57+
protected $product;
58+
59+
/**
60+
* @var SubLineItem[] $subLineItems
61+
*/
62+
protected $subLineItems;
63+
64+
public function __construct(
65+
string $uuid,
66+
?string $externalIdentifier,
67+
?string $name,
68+
int $quantity,
69+
string $price,
70+
?int $discountAmount,
71+
int $totalAmount,
72+
string $createdAt,
73+
string $updatedAt,
74+
?Product $product,
75+
array $subLineItems
76+
) {
77+
$this->uuid = $uuid;
78+
$this->externalIdentifier = $externalIdentifier;
79+
$this->name = $name;
80+
$this->quantity = $quantity;
81+
$this->price = $price;
82+
$this->discountAmount = $discountAmount;
83+
$this->totalAmount = $totalAmount;
84+
$this->createdAt = $createdAt;
85+
$this->updatedAt = $updatedAt;
86+
$this->product = $product;
87+
$this->subLineItems = $subLineItems;
88+
}
89+
90+
public function getUuid(): string
91+
{
92+
return $this->uuid;
93+
}
94+
95+
public function getExternalIdentifier(): ?string
96+
{
97+
return $this->externalIdentifier;
98+
}
99+
100+
public function getName(): ?string
101+
{
102+
return $this->name;
103+
}
104+
105+
public function getQuantity(): int
106+
{
107+
return $this->quantity;
108+
}
109+
110+
public function getPrice(): string
111+
{
112+
return $this->price;
113+
}
114+
115+
public function getDiscountAmount(): ?int
116+
{
117+
return $this->discountAmount;
118+
}
119+
120+
public function getTotalAmount(): int
121+
{
122+
return $this->totalAmount;
123+
}
124+
125+
public function getCreatedAt(): string
126+
{
127+
return $this->createdAt;
128+
}
129+
130+
public function getUpdatedAt(): string
131+
{
132+
return $this->updatedAt;
133+
}
134+
135+
public function getProduct(): ?Product
136+
{
137+
return $this->product;
138+
}
139+
140+
public function getSubLineItems(): array
141+
{
142+
return $this->subLineItems;
143+
}
144+
}

src/Models/Orders/Order.php

Lines changed: 125 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Piggy\Api\Exceptions\PiggyRequestException;
99
use Piggy\Api\Models\Contacts\Contact;
1010
use Piggy\Api\Models\Shops\Shop;
11+
use Piggy\Api\StaticMappers\Orders\OrderMapper;
1112
use Piggy\Api\StaticMappers\Orders\OrdersMapper;
13+
use stdClass;
1214

1315
class Order
1416
{
@@ -22,16 +24,6 @@ class Order
2224
*/
2325
protected $externalIdentifier;
2426

25-
/**
26-
* @var Contact
27-
*/
28-
protected $contact;
29-
30-
/**
31-
* @var Shop
32-
*/
33-
protected $shop;
34-
3527
/**
3628
* @var string
3729
*/
@@ -82,7 +74,6 @@ class Order
8274
*/
8375
protected $paidAt;
8476

85-
// TODO: Add Line Items
8677
// TODO: Add Applied Discounts
8778
// TODO: Add Charges
8879

@@ -96,6 +87,21 @@ class Order
9687
*/
9788
protected $updatedAt;
9889

90+
/**
91+
* @var Contact
92+
*/
93+
protected $contact;
94+
95+
/**
96+
* @var Shop
97+
*/
98+
protected $shop;
99+
100+
/**
101+
* @var LineItem[] $lineItems
102+
*/
103+
protected $lineItems;
104+
99105
/**
100106
* @var string
101107
*/
@@ -104,8 +110,6 @@ class Order
104110
public function __construct(
105111
string $uuid,
106112
string $externalIdentifier,
107-
Contact $contact,
108-
Shop $shop,
109113
string $currency,
110114
?string $reference,
111115
string $status,
@@ -117,12 +121,13 @@ public function __construct(
117121
int $totalOrderAmount,
118122
?string $paidAt,
119123
string $createdAt,
120-
string $updatedAt
124+
string $updatedAt,
125+
Contact $contact,
126+
Shop $shop,
127+
array $lineItems
121128
) {
122129
$this->uuid = $uuid;
123130
$this->externalIdentifier = $externalIdentifier;
124-
$this->contact = $contact;
125-
$this->shop = $shop;
126131
$this->currency = $currency;
127132
$this->reference = $reference;
128133
$this->status = $status;
@@ -135,6 +140,9 @@ public function __construct(
135140
$this->paidAt = $paidAt;
136141
$this->createdAt = $createdAt;
137142
$this->updatedAt = $updatedAt;
143+
$this->contact = $contact;
144+
$this->shop = $shop;
145+
$this->lineItems = $lineItems;
138146
}
139147

140148
public function getUuid(): string
@@ -147,16 +155,6 @@ public function getExternalIdentifier(): string
147155
return $this->externalIdentifier;
148156
}
149157

150-
public function getContact(): Contact
151-
{
152-
return $this->contact;
153-
}
154-
155-
public function getShop(): Shop
156-
{
157-
return $this->shop;
158-
}
159-
160158
public function getCurrency(): string
161159
{
162160
return $this->currency;
@@ -217,6 +215,21 @@ public function getUpdatedAt(): string
217215
return $this->updatedAt;
218216
}
219217

218+
public function getContact(): Contact
219+
{
220+
return $this->contact;
221+
}
222+
223+
public function getShop(): Shop
224+
{
225+
return $this->shop;
226+
}
227+
228+
public function getLineItems(): array
229+
{
230+
return $this->lineItems;
231+
}
232+
220233
/**
221234
* @param array<string, mixed> $params
222235
*
@@ -230,4 +243,90 @@ public static function list(array $params = []): array
230243

231244
return OrdersMapper::map($response->getData());
232245
}
246+
247+
/**
248+
* @param string $uuid
249+
* @param array<string, mixed> $params
250+
*
251+
* @return Order
252+
*
253+
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
254+
*/
255+
public static function get(string $uuid, array $params = []): Order
256+
{
257+
$response = ApiClient::get(self::resourceUri."/$uuid", $params);
258+
259+
return OrderMapper::map($response->getData());
260+
}
261+
262+
/**
263+
* @param array<string, mixed> $params
264+
*
265+
* @return Order
266+
*
267+
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
268+
*/
269+
public static function find(array $params): Order
270+
{
271+
$response = ApiClient::get(self::resourceUri."/find", $params);
272+
273+
return OrderMapper::map($response->getData());
274+
}
275+
276+
/**
277+
* @param array<string, mixed> $body
278+
*
279+
* @return Order
280+
*
281+
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
282+
*/
283+
public static function create(array $body): Order
284+
{
285+
$response = ApiClient::post(self::resourceUri, $body);
286+
287+
return OrderMapper::map($response->getData());
288+
}
289+
290+
/**
291+
* @param string $uuid
292+
* @param array<string, mixed> $body
293+
*
294+
* @return Order
295+
*
296+
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
297+
*/
298+
public static function process(string $uuid, array $body): Order
299+
{
300+
$response = ApiClient::post(self::resourceUri."$uuid/process", $body);
301+
302+
return OrderMapper::map($response->getData());
303+
}
304+
305+
/**
306+
* @param array<string, mixed> $body
307+
*
308+
* @return Order
309+
*
310+
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
311+
*/
312+
public static function createAndProcess(array $body): Order
313+
{
314+
$response = ApiClient::post(self::resourceUri."/create-and-process", $body);
315+
316+
return OrderMapper::map($response->getData());
317+
}
318+
319+
/**
320+
* @param array<string, mixed> $body
321+
*
322+
* @return stdClass
323+
*
324+
* @throws GuzzleException|MaintenanceModeException|PiggyRequestException
325+
*/
326+
public static function calculate(array $body): stdClass
327+
{
328+
$response = ApiClient::post(self::resourceUri."/calculate", $body);
329+
330+
return $response->getData();
331+
}
233332
}

0 commit comments

Comments
 (0)