1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PagOnline\Tran; |
4
|
|
|
|
5
|
|
|
use PagOnline\Exceptions\IgfsMissingParException; |
6
|
|
|
use PagOnline\IgfsUtils; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class IgfsCgCredit. |
10
|
|
|
*/ |
11
|
|
|
class IgfsCgCredit extends BaseIgfsCgTran |
12
|
|
|
{ |
13
|
|
|
public $shopUserRef; |
14
|
|
|
public $amount; |
15
|
|
|
public $currencyCode; |
16
|
|
|
public $refTranID; |
17
|
|
|
public $pan; |
18
|
|
|
public $payInstrToken; |
19
|
|
|
public $billingID; |
20
|
|
|
public $expireMonth; |
21
|
|
|
public $expireYear; |
22
|
|
|
public $description; |
23
|
|
|
|
24
|
|
|
public $pendingAmount; |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $requestNamespace = Requests\IgfsCgCreditRequest::class; |
29
|
|
|
|
30
|
1 |
|
public function resetFields(): void |
31
|
|
|
{ |
32
|
1 |
|
parent::resetFields(); |
33
|
1 |
|
$this->shopUserRef = null; |
34
|
1 |
|
$this->amount = null; |
35
|
1 |
|
$this->currencyCode = null; |
36
|
1 |
|
$this->refTranID = null; |
37
|
1 |
|
$this->pan = null; |
38
|
1 |
|
$this->payInstrToken = null; |
39
|
1 |
|
$this->billingID = null; |
40
|
1 |
|
$this->expireMonth = null; |
41
|
1 |
|
$this->expireYear = null; |
42
|
1 |
|
$this->description = null; |
43
|
|
|
|
44
|
1 |
|
$this->pendingAmount = null; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
1 |
|
protected function getAdditionalRequestSignatureFields(): array |
51
|
|
|
{ |
52
|
1 |
|
return [ |
53
|
1 |
|
$this->shopUserRef, // SHOPUSERREF |
54
|
1 |
|
$this->amount, // AMOUNT |
55
|
1 |
|
$this->currencyCode, // CURRENCYCODE |
56
|
1 |
|
$this->refTranID, // REFORDERID |
57
|
1 |
|
$this->pan, // PAN |
58
|
1 |
|
$this->payInstrToken, // PAYINSTRTOKEN |
59
|
1 |
|
$this->expireMonth, // EXPIREMONTH |
60
|
1 |
|
$this->expireYear, // EXPIREYEAR |
61
|
1 |
|
$this->addInfo1, // UDF1 |
62
|
1 |
|
$this->addInfo2, // UDF2 |
63
|
1 |
|
$this->addInfo3, // UDF3 |
64
|
1 |
|
$this->addInfo4, // UDF4 |
65
|
1 |
|
$this->addInfo5, // UDF5 |
66
|
1 |
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
6 |
|
protected function checkFields(): void |
70
|
|
|
{ |
71
|
6 |
|
parent::checkFields(); |
72
|
1 |
|
if ($this->amount == null) { |
73
|
|
|
throw new IgfsMissingParException('Missing amount'); |
74
|
|
|
} |
75
|
1 |
|
if ($this->refTranID === null && $this->pan === null && $this->payInstrToken === null) { |
76
|
|
|
throw new IgfsMissingParException('Missing refTranID'); |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
if ($this->pan !== null && $this->pan === '') { |
80
|
|
|
// Se è stato impostato il pan verifico... |
81
|
|
|
throw new IgfsMissingParException('Missing pan'); |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
if ($this->payInstrToken !== null && $this->payInstrToken === '') { |
85
|
|
|
throw new IgfsMissingParException('Missing payInstrToken'); |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
if (($this->pan !== null || $this->payInstrToken !== null) && $this->currencyCode === null) { |
89
|
|
|
throw new IgfsMissingParException('Missing currencyCode'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
1 |
|
protected function buildRequest() |
94
|
|
|
{ |
95
|
1 |
|
$request = parent::buildRequest(); |
96
|
1 |
|
$this->replaceRequestParameter($request, 'shopUserRef', $this->shopUserRef); |
97
|
1 |
|
$this->replaceRequestParameter($request, 'amount', $this->amount); |
98
|
1 |
|
$this->replaceRequestParameter($request, 'currencyCode', $this->currencyCode); |
99
|
1 |
|
$this->replaceRequestParameter($request, 'refTranID', $this->refTranID); |
100
|
1 |
|
$this->replaceRequestParameter($request, 'pan', $this->pan); |
101
|
1 |
|
$this->replaceRequestParameter($request, 'payInstrToken', $this->payInstrToken); |
102
|
1 |
|
$this->replaceRequestParameter($request, 'billingID', $this->billingID); |
103
|
1 |
|
$this->replaceRequestParameter($request, 'expireMonth', $this->expireMonth); |
104
|
1 |
|
$this->replaceRequestParameter($request, 'expireYear', $this->expireYear); |
105
|
1 |
|
$this->replaceRequestParameter($request, 'description', $this->description); |
106
|
|
|
|
107
|
1 |
|
return $request; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
protected function parseResponseMap($response): void |
111
|
|
|
{ |
112
|
|
|
parent::parseResponseMap($response); |
113
|
|
|
// Opzionale |
114
|
|
|
$this->pendingAmount = IgfsUtils::getValue($response, 'pendingAmount'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
protected function getResponseSignature($response): string |
118
|
|
|
{ |
119
|
|
|
$fields = [ |
120
|
|
|
IgfsUtils::getValue($response, 'tid'), // TID |
121
|
|
|
IgfsUtils::getValue($response, 'shopID'), // SHOPID |
122
|
|
|
IgfsUtils::getValue($response, 'rc'), // RC |
123
|
|
|
IgfsUtils::getValue($response, 'errorDesc'), // ERRORDESC |
124
|
|
|
IgfsUtils::getValue($response, 'tranID'), // ORDERID |
125
|
|
|
IgfsUtils::getValue($response, 'date'), // TRANDATE |
126
|
|
|
IgfsUtils::getValue($response, 'addInfo1'), // UDF1 |
127
|
|
|
IgfsUtils::getValue($response, 'addInfo2'), // UDF2 |
128
|
|
|
IgfsUtils::getValue($response, 'addInfo3'), // UDF3 |
129
|
|
|
IgfsUtils::getValue($response, 'addInfo4'), // UDF4 |
130
|
|
|
IgfsUtils::getValue($response, 'addInfo5'), // UDF5 |
131
|
|
|
]; |
132
|
|
|
// signature dove il buffer e' cosi composto TID|SHOPID|RC|ERRORDESC|ORDERID|DATE|UDF1|UDF2|UDF3|UDF4|UDF5 |
133
|
|
|
return $this->getSignature($fields); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|