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