Skip to content

Commit 5857210

Browse files
wip
1 parent bc8a2ca commit 5857210

3 files changed

Lines changed: 267 additions & 0 deletions

File tree

src/Http/Traits/SetsOAuthResources.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Piggy\Api\Resources\OAuth\Loyalty\Rewards\RewardAttributesResource;
2727
use Piggy\Api\Resources\OAuth\Loyalty\Rewards\RewardsResource;
2828
use Piggy\Api\Resources\OAuth\Loyalty\Tokens\LoyaltyTokensResource;
29+
use Piggy\Api\Resources\OAuth\Orders\OrdersResource;
2930
use Piggy\Api\Resources\OAuth\Perks\PerksResource;
3031
use Piggy\Api\Resources\OAuth\PortalSessions\PortalSessionsResource;
3132
use Piggy\Api\Resources\OAuth\PrepaidTransactionsResource;
@@ -215,6 +216,11 @@ trait SetsOAuthResources
215216
*/
216217
public $categories;
217218

219+
/**
220+
* @var OrdersResource
221+
*/
222+
public $orders;
223+
218224
protected function setResources(BaseClient $client): void
219225
{
220226
$this->contacts = new ContactsResource($client);
@@ -252,5 +258,6 @@ protected function setResources(BaseClient $client): void
252258
$this->customAttributes = new CustomAttributeResource($client);
253259
$this->products = new ProductsResource($client);
254260
$this->categories = new CategoriesResource($client);
261+
$this->orders = new OrdersResource($client);
255262
}
256263
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
namespace Piggy\Api\Resources\Register\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/register/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

Comments
 (0)