1 | <?php |
||
11 | abstract class AbstractRequest extends BaseAbstractRequest |
||
12 | { |
||
13 | protected $liveEndpoint = 'https://api.zipmoney.com.au/merchant/v1'; |
||
14 | protected $testEndpoint = 'https://api.sandbox.zipmoney.com.au/merchant/v1'; |
||
15 | |||
16 | 15 | public function getKey() |
|
20 | |||
21 | 60 | public function setKey($value) |
|
25 | |||
26 | 45 | public function getApiKey() |
|
30 | |||
31 | 60 | public function setApiKey($value) |
|
35 | |||
36 | 30 | public function getHeaders() |
|
37 | { |
||
38 | return [ |
||
39 | 30 | 'Content-Type' => 'application/json', |
|
40 | 30 | 'Authorization' => 'Bearer ' . $this->getApiKey(), |
|
41 | 30 | 'Zip-Version' => '2017-03-01', |
|
42 | 10 | ]; |
|
43 | } |
||
44 | |||
45 | 30 | public function sendData($data) |
|
46 | { |
||
47 | 30 | $headers = $this->getHeaders(); |
|
48 | |||
49 | 30 | $url = $this->getEndpoint(); |
|
50 | 30 | $body = null; |
|
51 | 30 | if ($this->getHttpMethod() === 'GET') { |
|
52 | $url = $this->getEndpoint().'?'.http_build_query($data, '', '&'); |
||
53 | } else { |
||
54 | 30 | $body = json_encode($data); |
|
55 | } |
||
56 | |||
57 | 30 | $response = $this->httpClient->request($this->getHttpMethod(), $url, $headers, $body); |
|
58 | |||
59 | 30 | $responseHeaders = $response->getHeaders(); |
|
60 | |||
61 | 30 | $data = json_decode($response->getBody(), true); |
|
62 | |||
63 | 30 | return $this->createResponse($data, $responseHeaders, $response->getStatusCode()); |
|
64 | } |
||
65 | |||
66 | public function getHttpMethod() |
||
70 | |||
71 | 30 | protected function getBaseData() |
|
75 | |||
76 | 30 | protected function getEndpoint() |
|
80 | |||
81 | protected function createResponse($data, $headers = [], $status = 404) |
||
85 | } |
||
86 |
This check looks for function calls that miss required arguments.