88use Piggy \Api \Exceptions \PiggyRequestException ;
99use Piggy \Api \Models \Contacts \Contact ;
1010use Piggy \Api \Models \Shops \Shop ;
11+ use Piggy \Api \StaticMappers \Orders \OrderMapper ;
1112use Piggy \Api \StaticMappers \Orders \OrdersMapper ;
13+ use stdClass ;
1214
1315class 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