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 | protected $negativeAmountAllowed = true; |
|
17 | |||
18 | 15 | public function getKey() |
|
19 | { |
||
20 | return $this->getParameter('key'); |
||
21 | 60 | } |
|
22 | |||
23 | 60 | public function setKey($value) |
|
24 | { |
||
25 | return $this->setParameter('key', $value); |
||
26 | 45 | } |
|
27 | |||
28 | 45 | public function getApiKey() |
|
29 | { |
||
30 | return $this->getParameter('apiKey'); |
||
31 | 60 | } |
|
32 | |||
33 | 60 | public function setApiKey($value) |
|
34 | { |
||
35 | return $this->setParameter('apiKey', $value); |
||
36 | 30 | } |
|
37 | |||
38 | public function getHeaders() |
||
39 | 30 | { |
|
40 | 30 | return [ |
|
41 | 30 | 'Content-Type' => 'application/json', |
|
42 | 10 | 'Authorization' => 'Bearer ' . $this->getApiKey(), |
|
43 | 'Zip-Version' => '2017-03-01', |
||
44 | ]; |
||
45 | 30 | } |
|
46 | |||
47 | 30 | public function sendData($data) |
|
48 | { |
||
49 | 30 | $headers = $this->getHeaders(); |
|
50 | 30 | ||
51 | 30 | $url = $this->getEndpoint(); |
|
52 | $body = null; |
||
53 | if ($this->getHttpMethod() === 'GET') { |
||
54 | 30 | $url = $this->getEndpoint().'?'.http_build_query($data, '', '&'); |
|
55 | } else { |
||
56 | $body = json_encode($data); |
||
57 | 30 | } |
|
58 | |||
59 | 30 | $response = $this->httpClient->request($this->getHttpMethod(), $url, $headers, $body); |
|
60 | |||
61 | 30 | $responseHeaders = $response->getHeaders(); |
|
62 | |||
63 | 30 | $data = json_decode($response->getBody(), true); |
|
64 | |||
65 | return $this->createResponse($data, $responseHeaders, $response->getStatusCode()); |
||
66 | } |
||
67 | |||
68 | public function getHttpMethod() |
||
72 | |||
73 | 30 | protected function getBaseData() |
|
77 | |||
78 | 30 | protected function getEndpoint() |
|
82 | |||
83 | protected function createResponse($data, $headers = [], $status = 404) |
||
87 | } |
||
88 |
This check looks for function calls that miss required arguments.