1 | <?php |
||||
2 | |||||
3 | namespace PagOnline\Tran; |
||||
4 | |||||
5 | use PagOnline\BaseIgfsCg; |
||||
6 | use PagOnline\Exceptions\IgfsMissingParException; |
||||
7 | use PagOnline\IgfsUtils; |
||||
8 | use PagOnline\XmlEntities\Entry; |
||||
9 | use SimpleXMLElement; |
||||
10 | |||||
11 | class IgfsCgAuth extends BaseIgfsCgTran |
||||
12 | { |
||||
13 | public $shopUserRef; |
||||
14 | public $shopUserName; |
||||
15 | public $shopUserAccount; |
||||
16 | public $shopUserMobilePhone; |
||||
17 | public $shopUserIMEI; |
||||
18 | public $shopUserIP; |
||||
19 | public $trType = 'AUTH'; |
||||
20 | public $amount; |
||||
21 | public $currencyCode; |
||||
22 | public $langID; |
||||
23 | public $callbackURL; |
||||
24 | public $pan; |
||||
25 | public $payInstrToken; |
||||
26 | public $billingID; |
||||
27 | public $payload; |
||||
28 | public $regenPayInstrToken; |
||||
29 | public $keepOnRegenPayInstrToken; |
||||
30 | public $payInstrTokenExpire; |
||||
31 | public $payInstrTokenUsageLimit; |
||||
32 | public $payInstrTokenAlg; |
||||
33 | public $cvv2; |
||||
34 | public $expireMonth; |
||||
35 | public $expireYear; |
||||
36 | public $accountName; |
||||
37 | public $enrStatus; |
||||
38 | public $authStatus; |
||||
39 | public $cavv; |
||||
40 | public $xid; |
||||
41 | public $level3Info; |
||||
42 | public $description; |
||||
43 | public $paymentReason; |
||||
44 | public $topUpID; |
||||
45 | public $firstTopUp; |
||||
46 | public $payInstrTokenAsTopUpID; |
||||
47 | public $promoCode; |
||||
48 | public $payPassData; |
||||
49 | public $userAgent; |
||||
50 | public $fingerPrint; |
||||
51 | public $validityExpire; |
||||
52 | |||||
53 | public $paymentID; |
||||
54 | public $authCode; |
||||
55 | public $brand; |
||||
56 | public $acquirerID; |
||||
57 | public $maskedPan; |
||||
58 | public $additionalFee; |
||||
59 | public $status; |
||||
60 | public $nssResult; |
||||
61 | public $receiptPdf; |
||||
62 | public $payAddData; |
||||
63 | public $payUserRef; |
||||
64 | /** |
||||
65 | * @var string |
||||
66 | */ |
||||
67 | protected $requestNamespace = Requests\IgfsCgAuthRequest::class; |
||||
68 | |||||
69 | 1 | public function resetFields(): void |
|||
70 | { |
||||
71 | 1 | parent::resetFields(); |
|||
72 | 1 | $this->shopUserRef = null; |
|||
73 | 1 | $this->shopUserName = null; |
|||
74 | 1 | $this->shopUserAccount = null; |
|||
75 | 1 | $this->shopUserMobilePhone = null; |
|||
76 | 1 | $this->shopUserIMEI = null; |
|||
77 | 1 | $this->shopUserIP = null; |
|||
78 | 1 | $this->trType = 'AUTH'; |
|||
79 | 1 | $this->amount = null; |
|||
80 | 1 | $this->currencyCode = null; |
|||
81 | 1 | $this->langID = 'EN'; |
|||
82 | 1 | $this->callbackURL = null; |
|||
83 | 1 | $this->pan = null; |
|||
84 | 1 | $this->payInstrToken = null; |
|||
85 | 1 | $this->billingID = null; |
|||
86 | 1 | $this->payload = null; |
|||
87 | 1 | $this->regenPayInstrToken = null; |
|||
88 | 1 | $this->keepOnRegenPayInstrToken = null; |
|||
89 | 1 | $this->payInstrTokenExpire = null; |
|||
90 | 1 | $this->payInstrTokenUsageLimit = null; |
|||
91 | 1 | $this->payInstrTokenAlg = null; |
|||
92 | 1 | $this->cvv2 = null; |
|||
93 | 1 | $this->expireMonth = null; |
|||
94 | 1 | $this->expireYear = null; |
|||
95 | 1 | $this->accountName = null; |
|||
96 | 1 | $this->enrStatus = null; |
|||
97 | 1 | $this->authStatus = null; |
|||
98 | 1 | $this->cavv = null; |
|||
99 | 1 | $this->xid = null; |
|||
100 | 1 | $this->level3Info = null; |
|||
101 | 1 | $this->description = null; |
|||
102 | 1 | $this->paymentReason = null; |
|||
103 | 1 | $this->topUpID = null; |
|||
104 | 1 | $this->firstTopUp = null; |
|||
105 | 1 | $this->payInstrTokenAsTopUpID = null; |
|||
106 | 1 | $this->promoCode = null; |
|||
107 | 1 | $this->payPassData = null; |
|||
108 | 1 | $this->userAgent = null; |
|||
109 | 1 | $this->fingerPrint = null; |
|||
110 | 1 | $this->validityExpire = null; |
|||
111 | |||||
112 | 1 | $this->paymentID = null; |
|||
113 | 1 | $this->authCode = null; |
|||
114 | 1 | $this->brand = null; |
|||
115 | 1 | $this->acquirerID = null; |
|||
116 | 1 | $this->maskedPan = null; |
|||
117 | 1 | $this->additionalFee = null; |
|||
118 | 1 | $this->status = null; |
|||
119 | 1 | $this->nssResult = null; |
|||
120 | 1 | $this->receiptPdf = null; |
|||
121 | 1 | $this->payAddData = null; |
|||
122 | 1 | $this->payUserRef = null; |
|||
123 | } |
||||
124 | |||||
125 | /** |
||||
126 | * {@inheritdoc} |
||||
127 | */ |
||||
128 | 1 | protected function getAdditionalRequestSignatureFields(): array |
|||
129 | { |
||||
130 | 1 | return [ |
|||
131 | 1 | $this->shopUserRef, // SHOPUSERREF |
|||
132 | 1 | $this->shopUserName, // SHOPUSERNAME |
|||
133 | 1 | $this->shopUserAccount, // SHOPUSERACCOUNT |
|||
134 | 1 | $this->shopUserMobilePhone, //SHOPUSERMOBILEPHONE |
|||
135 | 1 | $this->shopUserIMEI, //SHOPUSERIMEI |
|||
136 | 1 | $this->shopUserIP, // SHOPUSERIP |
|||
137 | 1 | $this->trType, // TRTYPE |
|||
138 | 1 | $this->amount, // AMOUNT |
|||
139 | 1 | $this->currencyCode, // CURRENCYCODE |
|||
140 | 1 | $this->callbackURL, // CALLBACKURL |
|||
141 | 1 | $this->pan, // PAN |
|||
142 | 1 | $this->payInstrToken, // PAYINSTRTOKEN |
|||
143 | 1 | $this->payload, // PAYLOAD |
|||
144 | 1 | $this->cvv2, // CVV2 |
|||
145 | 1 | $this->expireMonth, // EXPIREMONTH |
|||
146 | 1 | $this->expireYear, // EXPIREYEAR |
|||
147 | 1 | $this->addInfo1, // UDF1 |
|||
148 | 1 | $this->addInfo2, // UDF2 |
|||
149 | 1 | $this->addInfo3, // UDF3 |
|||
150 | 1 | $this->addInfo4, // UDF4 |
|||
151 | 1 | $this->addInfo5, // UDF5 |
|||
152 | 1 | $this->topUpID, |
|||
153 | 1 | ]; |
|||
154 | } |
||||
155 | |||||
156 | 6 | protected function checkFields(): void |
|||
157 | { |
||||
158 | 6 | parent::checkFields(); |
|||
159 | 2 | if ($this->trType === null) { |
|||
160 | 1 | throw new IgfsMissingParException('Missing trType'); |
|||
161 | } |
||||
162 | |||||
163 | 1 | if ($this->trType != 'VERIFY') { |
|||
164 | 1 | if ($this->amount == null) { |
|||
165 | throw new IgfsMissingParException('Missing amount'); |
||||
166 | } |
||||
167 | 1 | if ($this->currencyCode == null) { |
|||
168 | throw new IgfsMissingParException('Missing currencyCode'); |
||||
169 | } |
||||
170 | } |
||||
171 | // Disabilitato per pagopoi |
||||
172 | // if ($this->pan == NULL) { |
||||
173 | // if ($this->payInstrToken == NULL) |
||||
174 | // throw new IgfsMissingParException("Missing pan"); |
||||
175 | // } |
||||
176 | 1 | if ($this->pan != null) { |
|||
177 | // Se è stato impostato il pan verifico... |
||||
178 | if ($this->pan == '') { |
||||
179 | throw new IgfsMissingParException('Missing pan'); |
||||
180 | } |
||||
181 | } |
||||
182 | 1 | if ($this->payInstrToken != null) { |
|||
183 | // Se è stato impostato il payInstrToken verifico... |
||||
184 | if ($this->payInstrToken == '') { |
||||
185 | throw new IgfsMissingParException('Missing payInstrToken'); |
||||
186 | } |
||||
187 | } |
||||
188 | 1 | if ($this->level3Info != null) { |
|||
189 | $i = 0; |
||||
190 | if ($this->level3Info->product != null) { |
||||
191 | foreach ($this->level3Info->product as $product) { |
||||
192 | if ($product->productCode == null) { |
||||
193 | throw new IgfsMissingParException('Missing productCode['.$i.']'); |
||||
194 | } |
||||
195 | if ($product->productDescription == null) { |
||||
196 | throw new IgfsMissingParException('Missing productDescription['.$i.']'); |
||||
197 | } |
||||
198 | ++$i; |
||||
199 | } |
||||
200 | } |
||||
201 | } |
||||
202 | } |
||||
203 | |||||
204 | 1 | protected function buildRequest() |
|||
205 | { |
||||
206 | 1 | $request = parent::buildRequest(); |
|||
207 | 1 | $this->replaceRequestParameter($request, 'shopUserRef', $this->shopUserRef); |
|||
208 | 1 | $this->replaceRequestParameter($request, 'shopUserName', $this->shopUserName); |
|||
209 | 1 | $this->replaceRequestParameter($request, 'shopUserAccount', $this->shopUserAccount); |
|||
210 | 1 | $this->replaceRequestParameter($request, 'shopUserMobilePhone', $this->shopUserMobilePhone); |
|||
211 | 1 | $this->replaceRequestParameter($request, 'shopUserIMEI', $this->shopUserIMEI); |
|||
212 | 1 | $this->replaceRequestParameter($request, 'shopUserIP', $this->shopUserIP); |
|||
213 | 1 | $this->replaceRequestParameter($request, 'trType', $this->trType); |
|||
214 | 1 | $this->replaceRequestParameter($request, 'amount', $this->amount); |
|||
215 | 1 | $this->replaceRequestParameter($request, 'currencyCode', $this->currencyCode); |
|||
216 | 1 | $this->replaceRequestParameter($request, 'langID', $this->langID); |
|||
217 | 1 | $this->replaceRequestParameter($request, 'callbackURL', $this->callbackURL); |
|||
218 | 1 | $this->replaceRequestParameter($request, 'pan', $this->pan); |
|||
219 | 1 | $this->replaceRequestParameter($request, 'payInstrToken', $this->payInstrToken); |
|||
220 | 1 | $this->replaceRequestParameter($request, 'billingID', $this->billingID); |
|||
221 | 1 | $this->replaceRequestParameter($request, 'payload', $this->payload); |
|||
222 | 1 | $this->replaceRequestParameter($request, 'regenPayInstrToken', $this->regenPayInstrToken); |
|||
223 | 1 | $this->replaceRequestParameter($request, 'keepOnRegenPayInstrToken', $this->keepOnRegenPayInstrToken); |
|||
224 | 1 | $this->replaceRequestParameter($request, 'payInstrTokenExpire', IgfsUtils::formatXMLGregorianCalendar($this->payInstrTokenExpire)); |
|||
225 | 1 | $this->replaceRequestParameter($request, 'payInstrTokenUsageLimit', $this->payInstrTokenUsageLimit); |
|||
226 | 1 | $this->replaceRequestParameter($request, 'payInstrTokenAlg', $this->payInstrTokenAlg); |
|||
227 | 1 | $this->replaceRequestParameter($request, 'cvv2', $this->cvv2); |
|||
228 | 1 | $this->replaceRequestParameter($request, 'expireMonth', $this->expireMonth); |
|||
229 | 1 | $this->replaceRequestParameter($request, 'expireYear', $this->expireYear); |
|||
230 | 1 | $this->replaceRequestParameter($request, 'accountName', $this->accountName); |
|||
231 | 1 | $this->replaceRequestParameter($request, 'enrStatus', $this->enrStatus); |
|||
232 | 1 | $this->replaceRequestParameter($request, 'authStatus', $this->authStatus); |
|||
233 | 1 | $this->replaceRequestParameter($request, 'cavv', $this->cavv); |
|||
234 | 1 | $this->replaceRequestParameter($request, 'xid', $this->xid); |
|||
235 | 1 | $this->replaceRequestParameter($request, 'description', $this->description); |
|||
236 | 1 | $this->replaceRequestParameter($request, 'paymentReason', $this->paymentReason); |
|||
237 | 1 | $this->replaceRequestParameter($request, 'topUpID', $this->topUpID); |
|||
238 | 1 | $this->replaceRequestParameter($request, 'firstTopUp', $this->firstTopUp); |
|||
239 | 1 | $this->replaceRequestParameter($request, 'payInstrTokenAsTopUpID', $this->payInstrTokenAsTopUpID); |
|||
240 | 1 | $this->replaceRequestParameter($request, 'promoCode', $this->promoCode); |
|||
241 | 1 | $this->replaceRequestParameter($request, 'payPassData', $this->payPassData); |
|||
242 | 1 | $this->replaceRequestParameter($request, 'userAgent', $this->userAgent); |
|||
243 | 1 | $this->replaceRequestParameter($request, 'fingerPrint', $this->fingerPrint); |
|||
244 | 1 | $this->replaceRequestParameter($request, 'validityExpire', IgfsUtils::formatXMLGregorianCalendar($this->validityExpire)); |
|||
245 | |||||
246 | 1 | if ($this->level3Info != null) { |
|||
247 | $this->replaceRequestParameter($request, 'level3Info', $this->level3Info->toXml('level3Info'), false); |
||||
248 | } else { |
||||
249 | 1 | $this->replaceRequestParameter($request, 'level3Info', ''); |
|||
250 | } |
||||
251 | |||||
252 | 1 | return $request; |
|||
253 | } |
||||
254 | |||||
255 | protected function parseResponseMap($response): void |
||||
256 | { |
||||
257 | parent::parseResponseMap($response); |
||||
258 | // Opzionale |
||||
259 | $this->paymentID = IgfsUtils::getValue($response, 'paymentID'); |
||||
260 | // Opzionale |
||||
261 | $this->authCode = IgfsUtils::getValue($response, 'authCode'); |
||||
262 | // Opzionale |
||||
263 | $this->brand = IgfsUtils::getValue($response, 'brand'); |
||||
264 | // Opzionale |
||||
265 | $this->acquirerID = IgfsUtils::getValue($response, 'acquirerID'); |
||||
266 | // Opzionale |
||||
267 | $this->maskedPan = IgfsUtils::getValue($response, 'maskedPan'); |
||||
268 | // Opzionale |
||||
269 | $this->payInstrToken = IgfsUtils::getValue($response, 'payInstrToken'); |
||||
270 | // Opzionale |
||||
271 | $this->additionalFee = IgfsUtils::getValue($response, 'additionalFee'); |
||||
272 | // Opzionale |
||||
273 | $this->status = IgfsUtils::getValue($response, 'status'); |
||||
274 | // Opzionale |
||||
275 | $this->nssResult = IgfsUtils::getValue($response, 'nssResult'); |
||||
276 | // Opzionale |
||||
277 | $this->topUpID = IgfsUtils::getValue($response, 'topUpID'); |
||||
278 | // Opzionale |
||||
279 | $this->payUserRef = IgfsUtils::getValue($response, 'payUserRef'); |
||||
280 | // Opzionale |
||||
281 | $this->shopUserMobilePhone = IgfsUtils::getValue($response, 'shopUserMobilePhone'); |
||||
282 | // Opzionale |
||||
283 | try { |
||||
284 | $this->receiptPdf = \base64_decode(IgfsUtils::getValue($response, 'receiptPdf'), true); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
285 | } catch (\Exception $e) { |
||||
286 | $this->receiptPdf = null; |
||||
287 | } |
||||
288 | |||||
289 | try { |
||||
290 | $xml = $response[BaseIgfsCg::$soapResponseTag]; |
||||
291 | |||||
292 | $xml = \str_replace('<soap:', '<', $xml); |
||||
293 | $xml = \str_replace('</soap:', '</', $xml); |
||||
294 | $dom = new SimpleXMLElement($xml, LIBXML_NOERROR, false); |
||||
295 | if (\count($dom) == 0) { |
||||
296 | return; |
||||
297 | } |
||||
298 | |||||
299 | $tmp = \str_replace('<Body>', '', $dom->Body->asXML()); |
||||
300 | $tmp = \str_replace('</Body>', '', $tmp); |
||||
301 | $dom = new SimpleXMLElement($tmp, LIBXML_NOERROR, false); |
||||
302 | if (\count($dom) == 0) { |
||||
303 | return; |
||||
304 | } |
||||
305 | |||||
306 | $xml_response = IgfsUtils::parseResponseFields($dom->response); |
||||
307 | if (isset($xml_response['payAddData'])) { |
||||
308 | $payAddData = []; |
||||
309 | foreach ($dom->response->children() as $item) { |
||||
310 | if ($item->getName() == 'payAddData') { |
||||
311 | $payAddData[] = Entry::fromXml($item->asXML()); |
||||
0 ignored issues
–
show
It seems like
$item->asXML() can also be of type true ; however, parameter $xml of PagOnline\XmlEntities\BaseXmlEntity::fromXml() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
312 | } |
||||
313 | } |
||||
314 | $this->payAddData = $payAddData; |
||||
315 | } |
||||
316 | } catch (\Exception $e) { |
||||
317 | $this->payAddData = null; |
||||
318 | } |
||||
319 | } |
||||
320 | |||||
321 | /** |
||||
322 | * @param array $response |
||||
323 | * |
||||
324 | * @throws \PagOnline\Exceptions\IgfsException |
||||
325 | * |
||||
326 | * @return string |
||||
327 | */ |
||||
328 | protected function getResponseSignature($response) |
||||
329 | { |
||||
330 | $fields = [ |
||||
331 | IgfsUtils::getValue($response, 'tid'), // TID |
||||
332 | IgfsUtils::getValue($response, 'shopID'), // SHOPID |
||||
333 | IgfsUtils::getValue($response, 'rc'), // RC |
||||
334 | IgfsUtils::getValue($response, 'errorDesc'), // ERRORDESC |
||||
335 | IgfsUtils::getValue($response, 'tranID'), // ORDERID |
||||
336 | IgfsUtils::getValue($response, 'date'), // TRANDATE |
||||
337 | IgfsUtils::getValue($response, 'paymentID'), // PAYMENTID |
||||
338 | IgfsUtils::getValue($response, 'authCode'), // AUTHCODE |
||||
339 | ]; |
||||
340 | // signature dove il buffer e' cosi composto TID|SHOPID|RC|ERRORCODE|ORDERID|PAYMENTID|AUTHCODE |
||||
341 | return $this->getSignature($fields); |
||||
342 | } |
||||
343 | } |
||||
344 |