1+ <?php
2+
3+ namespace Piggy \Api \Resources \OAuth \Orders ;
4+
5+ use Piggy \Api \Exceptions \PiggyRequestException ;
6+ use Piggy \Api \Mappers \Orders \OrderMapper ;
7+ use Piggy \Api \Mappers \Orders \OrdersMapper ;
8+ use Piggy \Api \Models \Orders \Order ;
9+ use Piggy \Api \Resources \BaseResource ;
10+
11+ class OrdersResource extends BaseResource
12+ {
13+ /**
14+ * @var string
15+ */
16+ protected $ resourceUri = '/api/v3/oauth/clients/orders ' ;
17+
18+ /**
19+ * @param array<string, mixed> $params
20+ *
21+ * @return Order[]
22+ *
23+ * @throws PiggyRequestException
24+ */
25+ public function list (array $ params = []): array
26+ {
27+ $ response = $ this ->client ->get ($ this ->resourceUri , $ params );
28+
29+ $ mapper = new OrdersMapper ();
30+
31+ return $ mapper ->map ($ response ->getData ());
32+ }
33+
34+ /**
35+ * @param string $uuid
36+ * @param array<string, mixed> $params
37+ *
38+ * @return Order
39+ *
40+ * @throws PiggyRequestException
41+ */
42+ public function get (string $ uuid , array $ params = []): Order
43+ {
44+ $ response = $ this ->client ->get ($ this ->resourceUri ."/ $ uuid " , $ params );
45+
46+ $ mapper = new OrderMapper ();
47+
48+ return $ mapper ->map ($ response ->getData ());
49+ }
50+
51+ /**
52+ * @param array<string, mixed> $params
53+ *
54+ * @return Order
55+ *
56+ * @throws PiggyRequestException
57+ */
58+ public function find (array $ params ): Order
59+ {
60+ $ response = $ this ->client ->get ($ this ->resourceUri ."/find " , $ params );
61+
62+ $ mapper = new OrderMapper ();
63+
64+ return $ mapper ->map ($ response ->getData ());
65+ }
66+
67+ /**
68+ * @param array<string, mixed> $body
69+ *
70+ * @return Order
71+ *
72+ * @throws PiggyRequestException
73+ */
74+ public function create (array $ body ): Order
75+ {
76+ $ response = $ this ->client ->post ($ this ->resourceUri , $ body );
77+
78+ $ mapper = new OrderMapper ();
79+
80+ return $ mapper ->map ($ response ->getData ());
81+ }
82+
83+ /**
84+ * @param string $uuid
85+ * @param array<string, mixed> $body
86+ *
87+ * @return array<string, mixed>
88+ *
89+ * @throws PiggyRequestException
90+ */
91+ public function process (string $ uuid , array $ body ): array
92+ {
93+ $ response = $ this ->client ->post ($ this ->resourceUri ."$ uuid/process " , $ body );
94+
95+ return $ response ->getData ();
96+ }
97+
98+ /**
99+ * @param array<string, mixed> $body
100+ *
101+ * @return array<string, mixed>
102+ *
103+ * @throws PiggyRequestException
104+ */
105+ public function createAndProcess (array $ body ): array
106+ {
107+ $ response = $ this ->client ->post ($ this ->resourceUri ."/create-and-process " , $ body );
108+
109+ $ mapper = new OrderMapper ();
110+
111+ return [
112+ 'order ' => $ mapper ->map ($ response ->getData ()),
113+ 'result ' => $ response ->getData ()->result ,
114+ ];
115+ }
116+
117+ /**
118+ * @param array<string, mixed> $body
119+ *
120+ * @return array<string, mixed>
121+ *
122+ * @throws PiggyRequestException
123+ */
124+ public function calculate (array $ body ): array
125+ {
126+ $ response = $ this ->client ->post ($ this ->resourceUri ."/calculate " , $ body );
127+
128+ return $ response ->getData ();
129+ }
130+ }
0 commit comments