1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\WindcaveHpp\Message; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
6
|
|
|
use Omnipay\Common\Message\AbstractRequest; |
7
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Windcave HPP Purchase Request |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
class PurchaseRequest extends AbstractRequest { |
14
|
|
|
|
15
|
|
|
const endpointTest = 'https://uat.windcave.com/api/v1'; |
16
|
|
|
const endpointLive = 'https://sec.windcave.com/api/v1'; |
17
|
|
|
|
18
|
|
|
public function initialize(array $parameters = []) |
19
|
|
|
{ |
20
|
|
|
$this->metaData = new ParameterBag(); |
|
|
|
|
21
|
|
|
|
22
|
|
|
return parent::initialize($parameters); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function setApiUsername($value) |
26
|
|
|
{ |
27
|
|
|
return $this->setParameter('apiUsername', $value); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getApiUsername() |
31
|
|
|
{ |
32
|
|
|
return $this->getParameter('apiUsername'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function setApiKey($value) |
36
|
|
|
{ |
37
|
|
|
return $this->setParameter('apiKey', $value); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getApiKey() |
41
|
|
|
{ |
42
|
|
|
return $this->getParameter('apiKey'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function setMerchantReference($value) |
46
|
|
|
{ |
47
|
|
|
return $this->setParameter('merchantReference', $value); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getMerchantReference() |
51
|
|
|
{ |
52
|
|
|
return $this->getParameter('merchantReference'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setType($value) |
56
|
|
|
{ |
57
|
|
|
return $this->setParameter('type', $value); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getType() |
61
|
|
|
{ |
62
|
|
|
return $this->getParameter('type') ?? 'purchase'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setLanguage($value) |
66
|
|
|
{ |
67
|
|
|
return $this->setParameter('language', $value); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getLanguage() |
71
|
|
|
{ |
72
|
|
|
return $this->getParameter('language') ?? 'en'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param $list |
77
|
|
|
* Possible methods: ['card', 'account2account', 'alipay', 'applepay', 'googlepay', 'paypal', 'interac', 'unionpay', 'oxipay', 'visacheckout', 'wechat'] |
78
|
|
|
* |
79
|
|
|
* @return PurchaseRequest |
80
|
|
|
*/ |
81
|
|
|
public function setPaymentMethods($list) |
82
|
|
|
{ |
83
|
|
|
return $this->setParameter('paymentMethods', $list); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getPaymentMethods() |
87
|
|
|
{ |
88
|
|
|
return $this->getParameter('paymentMethods'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function setCardTypes($list) |
92
|
|
|
{ |
93
|
|
|
return $this->setParameter('cardTypes', $list); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getCardTypes() |
97
|
|
|
{ |
98
|
|
|
return $this->getParameter('cardTypes'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function setExpiresAt($value) |
102
|
|
|
{ |
103
|
|
|
return $this->setParameter('expiresAt', $value); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getExpiresAt() |
107
|
|
|
{ |
108
|
|
|
return $this->getParameter('expiresAt'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function setDeclineUrl($url) |
112
|
|
|
{ |
113
|
|
|
return $this->setParameter('declineUrl', $url); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getDeclineUrl() |
117
|
|
|
{ |
118
|
|
|
return $this->getParameter('declineUrl'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function setStoreCard($value) |
122
|
|
|
{ |
123
|
|
|
return $this->setParameter('storeCard', $value); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function getStoreCard() |
127
|
|
|
{ |
128
|
|
|
return $this->getParameter('storeCard'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function setMetadata($data) |
132
|
|
|
{ |
133
|
|
|
return $this->setParameter('metadata', $data); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getMetadata() |
137
|
|
|
{ |
138
|
|
|
return $this->getParameter('metadata'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function getData() |
142
|
|
|
{ |
143
|
|
|
$this->validate('apiUsername', 'apiKey', 'amount', 'currency'); |
144
|
|
|
|
145
|
|
|
$data = []; |
146
|
|
|
|
147
|
|
|
$data['type'] = $this->getType(); |
148
|
|
|
$data['amount'] = $this->getAmount(); |
149
|
|
|
$data['currency'] = $this->getCurrency(); |
150
|
|
|
$data['storeCard'] = (bool) $this->getStoreCard() ?? false; |
151
|
|
|
$data['callbackUrls'] = []; |
152
|
|
|
|
153
|
|
|
if ( is_array($this->getPaymentMethods()) ) { |
154
|
|
|
$data['methods'] = $this->getPaymentMethods(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if ( is_array($this->getCardTypes()) ) { |
158
|
|
|
$data['cardTypes'] = $this->getCardTypes(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if ( is_array($this->getMetadata()) ) { |
162
|
|
|
$data['metaData'] = $this->getMetadata(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
if ( $this->getMerchantReference() ) { |
166
|
|
|
$data['merchantReference'] = $this->getMerchantReference(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
if ( $this->getReturnUrl() ) { |
170
|
|
|
$data['callbackUrls']['approved'] = $this->getReturnUrl(); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if ( $this->getDeclineUrl() ) { |
174
|
|
|
$data['callbackUrls']['declined'] = $this->getDeclineUrl(); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
if ( $this->getCancelUrl() ) { |
178
|
|
|
$data['callbackUrls']['cancelled'] = $this->getCancelUrl(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
if ( $this->getNotifyUrl() ) { |
182
|
|
|
$data['notificationUrl'] = $this->getNotifyUrl(); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
return $data; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function sendData($data) |
189
|
|
|
{ |
190
|
|
|
$headers = [ |
191
|
|
|
'Accept' => 'application/json', |
192
|
|
|
'Content-Type' => 'application/json', |
193
|
|
|
'Authorization' => 'Basic ' . $this->getAuthorization() |
194
|
|
|
]; |
195
|
|
|
|
196
|
|
|
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint('sessions'), $headers, json_encode($data)); |
197
|
|
|
|
198
|
|
|
try { |
199
|
|
|
$responseData = json_decode($httpResponse->getBody()->getContents()); |
200
|
|
|
} catch (\Exception $exception) { |
201
|
|
|
$responseData = []; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return $this->response = new PurchaseResponse($this, $responseData ?? []); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Get endpoint |
209
|
|
|
* |
210
|
|
|
* Returns endpoint depending on test mode |
211
|
|
|
* |
212
|
|
|
* @access protected |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
protected function getEndpoint($path = '') |
216
|
|
|
{ |
217
|
|
|
return ($this->getTestMode() ? self::endpointTest : self::endpointLive) . '/' . $path; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
protected function getAuthorization() |
221
|
|
|
{ |
222
|
|
|
return base64_encode($this->getApiUsername().':'.$this->getApiKey()); |
223
|
|
|
} |
224
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths