@@ -11,15 +11,12 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @link http://www.redsys.es/ |
13 | 13 | */ |
14 | -class Gateway extends AbstractGateway |
|
15 | -{ |
|
16 | - public function getName() |
|
17 | - { |
|
14 | +class Gateway extends AbstractGateway { |
|
15 | + public function getName() { |
|
18 | 16 | return 'Redsys'; |
19 | 17 | } |
20 | 18 | |
21 | - public function getDefaultParameters() |
|
22 | - { |
|
19 | + public function getDefaultParameters() { |
|
23 | 20 | return array( |
24 | 21 | 'merchantId' => '', |
25 | 22 | 'merchantName' => '', |
@@ -29,53 +26,43 @@ discard block |
||
29 | 26 | ); |
30 | 27 | } |
31 | 28 | |
32 | - public function getMerchantId() |
|
33 | - { |
|
29 | + public function getMerchantId() { |
|
34 | 30 | return $this->getParameter('merchantId'); |
35 | 31 | } |
36 | 32 | |
37 | - public function setMerchantId($value) |
|
38 | - { |
|
33 | + public function setMerchantId($value) { |
|
39 | 34 | return $this->setParameter('merchantId', $value); |
40 | 35 | } |
41 | 36 | |
42 | - public function getMerchantName() |
|
43 | - { |
|
37 | + public function getMerchantName() { |
|
44 | 38 | return $this->getParameter('merchantName'); |
45 | 39 | } |
46 | 40 | |
47 | - public function setMerchantName($value) |
|
48 | - { |
|
41 | + public function setMerchantName($value) { |
|
49 | 42 | return $this->setParameter('merchantName', $value); |
50 | 43 | } |
51 | 44 | |
52 | - public function getTerminalId() |
|
53 | - { |
|
45 | + public function getTerminalId() { |
|
54 | 46 | return $this->getParameter('terminalId'); |
55 | 47 | } |
56 | 48 | |
57 | - public function setTerminalId($value) |
|
58 | - { |
|
49 | + public function setTerminalId($value) { |
|
59 | 50 | return $this->setParameter('terminalId', $value); |
60 | 51 | } |
61 | 52 | |
62 | - public function getHmacKey() |
|
63 | - { |
|
53 | + public function getHmacKey() { |
|
64 | 54 | return $this->getParameter('hmacKey'); |
65 | 55 | } |
66 | 56 | |
67 | - public function setHmacKey($value) |
|
68 | - { |
|
57 | + public function setHmacKey($value) { |
|
69 | 58 | return $this->setParameter('hmacKey', $value); |
70 | 59 | } |
71 | 60 | |
72 | - public function purchase(array $parameters = array()) |
|
73 | - { |
|
61 | + public function purchase(array $parameters = array()) { |
|
74 | 62 | return $this->createRequest('\Omnipay\Redsys\Message\PurchaseRequest', $parameters); |
75 | 63 | } |
76 | 64 | |
77 | - public function completePurchase(array $parameters = array()) |
|
78 | - { |
|
65 | + public function completePurchase(array $parameters = array()) { |
|
79 | 66 | return $this->createRequest('\Omnipay\Redsys\Message\CompletePurchaseRequest', $parameters); |
80 | 67 | } |
81 | 68 | } |
@@ -11,8 +11,7 @@ discard block |
||
11 | 11 | * This abstract class extends the base Omnipay AbstractResponse in order |
12 | 12 | * to provide some common encoding and decoding functions. |
13 | 13 | */ |
14 | -abstract class AbstractResponse extends BaseAbstractResponse |
|
15 | -{ |
|
14 | +abstract class AbstractResponse extends BaseAbstractResponse { |
|
16 | 15 | /** |
17 | 16 | * Encode merchant parameters |
18 | 17 | * |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * |
21 | 20 | * @return string Encoded data |
22 | 21 | */ |
23 | - protected function encodeMerchantParameters($data) |
|
24 | - { |
|
22 | + protected function encodeMerchantParameters($data) { |
|
25 | 23 | return base64_encode(json_encode($data)); |
26 | 24 | } |
27 | 25 | |
@@ -32,8 +30,7 @@ discard block |
||
32 | 30 | * |
33 | 31 | * @return array Decoded data |
34 | 32 | */ |
35 | - protected function decodeMerchantParameters($data) |
|
36 | - { |
|
33 | + protected function decodeMerchantParameters($data) { |
|
37 | 34 | return (array)json_decode(base64_decode(strtr($data, '-_', '+/'))); |
38 | 35 | } |
39 | 36 | |
@@ -49,8 +46,7 @@ discard block |
||
49 | 46 | * |
50 | 47 | * @throws RuntimeException |
51 | 48 | */ |
52 | - protected function encryptMessage($message, $key) |
|
53 | - { |
|
49 | + protected function encryptMessage($message, $key) { |
|
54 | 50 | $iv = implode(array_map("chr", array(0, 0, 0, 0, 0, 0, 0, 0))); |
55 | 51 | |
56 | 52 | if (function_exists('mcrypt_encrypt')) { |
@@ -73,14 +69,12 @@ discard block |
||
73 | 69 | * |
74 | 70 | * @return string Generated signature |
75 | 71 | */ |
76 | - protected function createSignature($message, $salt, $key) |
|
77 | - { |
|
72 | + protected function createSignature($message, $salt, $key) { |
|
78 | 73 | $ciphertext = $this->encryptMessage($salt, $key); |
79 | 74 | return base64_encode(hash_hmac('sha256', $message, $ciphertext, true)); |
80 | 75 | } |
81 | 76 | |
82 | - protected function createReturnSignature($message, $salt, $key) |
|
83 | - { |
|
77 | + protected function createReturnSignature($message, $salt, $key) { |
|
84 | 78 | return strtr($this->createSignature($message, $salt, $key), '+/', '-_'); |
85 | 79 | } |
86 | 80 | } |
@@ -5,15 +5,12 @@ |
||
5 | 5 | /** |
6 | 6 | * Redsys Complete Purchase Request |
7 | 7 | */ |
8 | -class CompletePurchaseRequest extends PurchaseRequest |
|
9 | -{ |
|
10 | - public function getData() |
|
11 | - { |
|
8 | +class CompletePurchaseRequest extends PurchaseRequest { |
|
9 | + public function getData() { |
|
12 | 10 | return $this->httpRequest->request->all(); |
13 | 11 | } |
14 | 12 | |
15 | - public function sendData($data) |
|
16 | - { |
|
13 | + public function sendData($data) { |
|
17 | 14 | return $this->response = new CompletePurchaseResponse($this, $data); |
18 | 15 | } |
19 | 16 | } |
@@ -8,8 +8,7 @@ discard block |
||
8 | 8 | /** |
9 | 9 | * Redsys Complete Purchase Response |
10 | 10 | */ |
11 | -class CompletePurchaseResponse extends AbstractResponse |
|
12 | -{ |
|
11 | +class CompletePurchaseResponse extends AbstractResponse { |
|
13 | 12 | /** @var array */ |
14 | 13 | protected $merchantParameters; |
15 | 14 | /** @var string */ |
@@ -27,8 +26,7 @@ discard block |
||
27 | 26 | * |
28 | 27 | * @throws InvalidResponseException If order number is missing or signature does not match |
29 | 28 | */ |
30 | - public function __construct(RequestInterface $request, $data) |
|
31 | - { |
|
29 | + public function __construct(RequestInterface $request, $data) { |
|
32 | 30 | parent::__construct($request, $data); |
33 | 31 | |
34 | 32 | if (!empty($data['Ds_MerchantParameters'])) { |
@@ -65,8 +63,7 @@ discard block |
||
65 | 63 | * |
66 | 64 | * @return boolean |
67 | 65 | */ |
68 | - public function isSuccessful() |
|
69 | - { |
|
66 | + public function isSuccessful() { |
|
70 | 67 | $key = $this->usingUpcaseParameters ? 'DS_RESPONSE' : 'Ds_Response'; |
71 | 68 | return isset($this->merchantParameters[$key]) |
72 | 69 | && is_numeric($this->merchantParameters[$key]) |
@@ -79,8 +76,7 @@ discard block |
||
79 | 76 | * |
80 | 77 | * @return mixed |
81 | 78 | */ |
82 | - public function getData() |
|
83 | - { |
|
79 | + public function getData() { |
|
84 | 80 | $data = parent::getData(); |
85 | 81 | return is_array($data) && is_array($this->merchantParameters) |
86 | 82 | ? array_merge($data, $this->merchantParameters) |
@@ -92,8 +88,7 @@ discard block |
||
92 | 88 | * |
93 | 89 | * @return null|mixed |
94 | 90 | */ |
95 | - protected function getKey($key) |
|
96 | - { |
|
91 | + protected function getKey($key) { |
|
97 | 92 | if ($this->usingUpcaseParameters) { |
98 | 93 | $key = strtoupper($key); |
99 | 94 | } |
@@ -105,8 +100,7 @@ discard block |
||
105 | 100 | * |
106 | 101 | * @return null|string |
107 | 102 | */ |
108 | - public function getTransactionReference() |
|
109 | - { |
|
103 | + public function getTransactionReference() { |
|
110 | 104 | return $this->getKey('Ds_AuthorisationCode'); |
111 | 105 | } |
112 | 106 | |
@@ -115,8 +109,7 @@ discard block |
||
115 | 109 | * |
116 | 110 | * @return null|string |
117 | 111 | */ |
118 | - public function getMessage() |
|
119 | - { |
|
112 | + public function getMessage() { |
|
120 | 113 | return $this->getKey('Ds_Response'); |
121 | 114 | } |
122 | 115 | |
@@ -125,8 +118,7 @@ discard block |
||
125 | 118 | * |
126 | 119 | * @return null|string |
127 | 120 | */ |
128 | - public function getCardType() |
|
129 | - { |
|
121 | + public function getCardType() { |
|
130 | 122 | return $this->getKey('Ds_Card_Type'); |
131 | 123 | } |
132 | 124 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Redsys Purchase Request |
9 | 9 | */ |
10 | -class PurchaseRequest extends AbstractRequest |
|
11 | -{ |
|
10 | +class PurchaseRequest extends AbstractRequest { |
|
12 | 11 | protected $liveEndpoint = 'https://sis.redsys.es/sis/realizarPago'; |
13 | 12 | protected $testEndpoint = 'https://sis-t.redsys.es:25443/sis/realizarPago'; |
14 | 13 | protected static $consumerLanguages = array( |
@@ -26,18 +25,15 @@ discard block |
||
26 | 25 | 'eu' => '013', // Basque |
27 | 26 | ); |
28 | 27 | |
29 | - public function getCardholder() |
|
30 | - { |
|
28 | + public function getCardholder() { |
|
31 | 29 | return $this->getParameter('cardholder'); |
32 | 30 | } |
33 | 31 | |
34 | - public function setCardholder($value) |
|
35 | - { |
|
32 | + public function setCardholder($value) { |
|
36 | 33 | return $this->setParameter('cardholder', $value); |
37 | 34 | } |
38 | 35 | |
39 | - public function getConsumerLanguage() |
|
40 | - { |
|
36 | + public function getConsumerLanguage() { |
|
41 | 37 | return $this->getParameter('consumerLanguage'); |
42 | 38 | } |
43 | 39 | |
@@ -46,8 +42,7 @@ discard block |
||
46 | 42 | * |
47 | 43 | * @param string|int Either the ISO 639-1 code to be converted, or the gateway's own numeric language code |
48 | 44 | */ |
49 | - public function setConsumerLanguage($value) |
|
50 | - { |
|
45 | + public function setConsumerLanguage($value) { |
|
51 | 46 | if (is_int($value)) { |
52 | 47 | if ($value < 0 || $value > 13) { |
53 | 48 | $value = 1; |
@@ -60,53 +55,43 @@ discard block |
||
60 | 55 | return $this->setParameter('consumerLanguage', $value); |
61 | 56 | } |
62 | 57 | |
63 | - public function getHmacKey() |
|
64 | - { |
|
58 | + public function getHmacKey() { |
|
65 | 59 | return $this->getParameter('hmacKey'); |
66 | 60 | } |
67 | 61 | |
68 | - public function setHmacKey($value) |
|
69 | - { |
|
62 | + public function setHmacKey($value) { |
|
70 | 63 | return $this->setParameter('hmacKey', $value); |
71 | 64 | } |
72 | 65 | |
73 | - public function getMerchantData() |
|
74 | - { |
|
66 | + public function getMerchantData() { |
|
75 | 67 | return $this->getParameter('merchantData'); |
76 | 68 | } |
77 | 69 | |
78 | - public function setMerchantData($value) |
|
79 | - { |
|
70 | + public function setMerchantData($value) { |
|
80 | 71 | return $this->setParameter('merchantData', $value); |
81 | 72 | } |
82 | 73 | |
83 | - public function getMerchantId() |
|
84 | - { |
|
74 | + public function getMerchantId() { |
|
85 | 75 | return $this->getParameter('merchantId'); |
86 | 76 | } |
87 | 77 | |
88 | - public function setMerchantId($value) |
|
89 | - { |
|
78 | + public function setMerchantId($value) { |
|
90 | 79 | return $this->setParameter('merchantId', $value); |
91 | 80 | } |
92 | 81 | |
93 | - public function getMerchantName() |
|
94 | - { |
|
82 | + public function getMerchantName() { |
|
95 | 83 | return $this->getParameter('merchantName'); |
96 | 84 | } |
97 | 85 | |
98 | - public function setMerchantName($value) |
|
99 | - { |
|
86 | + public function setMerchantName($value) { |
|
100 | 87 | return $this->setParameter('merchantName', $value); |
101 | 88 | } |
102 | 89 | |
103 | - public function getTerminalId() |
|
104 | - { |
|
90 | + public function getTerminalId() { |
|
105 | 91 | return $this->getParameter('terminalId'); |
106 | 92 | } |
107 | 93 | |
108 | - public function setTerminalId($value) |
|
109 | - { |
|
94 | + public function setTerminalId($value) { |
|
110 | 95 | return $this->setParameter('terminalId', $value); |
111 | 96 | } |
112 | 97 | |
@@ -115,8 +100,7 @@ discard block |
||
115 | 100 | * |
116 | 101 | * @param string|int $value The transaction ID (merchant order) to set for the transaction |
117 | 102 | */ |
118 | - public function setTransactionId($value) |
|
119 | - { |
|
103 | + public function setTransactionId($value) { |
|
120 | 104 | $start = substr($value, 0, 4); |
121 | 105 | $numerics = 0; |
122 | 106 | foreach (str_split($start) as $char) { |
@@ -131,8 +115,7 @@ discard block |
||
131 | 115 | parent::setTransactionId($value); |
132 | 116 | } |
133 | 117 | |
134 | - public function getData() |
|
135 | - { |
|
118 | + public function getData() { |
|
136 | 119 | $this->validate('merchantId', 'terminalId', 'amount', 'currency'); |
137 | 120 | |
138 | 121 | return array( |
@@ -155,13 +138,11 @@ discard block |
||
155 | 138 | ); |
156 | 139 | } |
157 | 140 | |
158 | - public function sendData($data) |
|
159 | - { |
|
141 | + public function sendData($data) { |
|
160 | 142 | return $this->response = new PurchaseResponse($this, $data); |
161 | 143 | } |
162 | 144 | |
163 | - public function getEndpoint() |
|
164 | - { |
|
145 | + public function getEndpoint() { |
|
165 | 146 | return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; |
166 | 147 | } |
167 | 148 | } |
@@ -7,32 +7,26 @@ |
||
7 | 7 | /** |
8 | 8 | * Redsys Purchase Response |
9 | 9 | */ |
10 | -class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface |
|
11 | -{ |
|
10 | +class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface { |
|
12 | 11 | protected $version = 'HMAC_SHA256_V1'; |
13 | 12 | |
14 | - public function isSuccessful() |
|
15 | - { |
|
13 | + public function isSuccessful() { |
|
16 | 14 | return false; |
17 | 15 | } |
18 | 16 | |
19 | - public function isRedirect() |
|
20 | - { |
|
17 | + public function isRedirect() { |
|
21 | 18 | return true; |
22 | 19 | } |
23 | 20 | |
24 | - public function getRedirectUrl() |
|
25 | - { |
|
21 | + public function getRedirectUrl() { |
|
26 | 22 | return $this->getRequest()->getEndpoint(); |
27 | 23 | } |
28 | 24 | |
29 | - public function getRedirectMethod() |
|
30 | - { |
|
25 | + public function getRedirectMethod() { |
|
31 | 26 | return 'POST'; |
32 | 27 | } |
33 | 28 | |
34 | - public function getRedirectData() |
|
35 | - { |
|
29 | + public function getRedirectData() { |
|
36 | 30 | $redirect_data = array(); |
37 | 31 | $redirect_data['Ds_SignatureVersion'] = $this->version; |
38 | 32 | $redirect_data['Ds_MerchantParameters'] = $this->encodeMerchantParameters($this->data); |