1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the PayBreak/basket package. |
4
|
|
|
* |
5
|
|
|
* (c) PayBreak <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PayBreak\Sdk\Gateways; |
12
|
|
|
|
13
|
|
|
use PayBreak\Sdk\Entities\ApplicationEntity; |
14
|
|
|
use PayBreak\Sdk\SdkException; |
15
|
|
|
use WNowicki\Generic\ApiClient\ErrorResponseException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Application Gateway |
19
|
|
|
* |
20
|
|
|
* @author WN |
21
|
|
|
* @package PayBreak\Sdk\Gateways |
22
|
|
|
*/ |
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) |
33
|
|
|
{ |
34
|
2 |
|
return ApplicationEntity::make($this->fetchDocument('/v4/applications/' . $id, $token, 'Application')); |
35
|
|
|
} |
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) |
76
|
|
|
{ |
77
|
2 |
|
return $this->requestAction('/v4/applications/' . $id . '/fulfil', [], $token); |
78
|
|
|
} |
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) |
88
|
|
|
{ |
89
|
2 |
|
return $this->requestAction( |
90
|
2 |
|
'/v4/applications/' . $id . '/request-cancellation', |
91
|
2 |
|
['description' => $description], |
92
|
|
|
$token |
93
|
2 |
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param $token |
98
|
|
|
* @return array |
99
|
|
|
* @throws SdkException |
100
|
|
|
*/ |
101
|
2 |
|
public function getPendingCancellations($installationId, $token) |
102
|
|
|
{ |
103
|
2 |
|
return $this->fetchDocument( |
104
|
2 |
|
'/v4/installations/' . $installationId . '/applications', |
105
|
2 |
|
$token, |
106
|
2 |
|
'Pending Cancellations', |
107
|
2 |
|
['pending-cancellations' => true] |
108
|
2 |
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @author EB |
113
|
|
|
* @param $installationId |
114
|
|
|
* @param $application |
115
|
|
|
* @param $token |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
2 |
|
public function getApplicationCreditInfo($installationId, $application, $token) |
119
|
|
|
{ |
120
|
2 |
|
return $this->postDocument( |
121
|
2 |
|
'v4/installations/' . $installationId . '/applications/' . $application . '/get-credit-information', |
122
|
2 |
|
[], |
123
|
2 |
|
$token, |
124
|
|
|
'Application Credit Information' |
125
|
2 |
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @author WN |
130
|
|
|
* @param string $action |
131
|
|
|
* @param array $data |
132
|
|
|
* @param string $token |
133
|
|
|
* @return bool |
134
|
|
|
* @throws SdkException |
135
|
|
|
*/ |
136
|
4 |
|
private function requestAction($action, $data, $token) |
137
|
|
|
{ |
138
|
4 |
|
$this->postDocument($action, $data, $token, 'Application'); |
139
|
4 |
|
return true; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|