1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PagOnline\Init; |
4
|
|
|
|
5
|
|
|
use PagOnline\Exceptions\IgfsMissingParException; |
6
|
|
|
use PagOnline\IgfsUtils; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class IgfsCgInit. |
10
|
|
|
*/ |
11
|
|
|
class IgfsCgInit extends BaseIgfsCgInit |
12
|
|
|
{ |
13
|
|
|
public $shopUserRef; |
14
|
|
|
public $shopUserName; |
15
|
|
|
public $shopUserAccount; |
16
|
|
|
public $shopUserMobilePhone; |
17
|
|
|
public $shopUserIMEI; |
18
|
|
|
public $trType = 'AUTH'; |
19
|
|
|
public $amount; |
20
|
|
|
public $currencyCode; |
21
|
|
|
public $langID = 'EN'; |
22
|
|
|
public $notifyURL; |
23
|
|
|
public $errorURL; |
24
|
|
|
public $callbackURL; |
25
|
|
|
public $addInfo1; |
26
|
|
|
public $addInfo2; |
27
|
|
|
public $addInfo3; |
28
|
|
|
public $addInfo4; |
29
|
|
|
public $addInfo5; |
30
|
|
|
public $payInstrToken; |
31
|
|
|
public $billingID; |
32
|
|
|
public $regenPayInstrToken; |
33
|
|
|
public $keepOnRegenPayInstrToken; |
34
|
|
|
public $payInstrTokenExpire; |
35
|
|
|
public $payInstrTokenUsageLimit; |
36
|
|
|
public $payInstrTokenAlg; |
37
|
|
|
public $accountName; |
38
|
|
|
public $level3Info; |
39
|
|
|
public $mandateInfo; |
40
|
|
|
public $description; |
41
|
|
|
public $paymentReason; |
42
|
|
|
public $topUpID; |
43
|
|
|
public $firstTopUp; |
44
|
|
|
public $payInstrTokenAsTopUpID; |
45
|
|
|
public $validityExpire; |
46
|
|
|
public $minExpireMonth; |
47
|
|
|
public $minExpireYear; |
48
|
|
|
public $termInfo; |
49
|
|
|
|
50
|
|
|
public $paymentID; |
51
|
|
|
public $redirectURL; |
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected $requestNamespace = Requests\IgfsCgInitRequest::class; |
56
|
|
|
|
57
|
7 |
|
public function resetFields() |
58
|
|
|
{ |
59
|
7 |
|
parent::resetFields(); |
60
|
7 |
|
$this->shopUserRef = null; |
61
|
7 |
|
$this->shopUserName = null; |
62
|
7 |
|
$this->shopUserAccount = null; |
63
|
7 |
|
$this->shopUserMobilePhone = null; |
64
|
7 |
|
$this->shopUserIMEI = null; |
65
|
7 |
|
$this->trType = 'AUTH'; |
66
|
7 |
|
$this->amount = null; |
67
|
7 |
|
$this->currencyCode = null; |
68
|
7 |
|
$this->langID = 'EN'; |
69
|
7 |
|
$this->notifyURL = null; |
70
|
7 |
|
$this->errorURL = null; |
71
|
7 |
|
$this->callbackURL = null; |
72
|
7 |
|
$this->addInfo1 = null; |
73
|
7 |
|
$this->addInfo2 = null; |
74
|
7 |
|
$this->addInfo3 = null; |
75
|
7 |
|
$this->addInfo4 = null; |
76
|
7 |
|
$this->addInfo5 = null; |
77
|
7 |
|
$this->payInstrToken = null; |
78
|
7 |
|
$this->billingID = null; |
79
|
7 |
|
$this->regenPayInstrToken = null; |
80
|
7 |
|
$this->keepOnRegenPayInstrToken = null; |
81
|
7 |
|
$this->payInstrTokenExpire = null; |
82
|
7 |
|
$this->payInstrTokenUsageLimit = null; |
83
|
7 |
|
$this->payInstrTokenAlg = null; |
84
|
7 |
|
$this->accountName = null; |
85
|
7 |
|
$this->level3Info = null; |
86
|
7 |
|
$this->mandateInfo = null; |
87
|
7 |
|
$this->description = null; |
88
|
7 |
|
$this->paymentReason = null; |
89
|
7 |
|
$this->topUpID = null; |
90
|
7 |
|
$this->firstTopUp = null; |
91
|
7 |
|
$this->payInstrTokenAsTopUpID = null; |
92
|
7 |
|
$this->validityExpire = null; |
93
|
7 |
|
$this->minExpireMonth = null; |
94
|
7 |
|
$this->minExpireYear = null; |
95
|
7 |
|
$this->termInfo = null; |
96
|
|
|
|
97
|
7 |
|
$this->paymentID = null; |
98
|
7 |
|
$this->redirectURL = null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritdoc} |
103
|
|
|
*/ |
104
|
7 |
|
protected function getAdditionalRequestSignatureFields(): array |
105
|
|
|
{ |
106
|
7 |
|
return [ |
107
|
7 |
|
$this->shopUserRef, // SHOPUSERREF |
108
|
7 |
|
$this->shopUserName, // SHOPUSERNAME |
109
|
7 |
|
$this->shopUserAccount, // SHOPUSERACCOUNT |
110
|
7 |
|
$this->shopUserMobilePhone, //SHOPUSERMOBILEPHONE |
111
|
7 |
|
$this->shopUserIMEI, //SHOPUSERIMEI |
112
|
7 |
|
$this->trType, // TRTYPE |
113
|
7 |
|
$this->amount, // AMOUNT |
114
|
7 |
|
$this->currencyCode, // CURRENCYCODE |
115
|
7 |
|
$this->langID, // LANGID |
116
|
7 |
|
$this->notifyURL, // NOTIFYURL |
117
|
7 |
|
$this->errorURL, // ERRORURL |
118
|
7 |
|
$this->callbackURL, // CALLBACKURL |
119
|
7 |
|
$this->addInfo1, // UDF1 |
120
|
7 |
|
$this->addInfo2, // UDF2 |
121
|
7 |
|
$this->addInfo3, // UDF3 |
122
|
7 |
|
$this->addInfo4, // UDF4 |
123
|
7 |
|
$this->addInfo5, // UDF5 |
124
|
7 |
|
$this->payInstrToken, // PAYINSTRTOKEN |
125
|
7 |
|
$this->topUpID, |
126
|
7 |
|
]; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @throws IgfsMissingParException |
131
|
|
|
*/ |
132
|
20 |
|
protected function checkFields() |
133
|
|
|
{ |
134
|
20 |
|
parent::checkFields(); |
135
|
|
|
|
136
|
16 |
|
if ($this->trType === null) { |
137
|
1 |
|
throw new IgfsMissingParException('Missing trType'); |
138
|
|
|
} |
139
|
|
|
|
140
|
15 |
|
if ($this->langID === null) { |
141
|
1 |
|
throw new IgfsMissingParException('Missing langID'); |
142
|
|
|
} |
143
|
|
|
|
144
|
14 |
|
if ($this->notifyURL === null) { |
145
|
1 |
|
throw new IgfsMissingParException('Missing notifyURL'); |
146
|
|
|
} |
147
|
|
|
|
148
|
13 |
|
if ($this->errorURL === null) { |
149
|
1 |
|
throw new IgfsMissingParException('Missing errorURL'); |
150
|
|
|
} |
151
|
|
|
|
152
|
12 |
|
if ($this->payInstrToken !== null && $this->payInstrToken === '') { |
153
|
|
|
// Se è stato impostato il payInstrToken verifico... |
154
|
1 |
|
throw new IgfsMissingParException('Missing payInstrToken'); |
155
|
|
|
} |
156
|
|
|
|
157
|
11 |
|
if ($this->level3Info !== null) { |
158
|
6 |
|
if (!empty($this->level3Info->product) && \is_array($this->level3Info->product)) { |
159
|
3 |
|
foreach ($this->level3Info->product as $i => $product) { |
160
|
3 |
|
if (empty($product->productCode)) { |
161
|
1 |
|
throw new IgfsMissingParException("Missing productCode[{$i}]"); |
162
|
|
|
} |
163
|
2 |
|
if (empty($product->productDescription)) { |
164
|
1 |
|
throw new IgfsMissingParException("Missing productDescription[{$i}]"); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
170
|
9 |
|
if (!empty($this->mandateInfo) && empty($this->mandateInfo->mandateID)) { |
171
|
2 |
|
throw new IgfsMissingParException('Missing mandateID'); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return false|mixed|string |
177
|
|
|
*/ |
178
|
7 |
|
protected function buildRequest() |
179
|
|
|
{ |
180
|
7 |
|
$request = parent::buildRequest(); |
181
|
7 |
|
$this->replaceRequestParameter($request, 'notifyURL', $this->notifyURL); |
182
|
7 |
|
$this->replaceRequestParameter($request, 'errorURL', $this->errorURL); |
183
|
7 |
|
$this->replaceRequestParameter($request, 'shopUserRef', $this->shopUserRef); |
184
|
7 |
|
$this->replaceRequestParameter($request, 'shopUserName', $this->shopUserName); |
185
|
7 |
|
$this->replaceRequestParameter($request, 'shopUserAccount', $this->shopUserAccount); |
186
|
7 |
|
$this->replaceRequestParameter($request, 'shopUserMobilePhone', $this->shopUserMobilePhone); |
187
|
7 |
|
$this->replaceRequestParameter($request, 'shopUserIMEI', $this->shopUserIMEI); |
188
|
7 |
|
$this->replaceRequestParameter($request, 'trType', $this->trType); |
189
|
7 |
|
$this->replaceRequestParameter($request, 'amount', $this->amount); |
190
|
7 |
|
$this->replaceRequestParameter($request, 'currencyCode', $this->currencyCode); |
191
|
7 |
|
$this->replaceRequestParameter($request, 'langID', $this->langID); |
192
|
7 |
|
$this->replaceRequestParameter($request, 'callbackURL', $this->callbackURL); |
193
|
7 |
|
$this->replaceRequestParameter($request, 'addInfo1', $this->addInfo1); |
194
|
7 |
|
$this->replaceRequestParameter($request, 'addInfo2', $this->addInfo2); |
195
|
7 |
|
$this->replaceRequestParameter($request, 'addInfo3', $this->addInfo3); |
196
|
7 |
|
$this->replaceRequestParameter($request, 'addInfo4', $this->addInfo4); |
197
|
7 |
|
$this->replaceRequestParameter($request, 'addInfo5', $this->addInfo5); |
198
|
7 |
|
$this->replaceRequestParameter($request, 'payInstrToken', $this->payInstrToken); |
199
|
7 |
|
$this->replaceRequestParameter($request, 'billingID', $this->billingID); |
200
|
7 |
|
$this->replaceRequestParameter($request, 'regenPayInstrToken', $this->regenPayInstrToken); |
201
|
7 |
|
$this->replaceRequestParameter($request, 'keepOnRegenPayInstrToken', $this->keepOnRegenPayInstrToken); |
202
|
7 |
|
$this->replaceRequestParameter($request, 'payInstrTokenExpire', IgfsUtils::formatXMLGregorianCalendar($this->payInstrTokenExpire)); |
203
|
7 |
|
$this->replaceRequestParameter($request, 'payInstrTokenUsageLimit', $this->payInstrTokenUsageLimit); |
204
|
7 |
|
$this->replaceRequestParameter($request, 'payInstrTokenAlg', $this->payInstrTokenAlg); |
205
|
7 |
|
$this->replaceRequestParameter($request, 'accountName', $this->accountName); |
206
|
7 |
|
$this->replaceRequestParameter($request, 'description', $this->description); |
207
|
7 |
|
$this->replaceRequestParameter($request, 'paymentReason', $this->paymentReason); |
208
|
7 |
|
$this->replaceRequestParameter($request, 'topUpID', $this->topUpID); |
209
|
7 |
|
$this->replaceRequestParameter($request, 'firstTopUp', $this->firstTopUp); |
210
|
7 |
|
$this->replaceRequestParameter($request, 'payInstrTokenAsTopUpID', $this->payInstrTokenAsTopUpID); |
211
|
7 |
|
$this->replaceRequestParameter($request, 'validityExpire', IgfsUtils::formatXMLGregorianCalendar($this->validityExpire)); |
212
|
7 |
|
$this->replaceRequestParameter($request, 'minExpireMonth', $this->minExpireMonth); |
213
|
7 |
|
$this->replaceRequestParameter($request, 'minExpireYear', $this->minExpireYear); |
214
|
|
|
|
215
|
7 |
|
if ($this->level3Info != null) { |
216
|
1 |
|
$this->replaceRequestParameter($request, 'level3Info', $this->level3Info->toXml('level3Info'), false); |
217
|
|
|
} else { |
218
|
7 |
|
$this->replaceRequestParameter($request, 'level3Info', ''); |
219
|
|
|
} |
220
|
|
|
|
221
|
7 |
|
if ($this->mandateInfo != null) { |
222
|
1 |
|
$this->replaceRequestParameter($request, 'mandateInfo', $this->level3Info->toXml('mandateInfo'), false); |
223
|
|
|
} else { |
224
|
7 |
|
$this->replaceRequestParameter($request, 'mandateInfo', ''); |
225
|
|
|
} |
226
|
|
|
|
227
|
7 |
|
if ($this->termInfo != null) { |
228
|
1 |
|
$sb = ''; |
229
|
1 |
|
foreach ($this->termInfo as $item) { |
230
|
1 |
|
$sb .= $item->toXml('termInfo'); |
231
|
|
|
} |
232
|
1 |
|
$this->replaceRequestParameter($request, 'termInfo', $sb, false); |
233
|
|
|
} else { |
234
|
7 |
|
$this->replaceRequestParameter($request, 'termInfo', ''); |
235
|
|
|
} |
236
|
|
|
|
237
|
7 |
|
return $request; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param array $response |
242
|
|
|
*/ |
243
|
3 |
|
protected function parseResponseMap($response) |
244
|
|
|
{ |
245
|
3 |
|
parent::parseResponseMap($response); |
246
|
|
|
// Opzionale |
247
|
3 |
|
$this->paymentID = IgfsUtils::getValue($response, 'paymentID'); |
248
|
|
|
// Opzionale |
249
|
3 |
|
$this->redirectURL = IgfsUtils::getValue($response, 'redirectURL'); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @param array $response |
254
|
|
|
* |
255
|
|
|
* @throws \PagOnline\Exceptions\IgfsException |
256
|
|
|
* |
257
|
|
|
* @return string |
258
|
|
|
*/ |
259
|
1 |
|
protected function getResponseSignature($response) |
260
|
|
|
{ |
261
|
1 |
|
$fields = [ |
262
|
1 |
|
IgfsUtils::getValue($response, 'tid'), // TID |
263
|
1 |
|
IgfsUtils::getValue($response, 'shopID'), // SHOPID |
264
|
1 |
|
IgfsUtils::getValue($response, 'rc'), // RC |
265
|
1 |
|
IgfsUtils::getValue($response, 'errorDesc'), // ERRORDESC |
266
|
1 |
|
IgfsUtils::getValue($response, 'paymentID'), // PAYMENTID |
267
|
1 |
|
IgfsUtils::getValue($response, 'redirectURL'), // REDIRECTURL |
268
|
1 |
|
]; |
269
|
|
|
// signature dove il buffer e' cosi composto TID|SHOPID|RC|ERRORDESC|PAYMENTID|REDIRECTURL |
270
|
1 |
|
return $this->getSignature($fields); |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|