1 | <?php |
||
9 | class Request |
||
10 | { |
||
11 | /** |
||
12 | * Paddle API Endpoint. |
||
13 | */ |
||
14 | const API_ENDPOINT = "https://vendors.paddle.com/api"; |
||
15 | |||
16 | /** |
||
17 | * Method options. |
||
18 | */ |
||
19 | const METHOD_GET = 'get'; |
||
20 | const METHOD_POST = 'post'; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $uri; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $data = []; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $rules = []; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $method; |
||
41 | |||
42 | /** |
||
43 | * Creates an instance with the URI and data. |
||
44 | * |
||
45 | * @param string $uri |
||
46 | * @param array $data |
||
47 | * @param array $rules |
||
48 | * @param string $method |
||
49 | */ |
||
50 | public function __construct(string $uri, array $data = [], array $rules = [], string $method = self::METHOD_POST) |
||
58 | |||
59 | /** |
||
60 | * Formats the URL to send the request to. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | public function url(): string |
||
68 | |||
69 | /** |
||
70 | * Validates the data with the rules. |
||
71 | * |
||
72 | * @return $this |
||
73 | * @throws \ProtoneMedia\LaravelPaddle\Api\InvalidDataException |
||
74 | */ |
||
75 | protected function validateData() |
||
87 | |||
88 | /** |
||
89 | * Sends the data payload to the uri and returns to decoded response. |
||
90 | * |
||
91 | * @return mixed |
||
92 | * |
||
93 | * @throws \ProtoneMedia\LaravelPaddle\Api\PaddleApiException |
||
94 | */ |
||
95 | public function send() |
||
127 | |||
128 | /** |
||
129 | * Getter for the set data. |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | public function getData(): array |
||
137 | |||
138 | /** |
||
139 | * Loops through the array to set all data attributes. |
||
140 | * |
||
141 | * @param array $data |
||
142 | * @return $this |
||
143 | */ |
||
144 | private function fill(array $data) |
||
152 | |||
153 | /** |
||
154 | * Setter for the data. |
||
155 | * |
||
156 | * @param string $key |
||
157 | * @param mixed $value |
||
158 | * @return $this |
||
159 | */ |
||
160 | protected function setAttribute(string $key, $value = null) |
||
166 | |||
167 | /** |
||
168 | * To make the request fluent. |
||
169 | * |
||
170 | * @param string $method |
||
171 | * @param array $parameters |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function __call($method, $parameters) |
||
178 | } |
||
179 |