1 | <?php |
||
23 | class ApplicationGateway extends AbstractGateway |
||
24 | { |
||
25 | /** |
||
26 | * @author WN |
||
27 | * @param int $id |
||
28 | * @param string $token |
||
29 | * @return ApplicationEntity |
||
30 | * @throws SdkException |
||
31 | */ |
||
32 | 2 | public function getApplication($id, $token) |
|
36 | |||
37 | /** |
||
38 | * @author WN |
||
39 | * @param ApplicationEntity $application |
||
40 | * @param string $token |
||
41 | * @return ApplicationEntity |
||
42 | * @throws SdkException |
||
43 | */ |
||
44 | 6 | public function initialiseApplication(ApplicationEntity $application, $token) |
|
45 | { |
||
46 | 6 | $api = $this->getApiFactory()->makeApiClient($token); |
|
47 | |||
48 | try { |
||
49 | 6 | $response = $api->post('/v4/initialize-application', $application->toArray(true)); |
|
50 | |||
51 | 2 | $application->setId($response['application']); |
|
52 | 2 | $application->setResumeUrl($response['url']); |
|
53 | |||
54 | 2 | return $application; |
|
55 | |||
56 | 4 | } catch (ErrorResponseException $e) { |
|
57 | |||
58 | 2 | $this->logWarning('ApplicationGateway::initialiseApplication[' . $e->getCode() . ']: ' . $e->getMessage()); |
|
59 | 2 | throw new SdkException($e->getMessage()); |
|
60 | |||
61 | 2 | } catch (\Exception $e) { |
|
62 | |||
63 | 2 | $this->logError('ApplicationGateway::initialiseApplication[' . $e->getCode() . ']: ' . $e->getMessage()); |
|
64 | 2 | throw new SdkException('Problem Initialising Application on Provider API'); |
|
65 | } |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @author WN |
||
70 | * @param int $id |
||
71 | * @param string $token |
||
72 | * @return bool |
||
73 | * @throws SdkException |
||
74 | */ |
||
75 | 2 | public function fulfilApplication($id, $token) |
|
79 | |||
80 | /** |
||
81 | * @param int $id |
||
82 | * @param string $description |
||
83 | * @param string $token |
||
84 | * @return bool |
||
85 | * @throws SdkException |
||
86 | */ |
||
87 | 2 | public function cancelApplication($id, $description, $token) |
|
95 | |||
96 | /** |
||
97 | * @param $token |
||
98 | * @return array |
||
99 | * @throws SdkException |
||
100 | */ |
||
101 | 2 | public function getPendingCancellations($installationId, $token) |
|
110 | |||
111 | /** |
||
112 | * Get Merchant Payments. Filter Params can accept |
||
113 | * - since, until : (string - ISO8601 Date Part Only) |
||
114 | * - count, offset : (int) |
||
115 | * |
||
116 | * @author SL |
||
117 | * @param $application |
||
118 | * @param $token |
||
119 | * @param array $filterParams |
||
120 | * @return array |
||
121 | */ |
||
122 | 2 | public function getMerchantPayments($application, $token, array $filterParams = []) |
|
123 | { |
||
124 | 2 | return $this->fetchDocument( |
|
125 | 2 | '/v4/applications/' . $application . '/merchant-payments', |
|
126 | 2 | $token, |
|
127 | 2 | 'Merchant Payments', |
|
128 | $filterParams |
||
129 | 2 | ); |
|
130 | } |
||
131 | |||
132 | /** |
||
133 | * Add a Merchant Payment to the given application. Amount should be supplied in pence. |
||
134 | * |
||
135 | * @author SL |
||
136 | * @param string $application |
||
137 | * @param \DateTime $effectiveDate |
||
138 | * @param int $amount |
||
139 | * @param string $token |
||
140 | * @return array |
||
141 | */ |
||
142 | 2 | public function addMerchantPayment($application, \DateTime $effectiveDate, $amount, $token) |
|
143 | { |
||
144 | 2 | return $this->postDocument( |
|
145 | 2 | '/v4/applications/' . $application . '/merchant-payments', |
|
146 | [ |
||
147 | 2 | 'amount' => $amount, |
|
148 | 2 | 'effective_date' => $effectiveDate->format('Y-m-d'), |
|
149 | 2 | ], |
|
150 | 2 | $token, |
|
151 | 'Add Merchant Payment' |
||
152 | 2 | ); |
|
153 | } |
||
154 | |||
155 | /** |
||
156 | * @author EB |
||
157 | * @param $installationId |
||
158 | * @param $application |
||
159 | * @param $token |
||
160 | * @return array |
||
161 | */ |
||
162 | 2 | public function getApplicationCreditInfo($installationId, $application, $token) |
|
171 | |||
172 | /** |
||
173 | * Get application history |
||
174 | * |
||
175 | * @author SL |
||
176 | * @param $application |
||
177 | * @param $token |
||
178 | * @return array |
||
179 | */ |
||
180 | 2 | public function getApplicationHistory($application, $token) |
|
181 | { |
||
182 | 2 | return $this->fetchDocument( |
|
183 | 2 | '/v4/applications/' . $application . '/status-history', |
|
184 | 2 | $token, |
|
185 | 'Application Status History' |
||
186 | 2 | ); |
|
187 | } |
||
188 | |||
189 | /** |
||
190 | * @author WN |
||
191 | * @param string $action |
||
192 | * @param array $data |
||
193 | * @param string $token |
||
194 | * @return bool |
||
195 | * @throws SdkException |
||
196 | */ |
||
197 | 4 | private function requestAction($action, $data, $token) |
|
202 | } |
||
203 |