1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PagOnline\Init; |
4
|
|
|
|
5
|
|
|
use PagOnline\Exceptions\IgfsException; |
6
|
|
|
use PagOnline\Exceptions\IgfsMissingParException; |
7
|
|
|
use PagOnline\IgfsUtils; |
8
|
|
|
use PagOnline\XmlEntities\Init\SelectorTerminalInfo; |
9
|
|
|
|
10
|
|
|
class IgfsCgSelector extends BaseIgfsCgInit |
11
|
|
|
{ |
12
|
|
|
public $shopUserRef; |
13
|
|
|
public $trType = 'AUTH'; |
14
|
|
|
public $amount; |
15
|
|
|
public $currencyCode; |
16
|
|
|
public $langID = 'EN'; |
17
|
|
|
public $addInfo1; |
18
|
|
|
public $addInfo2; |
19
|
|
|
public $addInfo3; |
20
|
|
|
public $addInfo4; |
21
|
|
|
public $addInfo5; |
22
|
|
|
public $payInstrToken; |
23
|
|
|
public $billingID; |
24
|
|
|
|
25
|
|
|
public $termInfo; |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $requestNamespace = Requests\IgfsCgSelectorRequest::class; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
1 |
|
public function resetFields() |
35
|
|
|
{ |
36
|
1 |
|
parent::resetFields(); |
37
|
1 |
|
$this->shopUserRef = null; |
38
|
1 |
|
$this->trType = 'AUTH'; |
39
|
1 |
|
$this->amount = null; |
40
|
1 |
|
$this->currencyCode = null; |
41
|
1 |
|
$this->langID = 'EN'; |
42
|
1 |
|
$this->addInfo1 = null; |
43
|
1 |
|
$this->addInfo2 = null; |
44
|
1 |
|
$this->addInfo3 = null; |
45
|
1 |
|
$this->addInfo4 = null; |
46
|
1 |
|
$this->addInfo5 = null; |
47
|
1 |
|
$this->payInstrToken = null; |
48
|
1 |
|
$this->billingID = null; |
49
|
|
|
|
50
|
1 |
|
$this->termInfo = null; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
1 |
|
protected function getAdditionalRequestSignatureFields(): array |
57
|
|
|
{ |
58
|
1 |
|
return [ |
59
|
1 |
|
$this->shopUserRef, // SHOPUSERREF |
60
|
1 |
|
$this->trType, // TRTYPE |
61
|
1 |
|
$this->amount, // AMOUNT |
62
|
1 |
|
$this->currencyCode, // CURRENCYCODE |
63
|
1 |
|
$this->langID, // LANGID |
64
|
1 |
|
$this->addInfo1, // UDF1 |
65
|
1 |
|
$this->addInfo2, // UDF2 |
66
|
1 |
|
$this->addInfo3, // UDF3 |
67
|
1 |
|
$this->addInfo4, // UDF4 |
68
|
1 |
|
$this->addInfo5, // UDF5 |
69
|
1 |
|
$this->payInstrToken, |
70
|
1 |
|
]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @throws IgfsMissingParException |
75
|
|
|
*/ |
76
|
10 |
|
protected function checkFields() |
77
|
|
|
{ |
78
|
10 |
|
parent::checkFields(); |
79
|
7 |
|
if ($this->trType == null) { |
80
|
1 |
|
throw new IgfsMissingParException('Missing trType'); |
81
|
|
|
} |
82
|
6 |
|
if ($this->trType != 'TOKENIZE') { |
83
|
5 |
|
if ($this->amount == null) { |
84
|
2 |
|
throw new IgfsMissingParException('Missing amount'); |
85
|
|
|
} |
86
|
3 |
|
if ($this->currencyCode == null) { |
87
|
1 |
|
throw new IgfsMissingParException('Missing currencyCode'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
3 |
|
if ($this->langID == null) { |
91
|
1 |
|
throw new IgfsMissingParException('Missing langID'); |
92
|
|
|
} |
93
|
|
|
|
94
|
2 |
|
if (empty($this->payInstrToken)) { |
95
|
1 |
|
throw new IgfsMissingParException('Missing payInstrToken'); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
protected function buildRequest() |
100
|
|
|
{ |
101
|
1 |
|
$request = parent::buildRequest(); |
102
|
1 |
|
$this->replaceRequestParameter($request, 'shopUserRef', $this->shopUserRef); |
103
|
1 |
|
$this->replaceRequestParameter($request, 'trType', $this->trType); |
104
|
1 |
|
$this->replaceRequestParameter($request, 'amount', $this->amount); |
105
|
1 |
|
$this->replaceRequestParameter($request, 'currencyCode', $this->currencyCode); |
106
|
1 |
|
$this->replaceRequestParameter($request, 'langID', $this->langID); |
107
|
1 |
|
$this->replaceRequestParameter($request, 'addInfo1', $this->addInfo1); |
108
|
1 |
|
$this->replaceRequestParameter($request, 'addInfo2', $this->addInfo2); |
109
|
1 |
|
$this->replaceRequestParameter($request, 'addInfo3', $this->addInfo3); |
110
|
1 |
|
$this->replaceRequestParameter($request, 'addInfo4', $this->addInfo4); |
111
|
1 |
|
$this->replaceRequestParameter($request, 'addInfo5', $this->addInfo5); |
112
|
1 |
|
$this->replaceRequestParameter($request, 'payInstrToken', $this->payInstrToken); |
113
|
1 |
|
$this->replaceRequestParameter($request, 'billingID', $this->billingID); |
114
|
|
|
|
115
|
1 |
|
return $request; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param array $response |
120
|
|
|
*/ |
121
|
|
|
protected function parseResponseMap($response) |
122
|
|
|
{ |
123
|
|
|
parent::parseResponseMap($response); |
124
|
|
|
|
125
|
|
|
try { |
126
|
|
|
$responseNode = $this->responseXmlToObject($response[static::$soapResponseTag]); |
127
|
|
|
if ($responseNode === null || $responseNode->children()->count() === 0) { |
128
|
|
|
return; |
129
|
|
|
} |
130
|
|
|
$termInfos = $responseNode->xpath('//termInfo'); |
131
|
|
|
if (\count($termInfos) > 0) { |
132
|
|
|
$this->termInfo = []; |
133
|
|
|
foreach ($termInfos as $item) { |
134
|
|
|
\array_push($this->termInfo, SelectorTerminalInfo::fromXml($item->asXML())); |
|
|
|
|
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} catch (\Exception $e) { |
138
|
|
|
$this->termInfo = null; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param array $response |
144
|
|
|
* |
145
|
|
|
* @throws IgfsException |
146
|
|
|
* |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
|
|
protected function getResponseSignature($response) |
150
|
|
|
{ |
151
|
|
|
$fields = [ |
152
|
|
|
IgfsUtils::getValue($response, 'tid'), // TID |
153
|
|
|
IgfsUtils::getValue($response, 'shopID'), // SHOPID |
154
|
|
|
IgfsUtils::getValue($response, 'rc'), // RC |
155
|
|
|
IgfsUtils::getValue($response, 'errorDesc'), // ERRORDESC |
156
|
|
|
]; |
157
|
|
|
// signature dove il buffer e' cosi composto TID|SHOPID|RC|ERRORDESC|PAYMENTID|REDIRECTURL |
158
|
|
|
return $this->getSignature($fields); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|