|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Marlon Ogone package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Marlon BVBA <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Ogone; |
|
12
|
|
|
|
|
13
|
|
|
use InvalidArgumentException; |
|
14
|
|
|
|
|
15
|
|
|
abstract class AbstractResponse implements Response |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Available Ogone parameters |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $ogoneFields = array('AAVADDRESS', 'AAVCHECK', 'AAVZIP', 'ACCEPTANCE', 'ALIAS', 'AMOUNT', 'BIN', 'BRAND', 'CARDNO', 'CCCTY', 'CN', |
|
23
|
|
|
'COMPLUS', 'CREATION_STATUS', 'CURRENCY', 'CVC', 'CVCCHECK', 'DCC_COMMPERCENTAGE', 'DCC_CONVAMOUNT', 'DCC_CONVCCY', 'DCC_EXCHRATE', 'DCC_EXCHRATESOURCE', |
|
24
|
|
|
'DCC_EXCHRATETS', 'DCC_INDICATOR', 'DCC_MARGINPERCENTAGE', 'DCC_VALIDHOURS', 'DIGESTCARDNO', 'ECI', 'ED', 'ENCCARDNO', 'IP', 'IPCTY', |
|
25
|
|
|
'NBREMAILUSAGE','NBRIPUSAGE', 'NBRIPUSAGE_ALLTX', 'NBRUSAGE', 'NCERROR', 'NCERRORCN', 'NCERRORCARDNO', 'NCERRORCVC', 'NCERRORED', 'NCSTATUS', 'ORDERID', |
|
26
|
|
|
'PAYID', 'PM', 'SCO_CATEGORY', 'SCORING', 'STATUS', 'SUBSCRIPTION_ID', 'TRXDATE','VC'); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $parameters; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $shaSign; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param array $httpRequest Typically $_REQUEST |
|
40
|
|
|
* @throws \InvalidArgumentException |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(array $httpRequest) |
|
43
|
|
|
{ |
|
44
|
|
|
// use uppercase internally |
|
45
|
|
|
$httpRequest = array_change_key_case($httpRequest, CASE_UPPER); |
|
46
|
|
|
|
|
47
|
|
|
// set sha sign |
|
48
|
|
|
$this->shaSign = $this->extractShaSign($httpRequest); |
|
49
|
|
|
|
|
50
|
|
|
// filter request for Ogone parameters |
|
51
|
|
|
$this->parameters = $this->filterRequestParameters($httpRequest); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Filter http request parameters |
|
56
|
|
|
* @param array $requestParameters |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function filterRequestParameters(array $requestParameters) |
|
60
|
|
|
{ |
|
61
|
|
|
// filter request for Ogone parameters |
|
62
|
|
|
return array_intersect_key($requestParameters, array_flip($this->ogoneFields)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Set Ogone SHA sign |
|
67
|
|
|
* @param array $parameters |
|
68
|
|
|
* @throws \InvalidArgumentException |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function extractShaSign(array $parameters) |
|
71
|
|
|
{ |
|
72
|
|
|
if (!array_key_exists(self::SHASIGN_FIELD, $parameters) || $parameters[self::SHASIGN_FIELD] == '') { |
|
73
|
|
|
throw new InvalidArgumentException('SHASIGN parameter not present in parameters.'); |
|
74
|
|
|
} |
|
75
|
|
|
return $parameters[self::SHASIGN_FIELD]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Retrieves a response parameter |
|
80
|
|
|
* @param string $key |
|
81
|
|
|
* @throws \InvalidArgumentException |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getParam($key) |
|
84
|
|
|
{ |
|
85
|
|
|
if (method_exists($this, 'get'.$key)) { |
|
86
|
|
|
return $this->{'get'.$key}(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
// always use uppercase |
|
90
|
|
|
$key = strtoupper($key); |
|
91
|
|
|
|
|
92
|
|
|
if (!array_key_exists($key, $this->parameters)) { |
|
93
|
|
|
throw new InvalidArgumentException('Parameter ' . $key . ' does not exist.'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $this->parameters[$key]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Get all parameters + SHASIGN |
|
101
|
|
|
* @return array |
|
102
|
|
|
*/ |
|
103
|
|
|
public function toArray() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->parameters + array('SHASIGN' => $this->shaSign); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|