@@ -7,8 +7,7 @@ discard block |
||
| 7 | 7 | /** |
| 8 | 8 | * Redsys Webservice Purchase Request |
| 9 | 9 | */ |
| 10 | -class WebservicePurchaseRequest extends PurchaseRequest |
|
| 11 | -{ |
|
| 10 | +class WebservicePurchaseRequest extends PurchaseRequest { |
|
| 12 | 11 | /** @var string */ |
| 13 | 12 | protected $liveWsdl = __DIR__ . "/redsys-webservice-live.wsdl"; |
| 14 | 13 | /** @var string */ |
@@ -18,8 +17,7 @@ discard block |
||
| 18 | 17 | /** @var string */ |
| 19 | 18 | protected $testEndpoint = "https://sis-t.redsys.es:25443/sis/services/SerClsWSEntrada"; |
| 20 | 19 | |
| 21 | - public function getData() |
|
| 22 | - { |
|
| 20 | + public function getData() { |
|
| 23 | 21 | $this->validate('merchantId', 'terminalId', 'amount', 'currency', 'card'); |
| 24 | 22 | $card = $this->getCard(); |
| 25 | 23 | // @todo given test card doesn't validate? |
@@ -63,8 +61,7 @@ discard block |
||
| 63 | 61 | // ); |
| 64 | 62 | } |
| 65 | 63 | |
| 66 | - public function sendData($data) |
|
| 67 | - { |
|
| 64 | + public function sendData($data) { |
|
| 68 | 65 | |
| 69 | 66 | // @todo either use SOAP client here, or wrap in soap yourself and just guzzle it |
| 70 | 67 | /* |
@@ -8,10 +8,8 @@ discard block |
||
| 8 | 8 | /** |
| 9 | 9 | * Redsys Purchase Response |
| 10 | 10 | */ |
| 11 | -class WebservicePurchaseResponse extends AbstractResponse |
|
| 12 | -{ |
|
| 13 | - public function isSuccessful() |
|
| 14 | - { |
|
| 11 | +class WebservicePurchaseResponse extends AbstractResponse { |
|
| 12 | + public function isSuccessful() { |
|
| 15 | 13 | // check for field existence as well as value |
| 16 | 14 | return !empty($this->data->CODIGO) |
| 17 | 15 | && $this->data->CODIGO == '0' |
@@ -21,14 +19,12 @@ discard block |
||
| 21 | 19 | } |
| 22 | 20 | |
| 23 | 21 | // @todo Other methods required for abstract response |
| 24 | - public function getTransactionReference() |
|
| 25 | - { |
|
| 22 | + public function getTransactionReference() { |
|
| 26 | 23 | return "WOOT"; |
| 27 | 24 | } |
| 28 | 25 | |
| 29 | 26 | // @todo Switch to just returning the error code (no message supplied in package) |
| 30 | - public function getMessage() |
|
| 31 | - { |
|
| 27 | + public function getMessage() { |
|
| 32 | 28 | if ($this->data instanceof SimpleXMLElement) { |
| 33 | 29 | $out = $this->data->asXML(); |
| 34 | 30 | } else { |
@@ -13,8 +13,7 @@ discard block |
||
| 13 | 13 | * encryption methods are provided later, the VERSION const can be |
| 14 | 14 | * switched to a constructor option (and validated against a whitelist). |
| 15 | 15 | */ |
| 16 | -class Security |
|
| 17 | -{ |
|
| 16 | +class Security { |
|
| 18 | 17 | /** @var string */ |
| 19 | 18 | const VERSION = 'HMAC_SHA256_V1'; |
| 20 | 19 | |
@@ -25,8 +24,7 @@ discard block |
||
| 25 | 24 | * |
| 26 | 25 | * @return string Encoded data |
| 27 | 26 | */ |
| 28 | - public function encodeMerchantParameters($data) |
|
| 29 | - { |
|
| 27 | + public function encodeMerchantParameters($data) { |
|
| 30 | 28 | return base64_encode(json_encode($data)); |
| 31 | 29 | } |
| 32 | 30 | |
@@ -37,8 +35,7 @@ discard block |
||
| 37 | 35 | * |
| 38 | 36 | * @return array Decoded data |
| 39 | 37 | */ |
| 40 | - public function decodeMerchantParameters($data) |
|
| 41 | - { |
|
| 38 | + public function decodeMerchantParameters($data) { |
|
| 42 | 39 | return (array)json_decode(base64_decode(strtr($data, '-_', '+/'))); |
| 43 | 40 | } |
| 44 | 41 | |
@@ -52,8 +49,7 @@ discard block |
||
| 52 | 49 | * |
| 53 | 50 | * @throws RuntimeException |
| 54 | 51 | */ |
| 55 | - protected function encryptMessage($message, $key) |
|
| 56 | - { |
|
| 52 | + protected function encryptMessage($message, $key) { |
|
| 57 | 53 | $iv = implode(array_map('chr', array(0, 0, 0, 0, 0, 0, 0, 0))); |
| 58 | 54 | |
| 59 | 55 | if ($this->hasValidEncryptionMethod()) { |
@@ -72,8 +68,7 @@ discard block |
||
| 72 | 68 | * |
| 73 | 69 | * @return bool |
| 74 | 70 | */ |
| 75 | - public function hasValidEncryptionMethod() |
|
| 76 | - { |
|
| 71 | + public function hasValidEncryptionMethod() { |
|
| 77 | 72 | return function_exists('mcrypt_encrypt'); |
| 78 | 73 | } |
| 79 | 74 | |
@@ -88,14 +83,12 @@ discard block |
||
| 88 | 83 | * |
| 89 | 84 | * @return string Generated signature |
| 90 | 85 | */ |
| 91 | - public function createSignature($message, $salt, $key) |
|
| 92 | - { |
|
| 86 | + public function createSignature($message, $salt, $key) { |
|
| 93 | 87 | $ciphertext = $this->encryptMessage($salt, $key); |
| 94 | 88 | return base64_encode(hash_hmac('sha256', $message, $ciphertext, true)); |
| 95 | 89 | } |
| 96 | 90 | |
| 97 | - public function createReturnSignature($message, $salt, $key) |
|
| 98 | - { |
|
| 91 | + public function createReturnSignature($message, $salt, $key) { |
|
| 99 | 92 | return strtr($this->createSignature($message, $salt, $key), '+/', '-_'); |
| 100 | 93 | } |
| 101 | 94 | } |
@@ -7,30 +7,24 @@ |
||
| 7 | 7 | /** |
| 8 | 8 | * Redsys Purchase Response |
| 9 | 9 | */ |
| 10 | -class PurchaseResponse extends AbstractResponse |
|
| 11 | -{ |
|
| 12 | - public function isSuccessful() |
|
| 13 | - { |
|
| 10 | +class PurchaseResponse extends AbstractResponse { |
|
| 11 | + public function isSuccessful() { |
|
| 14 | 12 | return false; |
| 15 | 13 | } |
| 16 | 14 | |
| 17 | - public function isRedirect() |
|
| 18 | - { |
|
| 15 | + public function isRedirect() { |
|
| 19 | 16 | return true; |
| 20 | 17 | } |
| 21 | 18 | |
| 22 | - public function getRedirectUrl() |
|
| 23 | - { |
|
| 19 | + public function getRedirectUrl() { |
|
| 24 | 20 | return $this->getRequest()->getEndpoint(); |
| 25 | 21 | } |
| 26 | 22 | |
| 27 | - public function getRedirectMethod() |
|
| 28 | - { |
|
| 23 | + public function getRedirectMethod() { |
|
| 29 | 24 | return 'POST'; |
| 30 | 25 | } |
| 31 | 26 | |
| 32 | - public function getRedirectData() |
|
| 33 | - { |
|
| 27 | + public function getRedirectData() { |
|
| 34 | 28 | return $this->data; |
| 35 | 29 | } |
| 36 | 30 | } |
@@ -11,15 +11,12 @@ discard block |
||
| 11 | 11 | * |
| 12 | 12 | * @link http://www.redsys.es/ |
| 13 | 13 | */ |
| 14 | -class RedirectGateway extends AbstractGateway |
|
| 15 | -{ |
|
| 16 | - public function getName() |
|
| 17 | - { |
|
| 14 | +class RedirectGateway extends AbstractGateway { |
|
| 15 | + public function getName() { |
|
| 18 | 16 | return 'Redsys Redirect'; |
| 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,15 +11,12 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @link http://www.redsys.es/ |
| 13 | 13 | */ |
| 14 | -class WebserviceGateway extends RedirectGateway |
|
| 15 | -{ |
|
| 16 | - public function getName() |
|
| 17 | - { |
|
| 14 | +class WebserviceGateway extends RedirectGateway { |
|
| 15 | + public function getName() { |
|
| 18 | 16 | return 'Redsys Webservice'; |
| 19 | 17 | } |
| 20 | 18 | |
| 21 | - public function purchase(array $parameters = array()) |
|
| 22 | - { |
|
| 19 | + public function purchase(array $parameters = array()) { |
|
| 23 | 20 | return $this->createRequest('\Omnipay\Redsys\Message\WebservicePurchaseRequest', $parameters); |
| 24 | 21 | } |
| 25 | 22 | } |