From 4daf2f7a57d7f1589309823f03577e9bde0674f1 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Tue, 31 May 2016 09:40:05 +0100 Subject: [PATCH 01/29] Added ability to change endpoint urls --- src/Omnipay/Realex/Message/AuthRequest.php | 8 +++++-- .../Realex/Message/CreateCardRequest.php | 8 +++++-- .../Realex/Message/CreateCustomerRequest.php | 8 +++++-- .../Realex/Message/DeleteCardRequest.php | 7 ++++-- .../Realex/Message/EnrolmentRequest.php | 6 ++++- .../Message/FetchTransactionRequest.php | 7 ++++-- src/Omnipay/Realex/Message/RefundRequest.php | 7 ++++-- .../Realex/Message/SavedAuthRequest.php | 8 +++++-- .../Realex/Message/UpdateCardRequest.php | 8 ++++--- .../Realex/Message/UpdateCustomerRequest.php | 8 ++++--- .../Realex/Message/VerifySigRequest.php | 9 ++++---- src/Omnipay/Realex/Message/VoidRequest.php | 8 ++++--- src/Omnipay/Realex/RemoteGateway.php | 23 +++++++++++++++++++ 13 files changed, 87 insertions(+), 28 deletions(-) diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index 5e224f8..86944d7 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -10,7 +10,7 @@ */ class AuthRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; +// protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; public function getCavv() { @@ -161,6 +161,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('AuthEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/CreateCardRequest.php b/src/Omnipay/Realex/Message/CreateCardRequest.php index a3eeb71..b1d89c4 100644 --- a/src/Omnipay/Realex/Message/CreateCardRequest.php +++ b/src/Omnipay/Realex/Message/CreateCardRequest.php @@ -9,7 +9,7 @@ class CreateCardRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; +// protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; public function getCustomerRef() { @@ -97,6 +97,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('AuthEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/CreateCustomerRequest.php b/src/Omnipay/Realex/Message/CreateCustomerRequest.php index d98bb98..39cb55c 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/CreateCustomerRequest.php @@ -8,7 +8,7 @@ class CreateCustomerRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; +// protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; public function getCustomerRef() { @@ -119,6 +119,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('AuthEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/DeleteCardRequest.php b/src/Omnipay/Realex/Message/DeleteCardRequest.php index 51f9c76..0d463b0 100644 --- a/src/Omnipay/Realex/Message/DeleteCardRequest.php +++ b/src/Omnipay/Realex/Message/DeleteCardRequest.php @@ -9,7 +9,6 @@ class DeleteCardRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; public function getCustomerRef() { @@ -71,6 +70,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('AuthEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/EnrolmentRequest.php b/src/Omnipay/Realex/Message/EnrolmentRequest.php index a2acc6a..2d167b7 100644 --- a/src/Omnipay/Realex/Message/EnrolmentRequest.php +++ b/src/Omnipay/Realex/Message/EnrolmentRequest.php @@ -122,6 +122,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('3DSecureEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('3DSecureEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/FetchTransactionRequest.php b/src/Omnipay/Realex/Message/FetchTransactionRequest.php index d9e741b..d022919 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionRequest.php +++ b/src/Omnipay/Realex/Message/FetchTransactionRequest.php @@ -9,7 +9,6 @@ */ class FetchTransactionRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; /** * Get the XML registration string to be sent to the gateway @@ -69,6 +68,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('3DSecureEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('3DSecureEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/RefundRequest.php b/src/Omnipay/Realex/Message/RefundRequest.php index 12930e1..be10d7a 100644 --- a/src/Omnipay/Realex/Message/RefundRequest.php +++ b/src/Omnipay/Realex/Message/RefundRequest.php @@ -9,7 +9,6 @@ */ class RefundRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; public function getTransactionReference() { @@ -138,6 +137,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('AuthEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index dfb98a5..985c4e1 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -10,7 +10,7 @@ */ class SavedAuthRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; +// protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; public function getCavv() { @@ -154,6 +154,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('SecureDataVaultEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/UpdateCardRequest.php b/src/Omnipay/Realex/Message/UpdateCardRequest.php index 80d4c93..6245b18 100644 --- a/src/Omnipay/Realex/Message/UpdateCardRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCardRequest.php @@ -9,8 +9,6 @@ class UpdateCardRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; - public function getCustomerRef() { return $this->getParameter('customerRef'); @@ -97,6 +95,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('SecureDataVaultEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php index f06b110..9f9d7d3 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php @@ -8,8 +8,6 @@ class UpdateCustomerRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; - public function getCustomerRef() { return $this->getParameter('customerRef'); @@ -119,6 +117,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('SecureDataVaultEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/VerifySigRequest.php b/src/Omnipay/Realex/Message/VerifySigRequest.php index c590cf7..efcd026 100644 --- a/src/Omnipay/Realex/Message/VerifySigRequest.php +++ b/src/Omnipay/Realex/Message/VerifySigRequest.php @@ -11,9 +11,6 @@ */ class VerifySigRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; - - /** * Decode our previously-encoded Merchant Data * @@ -126,7 +123,11 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('SecureDataVaultEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); } /** diff --git a/src/Omnipay/Realex/Message/VoidRequest.php b/src/Omnipay/Realex/Message/VoidRequest.php index 95feb05..434fbf6 100644 --- a/src/Omnipay/Realex/Message/VoidRequest.php +++ b/src/Omnipay/Realex/Message/VoidRequest.php @@ -9,8 +9,6 @@ */ class VoidRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; - public function getTransactionReference() { return $this->getParameter('pasRef'); @@ -97,6 +95,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->endpoint; + return $this->getParameter('SecureDataVaultEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); } } diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index 56a8eb9..b39ea4e 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -150,4 +150,27 @@ public function updateCustomer(array $parameters = array()) { return $this->createRequest('\Omnipay\Realex\Message\UpdateCustomerRequest', $parameters); } + + /** + * Setup service endpoint links for different realex service providers + */ + public function setAuthEndpoint($value){ + return $this->setParameter('AuthEndpoint', $value); + } + public function getAuthEndpoint(){ + return $this->getParameter('AuthEndpoint'); + } + public function setSecureDataVaultEndpoint($value){ + return $this->setParameter('SecureDataVaultEndpoint', $value); + } + public function getSecureDataVaultEndpoint(){ + return $this->getParameter('SecureDataVaultEndpoint'); + } + public function set3DSecureEndpoint($value){ + return $this->setParameter('3DSecureEndpoint', $value); + } + public function get3DSecureEndpoint(){ + return $this->getParameter('3DSecureEndpoint'); + } + } From 49d9807b85be6e7ded77e02ac4fa4408c651dd21 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Tue, 31 May 2016 09:49:49 +0100 Subject: [PATCH 02/29] changed opening brace to new lines --- src/Omnipay/Realex/RemoteGateway.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index b39ea4e..ba2f0ef 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -154,22 +154,28 @@ public function updateCustomer(array $parameters = array()) /** * Setup service endpoint links for different realex service providers */ - public function setAuthEndpoint($value){ + public function setAuthEndpoint($value) + { return $this->setParameter('AuthEndpoint', $value); } - public function getAuthEndpoint(){ + public function getAuthEndpoint() + { return $this->getParameter('AuthEndpoint'); } - public function setSecureDataVaultEndpoint($value){ + public function setSecureDataVaultEndpoint($value) + { return $this->setParameter('SecureDataVaultEndpoint', $value); } - public function getSecureDataVaultEndpoint(){ + public function getSecureDataVaultEndpoint() + { return $this->getParameter('SecureDataVaultEndpoint'); } - public function set3DSecureEndpoint($value){ + public function set3DSecureEndpoint($value) + { return $this->setParameter('3DSecureEndpoint', $value); } - public function get3DSecureEndpoint(){ + public function get3DSecureEndpoint() + { return $this->getParameter('3DSecureEndpoint'); } From 4b467bcabbda715a3432711897516f9d403a93a5 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Tue, 31 May 2016 09:53:50 +0100 Subject: [PATCH 03/29] updated closing brace position --- src/Omnipay/Realex/RemoteGateway.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index ba2f0ef..b081fa8 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -158,25 +158,29 @@ public function setAuthEndpoint($value) { return $this->setParameter('AuthEndpoint', $value); } + public function getAuthEndpoint() { return $this->getParameter('AuthEndpoint'); } + public function setSecureDataVaultEndpoint($value) { return $this->setParameter('SecureDataVaultEndpoint', $value); } + public function getSecureDataVaultEndpoint() { return $this->getParameter('SecureDataVaultEndpoint'); } + public function set3DSecureEndpoint($value) { return $this->setParameter('3DSecureEndpoint', $value); } + public function get3DSecureEndpoint() { return $this->getParameter('3DSecureEndpoint'); } - } From d6d40eed70473f0f8abf70bf339130849e161397 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Thu, 2 Jun 2016 08:46:57 +0100 Subject: [PATCH 04/29] Added Realex PayandShop.com default values --- src/Omnipay/Realex/RemoteGateway.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index b081fa8..d003744 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -25,7 +25,10 @@ public function getDefaultParameters() 'merchantId' => '', 'account' => '', 'secret' => '', - '3dSecure' => 0 + '3dSecure' => 0, + 'authEndpoint'=>'https://epage.payandshop.com/epage-remote.cgi', + 'secureDataVaultEndpoint'=>'https://epage.payandshop.com/epage-remote-plugins.cgi', + '3DSecureEndpoint'=>'https://epage.payandshop.com/epage-3dsecure.cgi' ); } From 31cf30bc501928ede173919f3654f8d304465aba Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Mon, 6 Jun 2016 07:20:27 +0100 Subject: [PATCH 05/29] changed formatting and removed comments --- src/Omnipay/Realex/Message/AuthRequest.php | 1 - src/Omnipay/Realex/Message/CreateCardRequest.php | 3 +-- src/Omnipay/Realex/Message/CreateCustomerRequest.php | 3 +-- src/Omnipay/Realex/Message/DeleteCardRequest.php | 2 +- src/Omnipay/Realex/Message/EnrolmentRequest.php | 5 ++--- src/Omnipay/Realex/Message/FetchTransactionRequest.php | 4 ++-- src/Omnipay/Realex/RemoteGateway.php | 6 +++--- 7 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index 86944d7..06c8c7f 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -10,7 +10,6 @@ */ class AuthRequest extends RemoteAbstractRequest { -// protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; public function getCavv() { diff --git a/src/Omnipay/Realex/Message/CreateCardRequest.php b/src/Omnipay/Realex/Message/CreateCardRequest.php index b1d89c4..acc8dc5 100644 --- a/src/Omnipay/Realex/Message/CreateCardRequest.php +++ b/src/Omnipay/Realex/Message/CreateCardRequest.php @@ -9,7 +9,6 @@ class CreateCardRequest extends RemoteAbstractRequest { -// protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; public function getCustomerRef() { @@ -97,7 +96,7 @@ protected function createResponse($data) public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); + return $this->getParameter('AuthEndpoint'); } public function setAuthEndpoint($value) { diff --git a/src/Omnipay/Realex/Message/CreateCustomerRequest.php b/src/Omnipay/Realex/Message/CreateCustomerRequest.php index 39cb55c..d6b1a00 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/CreateCustomerRequest.php @@ -8,7 +8,6 @@ class CreateCustomerRequest extends RemoteAbstractRequest { -// protected $endpoint = 'https://epage.payandshop.com/epage-remote-plugins.cgi'; public function getCustomerRef() { @@ -119,7 +118,7 @@ protected function createResponse($data) public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); + return $this->getParameter('AuthEndpoint'); } public function setAuthEndpoint($value) { diff --git a/src/Omnipay/Realex/Message/DeleteCardRequest.php b/src/Omnipay/Realex/Message/DeleteCardRequest.php index 0d463b0..6870008 100644 --- a/src/Omnipay/Realex/Message/DeleteCardRequest.php +++ b/src/Omnipay/Realex/Message/DeleteCardRequest.php @@ -70,7 +70,7 @@ protected function createResponse($data) public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); + return $this->getParameter('AuthEndpoint'); } public function setAuthEndpoint($value) { diff --git a/src/Omnipay/Realex/Message/EnrolmentRequest.php b/src/Omnipay/Realex/Message/EnrolmentRequest.php index 2d167b7..c0246fc 100644 --- a/src/Omnipay/Realex/Message/EnrolmentRequest.php +++ b/src/Omnipay/Realex/Message/EnrolmentRequest.php @@ -9,7 +9,6 @@ */ class EnrolmentRequest extends RemoteAbstractRequest { - protected $endpoint = 'https://epage.payandshop.com/epage-3dsecure.cgi'; /** * Get the XML registration string to be sent to the gateway @@ -122,10 +121,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->getParameter('3DSecureEndpoint'); + return $this->getParameter('3dSecureEndpoint'); } public function setAuthEndpoint($value) { - return $this->setParameter('3DSecureEndpoint', $value); + return $this->setParameter('3dSecureEndpoint', $value); } } diff --git a/src/Omnipay/Realex/Message/FetchTransactionRequest.php b/src/Omnipay/Realex/Message/FetchTransactionRequest.php index d022919..8aee7d6 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionRequest.php +++ b/src/Omnipay/Realex/Message/FetchTransactionRequest.php @@ -68,10 +68,10 @@ protected function createResponse($data) public function getEndpoint() { - return $this->getParameter('3DSecureEndpoint'); + return $this->getParameter('3dSecureEndpoint'); } public function setAuthEndpoint($value) { - return $this->setParameter('3DSecureEndpoint', $value); + return $this->setParameter('3dSecureEndpoint', $value); } } diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index d003744..fcce86e 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -28,7 +28,7 @@ public function getDefaultParameters() '3dSecure' => 0, 'authEndpoint'=>'https://epage.payandshop.com/epage-remote.cgi', 'secureDataVaultEndpoint'=>'https://epage.payandshop.com/epage-remote-plugins.cgi', - '3DSecureEndpoint'=>'https://epage.payandshop.com/epage-3dsecure.cgi' + '3dSecureEndpoint'=>'https://epage.payandshop.com/epage-3dsecure.cgi' ); } @@ -179,11 +179,11 @@ public function getSecureDataVaultEndpoint() public function set3DSecureEndpoint($value) { - return $this->setParameter('3DSecureEndpoint', $value); + return $this->setParameter('3dSecureEndpoint', $value); } public function get3DSecureEndpoint() { - return $this->getParameter('3DSecureEndpoint'); + return $this->getParameter('3dSecureEndpoint'); } } From ec574a35e947452accf1f9070ea7db7728077831 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Mon, 11 Jul 2016 15:31:44 +0100 Subject: [PATCH 06/29] removed commented line --- src/Omnipay/Realex/Message/SavedAuthRequest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index 985c4e1..53b8baf 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -10,7 +10,6 @@ */ class SavedAuthRequest extends RemoteAbstractRequest { -// protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; public function getCavv() { From 4a8f35b1a0aa7fa6a86a293d65b4042482136bdf Mon Sep 17 00:00:00 2001 From: istvanfodor Date: Fri, 7 Oct 2016 12:01:35 +0100 Subject: [PATCH 07/29] xml text node coding problem bugfix --- src/Omnipay/Realex/Message/AuthRequest.php | 42 +++++++++++------ .../Realex/Message/CreateCardRequest.php | 30 ++++++++----- .../Realex/Message/CreateCustomerRequest.php | 45 ++++++++++++------- .../Realex/Message/DeleteCardRequest.php | 12 +++-- .../Realex/Message/EnrolmentRequest.php | 33 +++++++++----- .../Message/FetchTransactionRequest.php | 12 +++-- src/Omnipay/Realex/Message/RefundRequest.php | 27 ++++++----- .../Realex/Message/SavedAuthRequest.php | 36 ++++++++++----- .../Realex/Message/UpdateCardRequest.php | 30 ++++++++----- .../Realex/Message/UpdateCustomerRequest.php | 45 ++++++++++++------- .../Realex/Message/VerifySigRequest.php | 30 ++++++++----- src/Omnipay/Realex/Message/VoidRequest.php | 18 +++++--- 12 files changed, 238 insertions(+), 122 deletions(-) diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index 06c8c7f..33058c7 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -72,19 +72,23 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account - $merchantEl = $domTree->createElement('account', $this->getAccount()); + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid', $orderId); + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); // amount - $amountEl = $domTree->createElement('amount', $amount); + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); $amountEl->setAttribute('currency', $this->getCurrency()); $root->appendChild($amountEl); @@ -96,21 +100,26 @@ public function getData() // Card details $cardEl = $domTree->createElement('card'); - $cardNumberEl = $domTree->createElement('number', $card->getNumber()); + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($cardNumberEl); - $expiryEl = $domTree->createElement('expdate', $card->getExpiryDate("my")); // mmyy + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expiryEl); - $cardTypeEl = $domTree->createElement('type', $this->getCardBrand()); + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($cardTypeEl); - $cardNameEl = $domTree->createElement('chname', $card->getBillingName()); + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($cardNameEl); $cvnEl = $domTree->createElement('cvn'); - $cvnNumberEl = $domTree->createElement('number', $card->getCvv()); + $cvnNumberEl = $domTree->createElement('number'); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); $cvnEl->appendChild($cvnNumberEl); $presIndEl = $domTree->createElement('presind', 1); @@ -118,7 +127,8 @@ public function getData() $cardEl->appendChild($cvnEl); - $issueEl = $domTree->createElement('issueno', $card->getIssueNumber()); + $issueEl = $domTree->createElement('issueno'); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); $cardEl->appendChild($issueEl); $root->appendChild($cardEl); @@ -129,9 +139,12 @@ public function getData() // 3D Secure section $mpiEl = $domTree->createElement('mpi'); - $cavvEl = $domTree->createElement('cavv', $this->getCavv()); - $xidEl = $domTree->createElement('xid', $this->getXid()); - $eciEl = $domTree->createElement('eci', $this->getEci()); + $cavvEl = $domTree->createElement('cavv'); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $xidEl = $domTree->createElement('xid'); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $eciEl = $domTree->createElement('eci'); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); $mpiEl->appendChild($cavvEl); $mpiEl->appendChild($xidEl); $mpiEl->appendChild($eciEl); @@ -143,7 +156,8 @@ public function getData() $tssEl = $domTree->createElement('tssinfo'); $addressEl = $domTree->createElement('address'); $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country', $card->getBillingCountry()); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); $addressEl->appendChild($countryEl); $tssEl->appendChild($addressEl); $root->appendChild($tssEl); diff --git a/src/Omnipay/Realex/Message/CreateCardRequest.php b/src/Omnipay/Realex/Message/CreateCardRequest.php index acc8dc5..18733fc 100644 --- a/src/Omnipay/Realex/Message/CreateCardRequest.php +++ b/src/Omnipay/Realex/Message/CreateCardRequest.php @@ -49,39 +49,49 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid', $orderId); + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); $cardEl = $domTree->createElement('card'); - $cardRefEl = $domTree->createElement('ref', $this->getCardReference()); + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); $cardEl->appendChild($cardRefEl); - $payerRefEl = $domTree->createElement('payerref', $this->getCustomerRef()); + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); $cardEl->appendChild($payerRefEl); - $numberEl = $domTree->createElement('number', $card->getNumber()); + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($numberEl); - $expDateEl = $domTree->createElement('expdate', $card->getExpiryDate("my")); + $expDateEl = $domTree->createElement('expdate'); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expDateEl); - $chNameEl = $domTree->createElement('chname', $card->getBillingName()); + $chNameEl = $domTree->createElement('chname'); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($chNameEl); - $typeEl = $domTree->createElement('type', $this->getCardBrand()); + $typeEl = $domTree->createElement('type'); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($typeEl); - $issueNoEl = $domTree->createElement('issueno', $card->getIssueNumber()); + $issueNoEl = $domTree->createElement('issueno'); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); $cardEl->appendChild($issueNoEl); $root->appendChild($cardEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/CreateCustomerRequest.php b/src/Omnipay/Realex/Message/CreateCustomerRequest.php index d6b1a00..5415311 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/CreateCustomerRequest.php @@ -43,11 +43,13 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid', $orderId); + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); $payerEl = $domTree->createElement('payer'); @@ -59,51 +61,64 @@ public function getData() */ $card = $this->getCard(); - $titleEl = $domTree->createElement('title', $card->getBillingTitle()); + $titleEl = $domTree->createElement('title'); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); $payerEl->appendChild($titleEl); - $firstnameEl = $domTree->createElement('firstname', $card->getBillingFirstName()); + $firstnameEl = $domTree->createElement('firstname'); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); $payerEl->appendChild($firstnameEl); - $lastnameEl = $domTree->createElement('surname', $card->getBillingLastName()); + $lastnameEl = $domTree->createElement('surname'); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); $payerEl->appendChild($lastnameEl); - $companyEl = $domTree->createElement('company', $card->getBillingCompany()); + $companyEl = $domTree->createElement('company'); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); $payerEl->appendChild($companyEl); $addressEl = $domTree->createElement('address'); - $line1El = $domTree->createElement('line1', $card->getBillingAddress1()); + $line1El = $domTree->createElement('line1'); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); $addressEl->appendChild($line1El); - $line2El = $domTree->createElement('line2', $card->getBillingAddress2()); + $line2El = $domTree->createElement('line2'); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); $addressEl->appendChild($line2El); - $cityEl = $domTree->createElement('city', $card->getBillingCity()); + $cityEl = $domTree->createElement('city'); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); $addressEl->appendChild($cityEl); - $countyEl = $domTree->createElement('county', $card->getBillingState()); + $countyEl = $domTree->createElement('county'); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); $addressEl->appendChild($countyEl); - $postcodeEl = $domTree->createElement('postcode', $card->getBillingPostcode()); + $postcodeEl = $domTree->createElement('postcode'); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); $addressEl->appendChild($postcodeEl); - $countryEl = $domTree->createElement('country', $card->getBillingCountry()); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); $addressEl->appendChild($countryEl); $payerEl->appendChild($addressEl); $phonenumbersEl = $domTree->createElement('phonenumbers'); - $homeEl = $domTree->createElement('home', $card->getBillingPhone()); + $homeEl = $domTree->createElement('home'); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); $phonenumbersEl->appendChild($homeEl); $payerEl->appendChild($phonenumbersEl); - $emailEl = $domTree->createElement('email', $card->getEmail()); + $emailEl = $domTree->createElement('email'); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); $payerEl->appendChild($emailEl); $root->appendChild($payerEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/DeleteCardRequest.php b/src/Omnipay/Realex/Message/DeleteCardRequest.php index 6870008..ce7f1c8 100644 --- a/src/Omnipay/Realex/Message/DeleteCardRequest.php +++ b/src/Omnipay/Realex/Message/DeleteCardRequest.php @@ -42,20 +42,24 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); $cardEl = $domTree->createElement('card'); - $cardRefEl = $domTree->createElement('ref', $this->getCardReference()); + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); $cardEl->appendChild($cardRefEl); - $payerRefEl = $domTree->createElement('payerref', $this->getCustomerRef()); + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode( $this->getCustomerRef())); $cardEl->appendChild($payerRefEl); $root->appendChild($cardEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/EnrolmentRequest.php b/src/Omnipay/Realex/Message/EnrolmentRequest.php index c0246fc..7df2c9b 100644 --- a/src/Omnipay/Realex/Message/EnrolmentRequest.php +++ b/src/Omnipay/Realex/Message/EnrolmentRequest.php @@ -41,19 +41,23 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account - $merchantEl = $domTree->createElement('account', $this->getAccount()); + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid', $orderId); + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); // amount - $amountEl = $domTree->createElement('amount', $amount); + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); $amountEl->setAttribute('currency', $this->getCurrency()); $root->appendChild($amountEl); @@ -65,21 +69,26 @@ public function getData() // Card details $cardEl = $domTree->createElement('card'); - $cardNumberEl = $domTree->createElement('number', $card->getNumber()); + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($cardNumberEl); - $expiryEl = $domTree->createElement('expdate', $card->getExpiryDate("my")); // mmyy + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expiryEl); - $cardTypeEl = $domTree->createElement('type', $this->getCardBrand()); + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($cardTypeEl); - $cardNameEl = $domTree->createElement('chname', $card->getBillingName()); + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($cardNameEl); $cvnEl = $domTree->createElement('cvn'); - $cvnNumberEl = $domTree->createElement('number', $card->getCvv()); + $cvnNumberEl = $domTree->createElement('number'); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); $cvnEl->appendChild($cvnNumberEl); $presIndEl = $domTree->createElement('presind', 1); @@ -87,12 +96,14 @@ public function getData() $cardEl->appendChild($cvnEl); - $issueEl = $domTree->createElement('issueno', $card->getIssueNumber()); + $issueEl = $domTree->createElement('issueno'); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); $cardEl->appendChild($issueEl); $root->appendChild($cardEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/FetchTransactionRequest.php b/src/Omnipay/Realex/Message/FetchTransactionRequest.php index 8aee7d6..df3287e 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionRequest.php +++ b/src/Omnipay/Realex/Message/FetchTransactionRequest.php @@ -42,18 +42,22 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account - $accountEl = $domTree->createElement('account', $this->getAccount()); + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($accountEl); // original order ID - $orderIdEl = $domTree->createElement('orderid', $orderId); + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($orderIdEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/RefundRequest.php b/src/Omnipay/Realex/Message/RefundRequest.php index be10d7a..1306e73 100644 --- a/src/Omnipay/Realex/Message/RefundRequest.php +++ b/src/Omnipay/Realex/Message/RefundRequest.php @@ -90,39 +90,44 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account - $accountEl = $domTree->createElement('account', $this->getAccount()); + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($accountEl); // the ID of the original transaction (confusingly in a tag called 'orderid') - $orderIdEl = $domTree->createElement('orderid', $originalTransactionId); + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); $root->appendChild($orderIdEl); // pasref for the original transaction - $pasRefEl = $domTree->createElement( - 'pasref', - $this->getTransactionReference() - ); + $pasRefEl = $domTree->createElement('pasref'); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); $root->appendChild($pasRefEl); // authcode returned for original transaction - $authCodeEl = $domTree->createElement('authcode', $this->getAuthCode()); + $authCodeEl = $domTree->createElement('authcode'); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); $root->appendChild($authCodeEl); // amount - $amountEl = $domTree->createElement('amount', $amount); + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); $amountEl->setAttribute('currency', $this->getCurrency()); $root->appendChild($amountEl); // refund hash $refundHash = sha1($this->getRefundPassword()); - $refundHashEl = $domTree->createElement('refundhash', $refundHash); + $refundHashEl = $domTree->createElement('refundhash'); + $refundHashEl->appendChild($domTree->createTextNode($refundHash)); $root->appendChild($refundHashEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index 53b8baf..9b02273 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -86,34 +86,41 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account - $merchantEl = $domTree->createElement('account', $this->getAccount()); + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid', $orderId); + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); // amount $amountEl = $domTree->createElement('amount', $amount); - $amountEl->setAttribute('currency', $this->getCurrency()); + $amountEl->setAttribute('currency'); + $amountEl->appendChild($domTree->createTextNode($this->getCurrency())); $root->appendChild($amountEl); $paymentDataEl = $domTree->createElement('paymentdata'); $cvnEl = $domTree->createElement('cvn'); - $numberEl = $domTree->createElement('number', $card->getCvv()); + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getCvv())); $cvnEl->appendChild($numberEl); $paymentDataEl->appendChild($cvnEl); $root->appendChild($paymentDataEl); - $payerRefEl = $domTree->createElement('payerref', $this->getCustomerRef()); + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); $root->appendChild($payerRefEl); - $paymentMethodEl = $domTree->createElement('paymentmethod', $this->getCardReference()); + $paymentMethodEl = $domTree->createElement('paymentmethod'); + $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); $root->appendChild($paymentMethodEl); $settleEl = $domTree->createElement('autosettle'); @@ -122,21 +129,26 @@ public function getData() // 3D Secure section $mpiEl = $domTree->createElement('mpi'); - $cavvEl = $domTree->createElement('cavv', $this->getCavv()); - $xidEl = $domTree->createElement('xid', $this->getXid()); - $eciEl = $domTree->createElement('eci', $this->getEci()); + $cavvEl = $domTree->createElement('cavv'); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $xidEl = $domTree->createElement('xid'); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $eciEl = $domTree->createElement('eci'); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); $mpiEl->appendChild($cavvEl); $mpiEl->appendChild($xidEl); $mpiEl->appendChild($eciEl); $root->appendChild($mpiEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $tssEl = $domTree->createElement('tssinfo'); $addressEl = $domTree->createElement('address'); $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country', $card->getBillingCountry()); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); $addressEl->appendChild($countryEl); $tssEl->appendChild($addressEl); $root->appendChild($tssEl); diff --git a/src/Omnipay/Realex/Message/UpdateCardRequest.php b/src/Omnipay/Realex/Message/UpdateCardRequest.php index 6245b18..93e6b75 100644 --- a/src/Omnipay/Realex/Message/UpdateCardRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCardRequest.php @@ -48,39 +48,49 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid', $orderId); + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); $cardEl = $domTree->createElement('card'); - $cardRefEl = $domTree->createElement('ref', $this->getCardReference()); + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); $cardEl->appendChild($cardRefEl); - $payerRefEl = $domTree->createElement('payerref', $this->getCustomerRef()); + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); $cardEl->appendChild($payerRefEl); - $numberEl = $domTree->createElement('number', $card->getNumber()); + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($numberEl); - $expDateEl = $domTree->createElement('expdate', $card->getExpiryDate("my")); + $expDateEl = $domTree->createElement('expdate'); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expDateEl); - $chNameEl = $domTree->createElement('chname', $card->getBillingName()); + $chNameEl = $domTree->createElement('chname'); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($chNameEl); - $typeEl = $domTree->createElement('type', $this->getCardBrand()); + $typeEl = $domTree->createElement('type'); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($typeEl); - $issueNoEl = $domTree->createElement('issueno', $card->getIssueNumber()); + $issueNoEl = $domTree->createElement('issueno'); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); $cardEl->appendChild($issueNoEl); $root->appendChild($cardEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php index 9f9d7d3..c4187e3 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php @@ -42,11 +42,13 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid' ); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid', $orderId); + $merchantEl = $domTree->createElement('orderid' ); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); $payerEl = $domTree->createElement('payer'); @@ -58,51 +60,64 @@ public function getData() */ $card = $this->getCard(); - $titleEl = $domTree->createElement('title', $card->getBillingTitle()); + $titleEl = $domTree->createElement('title'); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); $payerEl->appendChild($titleEl); - $firstnameEl = $domTree->createElement('firstname', $card->getBillingFirstName()); + $firstnameEl = $domTree->createElement('firstname'); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); $payerEl->appendChild($firstnameEl); - $lastnameEl = $domTree->createElement('surname', $card->getBillingLastName()); + $lastnameEl = $domTree->createElement('surname'); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); $payerEl->appendChild($lastnameEl); - $companyEl = $domTree->createElement('company', $card->getBillingCompany()); + $companyEl = $domTree->createElement('company'); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); $payerEl->appendChild($companyEl); $addressEl = $domTree->createElement('address'); - $line1El = $domTree->createElement('line1', $card->getBillingAddress1()); + $line1El = $domTree->createElement('line1'); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); $addressEl->appendChild($line1El); - $line2El = $domTree->createElement('line2', $card->getBillingAddress2()); + $line2El = $domTree->createElement('line2'); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); $addressEl->appendChild($line2El); - $cityEl = $domTree->createElement('city', $card->getBillingCity()); + $cityEl = $domTree->createElement('city'); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); $addressEl->appendChild($cityEl); - $countyEl = $domTree->createElement('county', $card->getBillingState()); + $countyEl = $domTree->createElement('county'); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); $addressEl->appendChild($countyEl); - $postcodeEl = $domTree->createElement('postcode', $card->getBillingPostcode()); + $postcodeEl = $domTree->createElement('postcode'); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); $addressEl->appendChild($postcodeEl); - $countryEl = $domTree->createElement('country', $card->getBillingCountry()); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); $addressEl->appendChild($countryEl); $payerEl->appendChild($addressEl); $phonenumbersEl = $domTree->createElement('phonenumbers'); - $homeEl = $domTree->createElement('home', $card->getBillingPhone()); + $homeEl = $domTree->createElement('home'); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); $phonenumbersEl->appendChild($homeEl); $payerEl->appendChild($phonenumbersEl); - $emailEl = $domTree->createElement('email', $card->getEmail()); + $emailEl = $domTree->createElement('email'); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); $payerEl->appendChild($emailEl); $root->appendChild($payerEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/VerifySigRequest.php b/src/Omnipay/Realex/Message/VerifySigRequest.php index efcd026..b265bd2 100644 --- a/src/Omnipay/Realex/Message/VerifySigRequest.php +++ b/src/Omnipay/Realex/Message/VerifySigRequest.php @@ -67,19 +67,23 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account - $merchantEl = $domTree->createElement('account', $this->getAccount()); + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid', $orderId); + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); // amount - $amountEl = $domTree->createElement('amount', $amount); + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); $amountEl->setAttribute('currency', $this->getCurrency()); $root->appendChild($amountEl); @@ -91,24 +95,30 @@ public function getData() // Card details $cardEl = $domTree->createElement('card'); - $cardNumberEl = $domTree->createElement('number', $card->getNumber()); + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($cardNumberEl); - $expiryEl = $domTree->createElement('expdate', $card->getExpiryDate("my")); // mmyy + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expiryEl); - $cardTypeEl = $domTree->createElement('type', $this->getCardBrand()); + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($cardTypeEl); - $cardNameEl = $domTree->createElement('chname', $card->getBillingName()); + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($cardNameEl); $root->appendChild($cardEl); - $paResEl = $domTree->createElement('pares', $paRes); + $paResEl = $domTree->createElement('pares'); + $paResEl->appendChild($domTree->createTextNode($paRes)); $root->appendChild($paResEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/VoidRequest.php b/src/Omnipay/Realex/Message/VoidRequest.php index 434fbf6..8ccb2cd 100644 --- a/src/Omnipay/Realex/Message/VoidRequest.php +++ b/src/Omnipay/Realex/Message/VoidRequest.php @@ -61,26 +61,32 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid', $merchantId); + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account - $accountEl = $domTree->createElement('account', $this->getAccount()); + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($accountEl); // original order ID - $orderIdEl = $domTree->createElement('orderid', $orderId); + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($orderIdEl); // pasref returned for original transaction - $pasRefEl = $domTree->createElement('pasref', $this->getTransactionReference()); + $pasRefEl = $domTree->createElement('pasref'); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); $root->appendChild($pasRefEl); // authcode returned for original transaction - $authCodeEl = $domTree->createElement('authcode', $this->getAuthCode()); + $authCodeEl = $domTree->createElement('authcode'); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); $root->appendChild($authCodeEl); - $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); From 746a6fedd8bce78f13ee3b23d36698f251af79af Mon Sep 17 00:00:00 2001 From: istvanfodor Date: Tue, 11 Oct 2016 09:11:37 +0100 Subject: [PATCH 08/29] replace tabs to 4 spaces --- src/Omnipay/Realex/Message/AuthRequest.php | 28 ++++++++--------- .../Realex/Message/CreateCardRequest.php | 20 ++++++------- .../Realex/Message/CreateCustomerRequest.php | 30 +++++++++---------- .../Realex/Message/DeleteCardRequest.php | 8 ++--- .../Realex/Message/EnrolmentRequest.php | 22 +++++++------- .../Message/FetchTransactionRequest.php | 8 ++--- src/Omnipay/Realex/Message/RefundRequest.php | 16 +++++----- .../Realex/Message/SavedAuthRequest.php | 24 +++++++-------- .../Realex/Message/UpdateCardRequest.php | 20 ++++++------- .../Realex/Message/UpdateCustomerRequest.php | 30 +++++++++---------- .../Realex/Message/VerifySigRequest.php | 20 ++++++------- src/Omnipay/Realex/Message/VoidRequest.php | 12 ++++---- 12 files changed, 119 insertions(+), 119 deletions(-) diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index 33058c7..a47b0f2 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -73,22 +73,22 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($merchantEl); // order ID $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); // amount $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->appendChild($domTree->createTextNode($amount)); $amountEl->setAttribute('currency', $this->getCurrency()); $root->appendChild($amountEl); @@ -101,25 +101,25 @@ public function getData() $cardEl = $domTree->createElement('card'); $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($cardNumberEl); $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expiryEl); $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($cardTypeEl); $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($cardNameEl); $cvnEl = $domTree->createElement('cvn'); $cvnNumberEl = $domTree->createElement('number'); - $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); $cvnEl->appendChild($cvnNumberEl); $presIndEl = $domTree->createElement('presind', 1); @@ -128,7 +128,7 @@ public function getData() $cardEl->appendChild($cvnEl); $issueEl = $domTree->createElement('issueno'); - $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); $cardEl->appendChild($issueEl); $root->appendChild($cardEl); @@ -140,11 +140,11 @@ public function getData() // 3D Secure section $mpiEl = $domTree->createElement('mpi'); $cavvEl = $domTree->createElement('cavv'); - $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); $xidEl = $domTree->createElement('xid'); - $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); $eciEl = $domTree->createElement('eci'); - $eciEl->appendChild($domTree->createTextNode($this->getEci())); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); $mpiEl->appendChild($cavvEl); $mpiEl->appendChild($xidEl); $mpiEl->appendChild($eciEl); @@ -157,7 +157,7 @@ public function getData() $addressEl = $domTree->createElement('address'); $addressEl->setAttribute('type', 'billing'); $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); $addressEl->appendChild($countryEl); $tssEl->appendChild($addressEl); $root->appendChild($tssEl); diff --git a/src/Omnipay/Realex/Message/CreateCardRequest.php b/src/Omnipay/Realex/Message/CreateCardRequest.php index 18733fc..2d4cde2 100644 --- a/src/Omnipay/Realex/Message/CreateCardRequest.php +++ b/src/Omnipay/Realex/Message/CreateCardRequest.php @@ -50,48 +50,48 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); $cardEl = $domTree->createElement('card'); $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); $cardEl->appendChild($cardRefEl); $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); $cardEl->appendChild($payerRefEl); $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getNumber())); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($numberEl); $expDateEl = $domTree->createElement('expdate'); - $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expDateEl); $chNameEl = $domTree->createElement('chname'); - $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($chNameEl); $typeEl = $domTree->createElement('type'); - $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($typeEl); $issueNoEl = $domTree->createElement('issueno'); - $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); $cardEl->appendChild($issueNoEl); $root->appendChild($cardEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/CreateCustomerRequest.php b/src/Omnipay/Realex/Message/CreateCustomerRequest.php index 5415311..7f55f31 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/CreateCustomerRequest.php @@ -44,12 +44,12 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); $payerEl = $domTree->createElement('payer'); @@ -62,63 +62,63 @@ public function getData() $card = $this->getCard(); $titleEl = $domTree->createElement('title'); - $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); $payerEl->appendChild($titleEl); $firstnameEl = $domTree->createElement('firstname'); - $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); $payerEl->appendChild($firstnameEl); $lastnameEl = $domTree->createElement('surname'); - $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); $payerEl->appendChild($lastnameEl); $companyEl = $domTree->createElement('company'); - $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); $payerEl->appendChild($companyEl); $addressEl = $domTree->createElement('address'); $line1El = $domTree->createElement('line1'); - $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); $addressEl->appendChild($line1El); $line2El = $domTree->createElement('line2'); - $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); $addressEl->appendChild($line2El); $cityEl = $domTree->createElement('city'); - $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); $addressEl->appendChild($cityEl); $countyEl = $domTree->createElement('county'); - $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); $addressEl->appendChild($countyEl); $postcodeEl = $domTree->createElement('postcode'); - $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); $addressEl->appendChild($postcodeEl); $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); $addressEl->appendChild($countryEl); $payerEl->appendChild($addressEl); $phonenumbersEl = $domTree->createElement('phonenumbers'); $homeEl = $domTree->createElement('home'); - $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); $phonenumbersEl->appendChild($homeEl); $payerEl->appendChild($phonenumbersEl); $emailEl = $domTree->createElement('email'); - $emailEl->appendChild($domTree->createTextNode($card->getEmail())); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); $payerEl->appendChild($emailEl); $root->appendChild($payerEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/DeleteCardRequest.php b/src/Omnipay/Realex/Message/DeleteCardRequest.php index ce7f1c8..d70e4be 100644 --- a/src/Omnipay/Realex/Message/DeleteCardRequest.php +++ b/src/Omnipay/Realex/Message/DeleteCardRequest.php @@ -43,23 +43,23 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); $cardEl = $domTree->createElement('card'); $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); $cardEl->appendChild($cardRefEl); $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode( $this->getCustomerRef())); + $payerRefEl->appendChild($domTree->createTextNode( $this->getCustomerRef())); $cardEl->appendChild($payerRefEl); $root->appendChild($cardEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/EnrolmentRequest.php b/src/Omnipay/Realex/Message/EnrolmentRequest.php index 7df2c9b..3132164 100644 --- a/src/Omnipay/Realex/Message/EnrolmentRequest.php +++ b/src/Omnipay/Realex/Message/EnrolmentRequest.php @@ -42,22 +42,22 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($merchantEl); // order ID $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); // amount $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->appendChild($domTree->createTextNode($amount)); $amountEl->setAttribute('currency', $this->getCurrency()); $root->appendChild($amountEl); @@ -70,25 +70,25 @@ public function getData() $cardEl = $domTree->createElement('card'); $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($cardNumberEl); $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expiryEl); $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($cardTypeEl); $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($cardNameEl); $cvnEl = $domTree->createElement('cvn'); $cvnNumberEl = $domTree->createElement('number'); - $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); $cvnEl->appendChild($cvnNumberEl); $presIndEl = $domTree->createElement('presind', 1); @@ -97,13 +97,13 @@ public function getData() $cardEl->appendChild($cvnEl); $issueEl = $domTree->createElement('issueno'); - $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); $cardEl->appendChild($issueEl); $root->appendChild($cardEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/FetchTransactionRequest.php b/src/Omnipay/Realex/Message/FetchTransactionRequest.php index df3287e..4b8e0d1 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionRequest.php +++ b/src/Omnipay/Realex/Message/FetchTransactionRequest.php @@ -43,21 +43,21 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($accountEl); // original order ID $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($orderId)); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($orderIdEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/RefundRequest.php b/src/Omnipay/Realex/Message/RefundRequest.php index 1306e73..7a639cd 100644 --- a/src/Omnipay/Realex/Message/RefundRequest.php +++ b/src/Omnipay/Realex/Message/RefundRequest.php @@ -91,43 +91,43 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($accountEl); // the ID of the original transaction (confusingly in a tag called 'orderid') $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); + $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); $root->appendChild($orderIdEl); // pasref for the original transaction $pasRefEl = $domTree->createElement('pasref'); - $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); $root->appendChild($pasRefEl); // authcode returned for original transaction $authCodeEl = $domTree->createElement('authcode'); - $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); $root->appendChild($authCodeEl); // amount $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->appendChild($domTree->createTextNode($amount)); $amountEl->setAttribute('currency', $this->getCurrency()); $root->appendChild($amountEl); // refund hash $refundHash = sha1($this->getRefundPassword()); $refundHashEl = $domTree->createElement('refundhash'); - $refundHashEl->appendChild($domTree->createTextNode($refundHash)); + $refundHashEl->appendChild($domTree->createTextNode($refundHash)); $root->appendChild($refundHashEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index 9b02273..c693e1a 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -87,40 +87,40 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($merchantEl); // order ID $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); // amount $amountEl = $domTree->createElement('amount', $amount); $amountEl->setAttribute('currency'); - $amountEl->appendChild($domTree->createTextNode($this->getCurrency())); + $amountEl->appendChild($domTree->createTextNode($this->getCurrency())); $root->appendChild($amountEl); $paymentDataEl = $domTree->createElement('paymentdata'); $cvnEl = $domTree->createElement('cvn'); $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getCvv())); + $numberEl->appendChild($domTree->createTextNode($card->getCvv())); $cvnEl->appendChild($numberEl); $paymentDataEl->appendChild($cvnEl); $root->appendChild($paymentDataEl); $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); $root->appendChild($payerRefEl); $paymentMethodEl = $domTree->createElement('paymentmethod'); - $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); + $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); $root->appendChild($paymentMethodEl); $settleEl = $domTree->createElement('autosettle'); @@ -130,25 +130,25 @@ public function getData() // 3D Secure section $mpiEl = $domTree->createElement('mpi'); $cavvEl = $domTree->createElement('cavv'); - $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); $xidEl = $domTree->createElement('xid'); - $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); $eciEl = $domTree->createElement('eci'); - $eciEl->appendChild($domTree->createTextNode($this->getEci())); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); $mpiEl->appendChild($cavvEl); $mpiEl->appendChild($xidEl); $mpiEl->appendChild($eciEl); $root->appendChild($mpiEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $tssEl = $domTree->createElement('tssinfo'); $addressEl = $domTree->createElement('address'); $addressEl->setAttribute('type', 'billing'); $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); $addressEl->appendChild($countryEl); $tssEl->appendChild($addressEl); $root->appendChild($tssEl); diff --git a/src/Omnipay/Realex/Message/UpdateCardRequest.php b/src/Omnipay/Realex/Message/UpdateCardRequest.php index 93e6b75..4a256f5 100644 --- a/src/Omnipay/Realex/Message/UpdateCardRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCardRequest.php @@ -49,48 +49,48 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); $cardEl = $domTree->createElement('card'); $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); $cardEl->appendChild($cardRefEl); $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); $cardEl->appendChild($payerRefEl); $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getNumber())); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($numberEl); $expDateEl = $domTree->createElement('expdate'); - $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expDateEl); $chNameEl = $domTree->createElement('chname'); - $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($chNameEl); $typeEl = $domTree->createElement('type'); - $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($typeEl); $issueNoEl = $domTree->createElement('issueno'); - $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); $cardEl->appendChild($issueNoEl); $root->appendChild($cardEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php index c4187e3..2186569 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php @@ -43,12 +43,12 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid' ); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID $merchantEl = $domTree->createElement('orderid' ); - $merchantEl->appendChild($domTree->createTextNode($orderId)); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); $payerEl = $domTree->createElement('payer'); @@ -61,63 +61,63 @@ public function getData() $card = $this->getCard(); $titleEl = $domTree->createElement('title'); - $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); $payerEl->appendChild($titleEl); $firstnameEl = $domTree->createElement('firstname'); - $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); $payerEl->appendChild($firstnameEl); $lastnameEl = $domTree->createElement('surname'); - $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); $payerEl->appendChild($lastnameEl); $companyEl = $domTree->createElement('company'); - $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); $payerEl->appendChild($companyEl); $addressEl = $domTree->createElement('address'); $line1El = $domTree->createElement('line1'); - $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); $addressEl->appendChild($line1El); $line2El = $domTree->createElement('line2'); - $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); $addressEl->appendChild($line2El); $cityEl = $domTree->createElement('city'); - $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); $addressEl->appendChild($cityEl); $countyEl = $domTree->createElement('county'); - $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); $addressEl->appendChild($countyEl); $postcodeEl = $domTree->createElement('postcode'); - $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); $addressEl->appendChild($postcodeEl); $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); $addressEl->appendChild($countryEl); $payerEl->appendChild($addressEl); $phonenumbersEl = $domTree->createElement('phonenumbers'); $homeEl = $domTree->createElement('home'); - $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); $phonenumbersEl->appendChild($homeEl); $payerEl->appendChild($phonenumbersEl); $emailEl = $domTree->createElement('email'); - $emailEl->appendChild($domTree->createTextNode($card->getEmail())); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); $payerEl->appendChild($emailEl); $root->appendChild($payerEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/VerifySigRequest.php b/src/Omnipay/Realex/Message/VerifySigRequest.php index b265bd2..ecd953b 100644 --- a/src/Omnipay/Realex/Message/VerifySigRequest.php +++ b/src/Omnipay/Realex/Message/VerifySigRequest.php @@ -68,22 +68,22 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($merchantEl); // order ID $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); + $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); // amount $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->appendChild($domTree->createTextNode($amount)); $amountEl->setAttribute('currency', $this->getCurrency()); $root->appendChild($amountEl); @@ -96,29 +96,29 @@ public function getData() $cardEl = $domTree->createElement('card'); $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); $cardEl->appendChild($cardNumberEl); $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); $cardEl->appendChild($expiryEl); $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($cardTypeEl); $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); $cardEl->appendChild($cardNameEl); $root->appendChild($cardEl); $paResEl = $domTree->createElement('pares'); - $paResEl->appendChild($domTree->createTextNode($paRes)); + $paResEl->appendChild($domTree->createTextNode($paRes)); $root->appendChild($paResEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); diff --git a/src/Omnipay/Realex/Message/VoidRequest.php b/src/Omnipay/Realex/Message/VoidRequest.php index 8ccb2cd..24e0904 100644 --- a/src/Omnipay/Realex/Message/VoidRequest.php +++ b/src/Omnipay/Realex/Message/VoidRequest.php @@ -62,31 +62,31 @@ public function getData() // merchant ID $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // account $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); $root->appendChild($accountEl); // original order ID $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($orderId)); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($orderIdEl); // pasref returned for original transaction $pasRefEl = $domTree->createElement('pasref'); - $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); $root->appendChild($pasRefEl); // authcode returned for original transaction $authCodeEl = $domTree->createElement('authcode'); - $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); $root->appendChild($authCodeEl); $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); From 0f14eb82b531373938578b49bb85b23aafeca208 Mon Sep 17 00:00:00 2001 From: istvanfodor Date: Tue, 11 Oct 2016 09:19:43 +0100 Subject: [PATCH 09/29] tidy changes --- src/Omnipay/Realex/Message/AuthRequest.php | 2 +- src/Omnipay/Realex/Message/DeleteCardRequest.php | 2 +- src/Omnipay/Realex/Message/UpdateCustomerRequest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index a47b0f2..c8a334e 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -109,7 +109,7 @@ public function getData() $cardEl->appendChild($expiryEl); $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); $cardEl->appendChild($cardTypeEl); $cardNameEl = $domTree->createElement('chname'); diff --git a/src/Omnipay/Realex/Message/DeleteCardRequest.php b/src/Omnipay/Realex/Message/DeleteCardRequest.php index d70e4be..232c512 100644 --- a/src/Omnipay/Realex/Message/DeleteCardRequest.php +++ b/src/Omnipay/Realex/Message/DeleteCardRequest.php @@ -53,7 +53,7 @@ public function getData() $cardEl->appendChild($cardRefEl); $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode( $this->getCustomerRef())); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); $cardEl->appendChild($payerRefEl); $root->appendChild($cardEl); diff --git a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php index 2186569..b2f9be5 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php @@ -42,12 +42,12 @@ public function getData() $root = $domTree->appendChild($root); // merchant ID - $merchantEl = $domTree->createElement('merchantid' ); + $merchantEl = $domTree->createElement('merchantid'); $merchantEl->appendChild($domTree->createTextNode($merchantId)); $root->appendChild($merchantEl); // order ID - $merchantEl = $domTree->createElement('orderid' ); + $merchantEl = $domTree->createElement('orderid'); $merchantEl->appendChild($domTree->createTextNode($orderId)); $root->appendChild($merchantEl); From 85430167f65ff415d7e50734e0a9d886a8508820 Mon Sep 17 00:00:00 2001 From: istvanfodor Date: Wed, 12 Oct 2016 10:03:41 +0100 Subject: [PATCH 10/29] RemoteAbstractRequest Amount node currency attribute value convert was wrong, move to convertation to node content --- src/Omnipay/Realex/Message/SavedAuthRequest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index c693e1a..d2a67c5 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -101,9 +101,9 @@ public function getData() $root->appendChild($merchantEl); // amount - $amountEl = $domTree->createElement('amount', $amount); - $amountEl->setAttribute('currency'); - $amountEl->appendChild($domTree->createTextNode($this->getCurrency())); + $amountEl = $domTree->createElement('amount'); + $amountEl->setAttribute('currency',$this->getCurrency()); + $amountEl->appendChild($domTree->createTextNode($amount)); $root->appendChild($amountEl); $paymentDataEl = $domTree->createElement('paymentdata'); From 6abd1d363ff7cdf3fd7a1297a84a649b22ac6a84 Mon Sep 17 00:00:00 2001 From: istvanfodor Date: Wed, 12 Oct 2016 10:07:46 +0100 Subject: [PATCH 11/29] added space after comma --- src/Omnipay/Realex/Message/SavedAuthRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index d2a67c5..15e57a6 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -102,7 +102,7 @@ public function getData() // amount $amountEl = $domTree->createElement('amount'); - $amountEl->setAttribute('currency',$this->getCurrency()); + $amountEl->setAttribute('currency', $this->getCurrency()); $amountEl->appendChild($domTree->createTextNode($amount)); $root->appendChild($amountEl); From be85459b64db950e4d485fdde225cf97d1ed0931 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Thu, 15 Jun 2017 16:57:31 +0100 Subject: [PATCH 12/29] added Redirect features --- .../Realex/Message/EnrolmentRequest.php | 18 +- .../Message/Redirect/AbstractRequest.php | 175 ++++++++++++++++++ .../Redirect/RedirectAuthorizeRequest.php | 24 +++ .../Redirect/RedirectAuthorizeResponse.php | 43 +++++ .../RedirectCompleteAuthorizeRequest.php | 37 ++++ .../RedirectCompleteStoreCardRequest.php | 43 +++++ .../Redirect/RedirectDataVaultRequest.php | 59 ++++++ .../Redirect/RedirectDataVaultResponse.php | 44 +++++ .../Redirect/RedirectPurchaseRequest.php | 14 ++ .../Redirect/RedirectPurchaseResponse.php | 16 ++ .../Redirect/RedirectStoreCardRequest.php | 93 ++++++++++ .../Redirect/RedirectStoreCardResponse.php | 18 ++ .../Message/Redirect/dataVaultResponse.php | 55 ++++++ .../Realex/Message/Redirect/response.php | 27 +++ .../Realex/Message/RemoteAbstractRequest.php | 1 + .../Realex/Message/VerifySigRequest.php | 18 +- src/Omnipay/Realex/RedirectGateway.php | 97 ++++++++++ src/Omnipay/Realex/RemoteGateway.php | 9 +- 18 files changed, 774 insertions(+), 17 deletions(-) create mode 100644 src/Omnipay/Realex/Message/Redirect/AbstractRequest.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php create mode 100644 src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php create mode 100644 src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php create mode 100644 src/Omnipay/Realex/Message/Redirect/response.php create mode 100644 src/Omnipay/Realex/RedirectGateway.php diff --git a/src/Omnipay/Realex/Message/EnrolmentRequest.php b/src/Omnipay/Realex/Message/EnrolmentRequest.php index 3132164..a3efdbc 100644 --- a/src/Omnipay/Realex/Message/EnrolmentRequest.php +++ b/src/Omnipay/Realex/Message/EnrolmentRequest.php @@ -107,7 +107,7 @@ public function getData() $root->appendChild($sha1El); $xmlString = $domTree->saveXML($root); - + return $xmlString; } @@ -130,12 +130,22 @@ protected function createResponse($data) return $response; } - public function getEndpoint() +// public function getEndpoint() +// { +// return $this->getParameter('3dSecureEndpoint'); +// } +// public function setAuthEndpoint($value) +// { +// return $this->setParameter('3dSecureEndpoint', $value); +// } + + public function getEndpoint() { - return $this->getParameter('3dSecureEndpoint'); + return $this->getParameter('authEndpoint'); } public function setAuthEndpoint($value) { - return $this->setParameter('3dSecureEndpoint', $value); + return $this->setParameter('authEndpoint', $value); } + } diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php new file mode 100644 index 0000000..41704bd --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -0,0 +1,175 @@ +getParameter('merchantId'); + } + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + public function getAccount() + { + return $this->getParameter('account'); + } + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + public function getSecret() + { + return $this->getParameter('secret'); + } + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + public function setStore($value) + { + return $this->setParameter('store', $value); + } + public function getStore() + { + return $this->getParameters('store'); + } + public function getPares() + { + return $this->getParameter('pares'); + } + public function setPares($value) + { + return $this->setParameter('pares', $value); + } + public function setCavv($value) + { + return $this->setParameter('cavv', $value); + } + public function getCavv() + { + return $this->getParameter('cavv'); + } + public function setXid($value) + { + return $this->setParameter('xid', $value); + } + public function getXid() + { + return $this->getParameter('xid'); + } + public function setEci($value) + { + return $this->setParameter('eci', $value); + } + public function getEci() + { + return $this->getParameter('eci'); + } + public function setNotifyUrl($value) + { + return $this->setParameter('notifyUrl', $value); + } + public function getNotifyUrl() + { + return $this->getParameter('notifyUrl'); + } + public function setExtraData($value) + { + return $this->setParameter('extraData', $value); + } + public function getExtraData() + { + return $this->getParameter('extraData'); + } + public function getBaseData($autoSettle = true, $card = null) + { + $data = array( + 'EXTRA' => $this->getExtraData(), + 'MERCHANT_ID' => $this->getMerchantId(), + 'ORDER_ID' => $this->getTransactionId(), + 'CURRENCY' => $this->getCurrency(), + 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), + 'AMOUNT' => round( $this->getAmount() * 100 ), + 'TIMESTAMP' => gmdate('YmdHis'), + 'AUTO_SETTLE_FLAG' => $autoSettle + ); + $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); + return $data; + } + public function createSignature($data, $method = 'sha1', $card = null) + { + $hash = $method(rtrim(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['AMOUNT'], + $data['CURRENCY'], + $card !== null ? $card->getNumber() : null + )), '.')); + + return $method($hash.'.'.$this->getSecret()); + } + public function getRequestXML($card, $autoSettle = true, $extraData = array(), $addressData = true, $cardData = true) + { + $data = $this->getBaseData($autoSettle, $card); + $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); + $request = new \SimpleXMLElement(''); + $request['timestamp'] = $data['TIMESTAMP']; + $request['type'] = $this->getType(); + $request->merchantid = $this->getMerchantId(); + $request->account = $this->getAccount(); + $request->orderid = $data['ORDER_ID']; + //$request->md5hash = $this->createSignature($data, 'md5', $card); + $request->custipaddress = $this->getClientIp(); + $request->amount = $data['AMOUNT']; + $request->amount['currency'] = $data['CURRENCY']; + $request->autosettle['flag'] = (int)$data['AUTO_SETTLE_FLAG']; + // Flesh out the XML structure + $request->addChild('card'); + $request->card->addChild('cvn'); + $request->card->number = $card->getNumber(); + $request->card->expdate = $card->getExpiryDate('my'); + $request->card->type = strtoupper($brand); + $request->card->chname = $card->getName(); + // Not all request want this data + if($cardData) { + $request->card->issueno = $card->getIssueNumber(); + $request->card->addChild('cvn'); + $request->card->cvn->addChild('number', $card->getCvv()); + $request->card->cvn->addChild('presind', 1); + } + // not all requests want this data + if($addressData) { + $request->address['type'] = 'billing'; + $request->address->code = $card->getBillingPostcode(); + $request->address->country = strtoupper($card->getBillingCountry()); + } + // Add in extra array data for any obscure fields + if(!empty($extraData)) { + foreach($extraData as $key => $value) { + $request->$key = $value; + } + } + $request->sha1hash = $data['SHA1HASH']; + return $request->asXML(); + } + protected function getType() + { + return 'auth'; + } + + public function getCheckoutEndpoint() + { + return $this->getParameter('checkoutEndpoint'); + } + + public function setCheckoutEndpoint($value) + { + return $this->setParameter('checkoutEndpoint', $value); + } + +} \ No newline at end of file diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php new file mode 100644 index 0000000..b634244 --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php @@ -0,0 +1,24 @@ +getBaseData(); + } + + public function sendData($data) + { + return $this->response = new RedirectAuthorizeResponse($this, $data); + } +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php new file mode 100644 index 0000000..5837e2d --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php @@ -0,0 +1,43 @@ +getRequest()->getCheckoutEndpoint(); + } + + public function getTransactionReference() + { + return $this->getRequest()->getTransactionId(); + } + + public function getRedirectMethod() + { + return 'POST'; + } + + public function getRedirectData() + { + return $this->getRequest()->getBaseData(false); + } + +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php new file mode 100644 index 0000000..8e35697 --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php @@ -0,0 +1,37 @@ +httpRequest->request->get('TIMESTAMP'), + $this->httpRequest->request->get('MERCHANT_ID'), + $this->httpRequest->request->get('ORDER_ID'), + $this->httpRequest->request->get('RESULT'), + $this->httpRequest->request->get('MESSAGE'), + $this->httpRequest->request->get('PASREF'), + $this->httpRequest->request->get('AUTHCODE') + ))); + + // Validate signature + if ( $this->httpRequest->request->get('SHA1HASH') !== sha1($hash.'.'.$this->getSecret()) ) { + throw new InvalidResponseException; + } + + return $this->httpRequest->request->all(); + } + + public function sendData($data) + { + return $this->response = new Response($this, $data); + } +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php new file mode 100644 index 0000000..aa7b30c --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php @@ -0,0 +1,43 @@ +httpRequest->request->get('hppResponse')) AS $key => $value) { + $data[$key] = base64_decode($value); + } + + // Build initial hash + $hash = sha1(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['RESULT'], + $data['MESSAGE'], + $data['PASREF'], + $data['AUTHCODE'], + ))); + + // Validate signature + if ( $data['SHA1HASH'] !== sha1($hash.'.'.$this->getSecret()) ) { + throw new InvalidResponseException; + } + + return $data; + } + + public function sendData($data) + { + return $this->response = new dataVaultResponse($this, $data); + } +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php new file mode 100644 index 0000000..7a907e3 --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php @@ -0,0 +1,59 @@ + $this->getAccount(), + 'MERCHANT_ID' => $this->getMerchantId(), + 'ORDER_ID' => $this->getTransactionId(), + 'CURRENCY' => $this->getCurrency(), + 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), + 'AMOUNT' => round($this->getAmount() * 100), + 'TIMESTAMP' => gmdate('YmdHis'), + 'AUTO_SETTLE_FLAG' => $autoSettle, + 'HPP_VERSION' => 2 + ); + + if(isset($this->getData()['extraData']) && is_array($this->getData()['extraData'])) { + $data = array_merge($data,$this->getData()['extraData']); + } + $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); + return $data; + } + /* + * "timestamp.merchantid.orderid.amount.currency.payerref.paymentmethod" + */ + public function createSignature($data, $method = 'sha1', $card = null) + { + $hash = $method(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['AMOUNT'], + $data['CURRENCY'], + $data['PAYER_REF'], + '' + ))); + + return $method($hash.'.'.$this->getSecret()); + } + + public function getRedirectData() { + return $this->getBaseData(); + } + + public function sendData($data) { + return $this->response = new RedirectDataVaultResponse($this, $data); + } + +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php new file mode 100644 index 0000000..e326f79 --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php @@ -0,0 +1,44 @@ +getRequest()->getCheckoutEndpoint(); + } + + public function getTransactionReference() + { + return $this->getRequest()->getTransactionId(); + } + + public function getRedirectMethod() + { + return 'POST'; + } + + public function getRedirectData() + { + $data = $this->getRequest()->getBaseData(false); + return $data; + } + +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php new file mode 100644 index 0000000..91d8365 --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php @@ -0,0 +1,14 @@ +response = new RedirectPurchaseResponse($this, $data); + } +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php new file mode 100644 index 0000000..afd4b15 --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php @@ -0,0 +1,16 @@ +getRequest()->getBaseData(); + } +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php new file mode 100644 index 0000000..fe8bb9a --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php @@ -0,0 +1,93 @@ +getParameter('customerRef'); + } + + public function setCustomerRef($data) + { + $this->setParameter('customerRef', $data); + } + public function getCustomerExists() + { + return $this->getParameter('customerExists'); + } + + public function setCustomerExists($data) + { + $this->setParameter('customerExists', $data); + } + public function getValidateCardOnly() + { + return $this->getParameter('validateCardOnly'); + } + + public function setValidateCardOnly($data) + { + $this->setParameter('validateCardOnly', $data); + } + public function getOfferSaveCard() + { + return $this->getParameter('offerSaveCard'); + } + + public function setOfferSaveCard($data) + { + $this->setParameter('offerSaveCard', $data); + } + public function getCardPaymentButton() + { + return $this->getParameter('cardPaymentButton'); + } + + public function setCardPaymentButton($data) + { + $this->setParameter('cardPaymentButton', $data); + } + public function getHPPPostDimensions() + { + return $this->getParameter('HPPPostDimensions'); + } + + public function setHPPPostDimensions($data) + { + $this->setParameter('HPPPostDimensions', $data); + } + public function getHPPPostResponse() + { + return $this->getParameter('HPPPostResponse'); + } + + public function setHPPPostResponse($data) + { + $this->setParameter('HPPPostResponse', $data); + } + public function getData() { + + $data['extraData'] = [ + 'PAYER_REF' => $this->getCustomerRef(), + 'PAYER_EXIST' => $this->getCustomerExists(), + 'VALIDATE_CARD_ONLY' => $this->getValidateCardOnly(), + 'OFFER_SAVE_CARD' => $this->getOfferSaveCard(), + 'CARD_STORAGE_ENABLE' => '1', + 'CARD_PAYMENT_BUTTON' => $this->getCardPaymentButton(), + 'HPP_POST_DIMENSIONS' => $this->getHPPPostDimensions(), + 'HPP_POST_RESPONSE' => $this->getHPPPostResponse(), + ]; + + return $data; + } + public function sendData($data) + { + return $this->response = new RedirectStoreCardResponse($this, $data); + } + +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php new file mode 100644 index 0000000..2c59caa --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php @@ -0,0 +1,18 @@ +getRequest()->getRedirectData(); + + return $data; + } +} diff --git a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php new file mode 100644 index 0000000..0131f5c --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php @@ -0,0 +1,55 @@ +request = $request; + $this->data = $data; + } + public function isSuccessful() + { + if(!$this->isPayerSetupSuccessful()){ + return false; + } elseif(!$this->isPayerCardAddSuccessful()){ + return false; + } else { + return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; + } + + } + public function getMessage() + { + $message; + if(isset($this->data['PMT_SETUP_MSG'])){ + $message .= $this->data['PMT_SETUP_MSG'] . ' '; + } + if(isset($this->data['PAYER_SETUP_MSG'])){ + $message .= $this->data['PAYER_SETUP_MSG'] . ' '; + } + if(isset($this->data['MESSAGE'])){ + $message .= $this->data['MESSAGE'] . ' '; + } + + return $message; + } + public function getTransactionReference() + { + return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; + } + + public function isPayerSetupSuccessful(){ + return !isset($this->data['PAYER_SETUP']) || (isset($this->data['PAYER_SETUP']) && '00' === $this->data['PAYER_SETUP']); + } + public function isPayerCardAddSuccessful(){ + return !isset($this->data['PMT_SETUP']) || (isset($this->data['PMT_SETUP']) && '00' === $this->data['PMT_SETUP']); + } + public function getCardToken(){ + return isset($this->data['SAVED_PMT_REF']) ? $this->data['SAVED_PMT_REF'] : null; + } +} \ No newline at end of file diff --git a/src/Omnipay/Realex/Message/Redirect/response.php b/src/Omnipay/Realex/Message/Redirect/response.php new file mode 100644 index 0000000..3b7018f --- /dev/null +++ b/src/Omnipay/Realex/Message/Redirect/response.php @@ -0,0 +1,27 @@ +request = $request; + $this->data = $data; + } + public function isSuccessful() + { + return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; + } + public function getMessage() + { + return isset($this->data['MESSAGE']) ? $this->data['MESSAGE'] : null; + } + public function getTransactionReference() + { + return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; + } +} \ No newline at end of file diff --git a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php index 001b4d9..f4c66dc 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php @@ -80,6 +80,7 @@ public function sendData($data) 'CURLOPT_SSL_VERIFYPEER' => false ) )); + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); return $this->createResponse($httpResponse->getBody(true)); diff --git a/src/Omnipay/Realex/Message/VerifySigRequest.php b/src/Omnipay/Realex/Message/VerifySigRequest.php index ecd953b..2f23e91 100644 --- a/src/Omnipay/Realex/Message/VerifySigRequest.php +++ b/src/Omnipay/Realex/Message/VerifySigRequest.php @@ -120,9 +120,9 @@ public function getData() $sha1El = $domTree->createElement('sha1hash'); $sha1El->appendChild($domTree->createTextNode($sha1hash)); $root->appendChild($sha1El); - + $xmlString = $domTree->saveXML($root); - + return $xmlString; } @@ -133,11 +133,11 @@ protected function createResponse($data) public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); + return $this->getParameter('authEndpoint'); } public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); + return $this->setParameter('authEndpoint', $value); } /** @@ -151,15 +151,14 @@ public function sendData($parameters) * @var VerifySigResponse $response */ $response = parent::sendData($parameters); - + if ($response->isSuccessful()) { - // a few additional parameters that need to be passed for 3D-Secure transactions $parameters = $this->getParameters(); $parameters['cavv'] = $response->getParam('cavv'); $parameters['eci'] = $response->getParam('eci'); $parameters['xid'] = $response->getParam('xid'); - + /** * Now finally, do our authorisation * @@ -168,10 +167,11 @@ public function sendData($parameters) */ $request = new AuthRequest($this->httpClient, $this->httpRequest); $request->initialize($parameters); - + $response = $request->send(); + } - + return $response; } } diff --git a/src/Omnipay/Realex/RedirectGateway.php b/src/Omnipay/Realex/RedirectGateway.php new file mode 100644 index 0000000..17078cf --- /dev/null +++ b/src/Omnipay/Realex/RedirectGateway.php @@ -0,0 +1,97 @@ + '', + 'secret' => '', + 'account' => 'internet', + 'testMode' => false, + 'checkoutEndpoint' => 'https://hpp.realexpayments.com/pay', + ); + } + + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getCheckoutEndpoint() + { + return $this->getParameter('checkoutEndpoint'); + } + + public function setCheckoutEndpoint($value) + { + return $this->setParameter('checkoutEndpoint', $value); + } + + public function authorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectAuthorizeRequest', $parameters); + } + + public function completeAuthorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteAuthorizeRequest', $parameters); + } + + public function purchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectPurchaseRequest', $parameters); + } + + public function completePurchase(array $parameters = array()) + { + return $this->completeAuthorize($parameters); + } + + public function storeCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectStoreCardRequest', $parameters); + } + public function completeStoreCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteStoreCardRequest', $parameters); + } + +} diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index fcce86e..a5941b3 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -93,6 +93,7 @@ public function set3dSecure($value) public function purchase(array $parameters = array()) { + if (array_key_exists('cardReference', $parameters)) { return $this->createRequest('\Omnipay\Realex\Message\SavedAuthRequest', $parameters); } elseif ($this->get3dSecure()) { @@ -159,22 +160,22 @@ public function updateCustomer(array $parameters = array()) */ public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); + return $this->setParameter('authEndpoint', $value); } public function getAuthEndpoint() { - return $this->getParameter('AuthEndpoint'); + return $this->getParameter('authEndpoint'); } public function setSecureDataVaultEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); + return $this->setParameter('secureDataVaultEndpoint', $value); } public function getSecureDataVaultEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); + return $this->getParameter('secureDataVaultEndpoint'); } public function set3DSecureEndpoint($value) From a0c0b24a4addb5aa9ceac917dc540bda2dbccf83 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 09:40:31 +0100 Subject: [PATCH 13/29] format code --- .gitignore | 1 + nbproject/project.properties | 7 + nbproject/project.xml | 9 + src/Omnipay/Realex/Message/AuthRequest.php | 335 +++++++++-------- src/Omnipay/Realex/Message/AuthResponse.php | 126 +++---- .../Realex/Message/CreateCardRequest.php | 205 ++++++----- .../Realex/Message/CreateCardResponse.php | 73 ++-- .../Realex/Message/CreateCustomerRequest.php | 260 +++++++------- .../Realex/Message/CreateCustomerResponse.php | 64 ++-- .../Realex/Message/DeleteCardRequest.php | 109 +++--- .../Realex/Message/DeleteCardResponse.php | 64 ++-- .../Realex/Message/EnrolmentRequest.php | 260 +++++++------- .../Realex/Message/EnrolmentResponse.php | 156 ++++---- .../Message/FetchTransactionRequest.php | 139 ++++--- .../Message/FetchTransactionResponse.php | 90 +++-- .../Message/Redirect/AbstractRequest.php | 339 +++++++++--------- .../Redirect/RedirectAuthorizeRequest.php | 26 +- .../Redirect/RedirectAuthorizeResponse.php | 57 ++- .../RedirectCompleteAuthorizeRequest.php | 53 ++- .../RedirectCompleteStoreCardRequest.php | 35 +- .../Redirect/RedirectDataVaultRequest.php | 33 +- .../Redirect/RedirectDataVaultResponse.php | 57 ++- .../Redirect/RedirectPurchaseRequest.php | 12 +- .../Redirect/RedirectPurchaseResponse.php | 12 +- .../Redirect/RedirectStoreCardRequest.php | 137 ++++--- .../Redirect/RedirectStoreCardResponse.php | 12 +- .../Message/Redirect/dataVaultResponse.php | 62 ++-- .../Realex/Message/Redirect/response.php | 43 +-- src/Omnipay/Realex/Message/RefundRequest.php | 265 +++++++------- src/Omnipay/Realex/Message/RefundResponse.php | 90 +++-- .../Realex/Message/RemoteAbstractRequest.php | 152 ++++---- .../Realex/Message/RemoteAbstractResponse.php | 49 ++- .../Realex/Message/SavedAuthRequest.php | 315 ++++++++-------- .../Realex/Message/UpdateCardRequest.php | 204 ++++++----- .../Realex/Message/UpdateCardResponse.php | 63 ++-- .../Realex/Message/UpdateCustomerRequest.php | 261 +++++++------- .../Realex/Message/UpdateCustomerResponse.php | 64 ++-- .../Realex/Message/VerifySigRequest.php | 325 +++++++++-------- .../Realex/Message/VerifySigResponse.php | 130 ++++--- src/Omnipay/Realex/Message/VoidRequest.php | 194 +++++----- src/Omnipay/Realex/Message/VoidResponse.php | 90 +++-- src/Omnipay/Realex/RedirectGateway.php | 159 ++++---- src/Omnipay/Realex/RemoteGateway.php | 323 ++++++++--------- 43 files changed, 2628 insertions(+), 2832 deletions(-) create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml diff --git a/.gitignore b/.gitignore index 0d77fdb..0d44bac 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock composer.phar phpunit.xml .idea +/nbproject/private/ \ No newline at end of file diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..76f6f91 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_56 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..9db1515 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + omnipay-realex + + + diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index c8a334e..8391142 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -8,176 +8,167 @@ /** * Realex Auth Request */ -class AuthRequest extends RemoteAbstractRequest -{ - - public function getCavv() - { - return $this->getParameter('cavv'); - } - - public function setCavv($value) - { - return $this->setParameter('cavv', $value); - } - - public function getEci() - { - return $this->getParameter('eci'); - } - - public function setEci($value) - { - return $this->setParameter('eci', $value); - } - - public function getXid() - { - return $this->getParameter('xid'); - } - - public function setXid($value) - { - return $this->setParameter('xid', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() - { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'auth'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $cvnEl = $domTree->createElement('cvn'); - - $cvnNumberEl = $domTree->createElement('number'); - $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); - $cvnEl->appendChild($cvnNumberEl); - - $presIndEl = $domTree->createElement('presind', 1); - $cvnEl->appendChild($presIndEl); - - $cardEl->appendChild($cvnEl); - - $issueEl = $domTree->createElement('issueno'); - $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueEl); - - $root->appendChild($cardEl); - - $settleEl = $domTree->createElement('autosettle'); - $settleEl->setAttribute('flag', 1); - $root->appendChild($settleEl); - - // 3D Secure section - $mpiEl = $domTree->createElement('mpi'); - $cavvEl = $domTree->createElement('cavv'); - $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); - $xidEl = $domTree->createElement('xid'); - $xidEl->appendChild($domTree->createTextNode($this->getXid())); - $eciEl = $domTree->createElement('eci'); - $eciEl->appendChild($domTree->createTextNode($this->getEci())); - $mpiEl->appendChild($cavvEl); - $mpiEl->appendChild($xidEl); - $mpiEl->appendChild($eciEl); - $root->appendChild($mpiEl); - - $sha1El = $domTree->createElement('sha1hash', $sha1hash); - $root->appendChild($sha1El); - - $tssEl = $domTree->createElement('tssinfo'); - $addressEl = $domTree->createElement('address'); - $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - $tssEl->appendChild($addressEl); - $root->appendChild($tssEl); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new AuthResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('AuthEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('AuthEndpoint', $value); - } +class AuthRequest extends RemoteAbstractRequest { + + public function getCavv() { + return $this->getParameter('cavv'); + } + + public function setCavv($value) { + return $this->setParameter('cavv', $value); + } + + public function getEci() { + return $this->getParameter('eci'); + } + + public function setEci($value) { + return $this->setParameter('eci', $value); + } + + public function getXid() { + return $this->getParameter('xid'); + } + + public function setXid($value) { + return $this->setParameter('xid', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'auth'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $cvnEl = $domTree->createElement('cvn'); + + $cvnNumberEl = $domTree->createElement('number'); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); + $cvnEl->appendChild($cvnNumberEl); + + $presIndEl = $domTree->createElement('presind', 1); + $cvnEl->appendChild($presIndEl); + + $cardEl->appendChild($cvnEl); + + $issueEl = $domTree->createElement('issueno'); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueEl); + + $root->appendChild($cardEl); + + $settleEl = $domTree->createElement('autosettle'); + $settleEl->setAttribute('flag', 1); + $root->appendChild($settleEl); + + // 3D Secure section + $mpiEl = $domTree->createElement('mpi'); + $cavvEl = $domTree->createElement('cavv'); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $xidEl = $domTree->createElement('xid'); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $eciEl = $domTree->createElement('eci'); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); + $mpiEl->appendChild($cavvEl); + $mpiEl->appendChild($xidEl); + $mpiEl->appendChild($eciEl); + $root->appendChild($mpiEl); + + $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $root->appendChild($sha1El); + + $tssEl = $domTree->createElement('tssinfo'); + $addressEl = $domTree->createElement('address'); + $addressEl->setAttribute('type', 'billing'); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + $tssEl->appendChild($addressEl); + $root->appendChild($tssEl); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new AuthResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('AuthEndpoint', $value); + } + } diff --git a/src/Omnipay/Realex/Message/AuthResponse.php b/src/Omnipay/Realex/Message/AuthResponse.php index 761a881..d0d735e 100644 --- a/src/Omnipay/Realex/Message/AuthResponse.php +++ b/src/Omnipay/Realex/Message/AuthResponse.php @@ -10,73 +10,61 @@ /** * Realex Auth Response */ -class AuthResponse extends RemoteAbstractResponse implements RedirectResponseInterface -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function isDecline() - { - return (substr($this->xml->result, 0, 1) == '1'); - } - - public function isBankSystemError() - { - return (substr($this->xml->result, 0, 1) == '2'); - } - - public function isRealexSystemError() - { - return (substr($this->xml->result, 0, 1) == '3'); - } - - public function getMessage() - { - return (string)$this->xml->message; - } - - public function getTransactionId() - { - return ($this->xml->orderid) ? (string)$this->xml->orderid : null; - } - - public function getTransactionReference() - { - return ($this->xml->pasref) ? (string)$this->xml->pasref : null; - } - - public function getAuthCode() - { - return ($this->xml->authcode) ? (string)$this->xml->authcode : null; - } - - public function getBatchId() - { - return ($this->xml->batchid) ? (string)$this->xml->batchid : null; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } +class AuthResponse extends RemoteAbstractResponse implements RedirectResponseInterface { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function isDecline() { + return (substr($this->xml->result, 0, 1) == '1'); + } + + public function isBankSystemError() { + return (substr($this->xml->result, 0, 1) == '2'); + } + + public function isRealexSystemError() { + return (substr($this->xml->result, 0, 1) == '3'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function getTransactionId() { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function getBatchId() { + return ($this->xml->batchid) ? (string) $this->xml->batchid : null; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } + } diff --git a/src/Omnipay/Realex/Message/CreateCardRequest.php b/src/Omnipay/Realex/Message/CreateCardRequest.php index 2d4cde2..98f1b82 100644 --- a/src/Omnipay/Realex/Message/CreateCardRequest.php +++ b/src/Omnipay/Realex/Message/CreateCardRequest.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,110 +7,104 @@ namespace Omnipay\Realex\Message; +class CreateCardRequest extends RemoteAbstractRequest { + + public function getCustomerRef() { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-new'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $cardEl = $domTree->createElement('card'); + + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); + + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($numberEl); + + $expDateEl = $domTree->createElement('expdate'); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expDateEl); + + $chNameEl = $domTree->createElement('chname'); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($chNameEl); + + $typeEl = $domTree->createElement('type'); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($typeEl); + + $issueNoEl = $domTree->createElement('issueno'); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueNoEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new CreateCardResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('AuthEndpoint', $value); + } -class CreateCardRequest extends RemoteAbstractRequest -{ - - public function getCustomerRef() - { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) - { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() - { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-new'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $cardEl = $domTree->createElement('card'); - - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); - - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($numberEl); - - $expDateEl = $domTree->createElement('expdate'); - $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expDateEl); - - $chNameEl = $domTree->createElement('chname'); - $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($chNameEl); - - $typeEl = $domTree->createElement('type'); - $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($typeEl); - - $issueNoEl = $domTree->createElement('issueno'); - $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueNoEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new CreateCardResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('AuthEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('AuthEndpoint', $value); - } } diff --git a/src/Omnipay/Realex/Message/CreateCardResponse.php b/src/Omnipay/Realex/Message/CreateCardResponse.php index 2ea374a..cdba215 100644 --- a/src/Omnipay/Realex/Message/CreateCardResponse.php +++ b/src/Omnipay/Realex/Message/CreateCardResponse.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,43 +7,37 @@ namespace Omnipay\Realex\Message; -class CreateCardResponse extends RemoteAbstractResponse -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function customerDoesntExist() - { - return ($this->xml->result == '520'); - } - - public function getMessage() - { - return (string) $this->xml->message; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } +class CreateCardResponse extends RemoteAbstractResponse { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function customerDoesntExist() { + return ($this->xml->result == '520'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } + } diff --git a/src/Omnipay/Realex/Message/CreateCustomerRequest.php b/src/Omnipay/Realex/Message/CreateCustomerRequest.php index 7f55f31..427c9d3 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/CreateCustomerRequest.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,137 +7,132 @@ namespace Omnipay\Realex\Message; -class CreateCustomerRequest extends RemoteAbstractRequest -{ - - public function getCustomerRef() - { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) - { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() - { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); +class CreateCustomerRequest extends RemoteAbstractRequest { + + public function getCustomerRef() { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'payer-new'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $payerEl = $domTree->createElement('payer'); + $payerEl->setAttribute('type', 'Business'); + $payerEl->setAttribute('ref', $payerRef); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $titleEl = $domTree->createElement('title'); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); + $payerEl->appendChild($titleEl); + + $firstnameEl = $domTree->createElement('firstname'); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); + $payerEl->appendChild($firstnameEl); + + $lastnameEl = $domTree->createElement('surname'); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); + $payerEl->appendChild($lastnameEl); + + $companyEl = $domTree->createElement('company'); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); + $payerEl->appendChild($companyEl); + + $addressEl = $domTree->createElement('address'); + + $line1El = $domTree->createElement('line1'); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); + $addressEl->appendChild($line1El); + + $line2El = $domTree->createElement('line2'); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); + $addressEl->appendChild($line2El); + + $cityEl = $domTree->createElement('city'); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); + $addressEl->appendChild($cityEl); + + $countyEl = $domTree->createElement('county'); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); + $addressEl->appendChild($countyEl); + + $postcodeEl = $domTree->createElement('postcode'); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); + $addressEl->appendChild($postcodeEl); + + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + + $payerEl->appendChild($addressEl); + + $phonenumbersEl = $domTree->createElement('phonenumbers'); + $homeEl = $domTree->createElement('home'); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); + $phonenumbersEl->appendChild($homeEl); + $payerEl->appendChild($phonenumbersEl); + + $emailEl = $domTree->createElement('email'); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); + $payerEl->appendChild($emailEl); + + $root->appendChild($payerEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new CreateCustomerResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('AuthEndpoint', $value); + } - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'payer-new'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $payerEl = $domTree->createElement('payer'); - $payerEl->setAttribute('type', 'Business'); - $payerEl->setAttribute('ref', $payerRef); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $titleEl = $domTree->createElement('title'); - $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); - $payerEl->appendChild($titleEl); - - $firstnameEl = $domTree->createElement('firstname'); - $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); - $payerEl->appendChild($firstnameEl); - - $lastnameEl = $domTree->createElement('surname'); - $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); - $payerEl->appendChild($lastnameEl); - - $companyEl = $domTree->createElement('company'); - $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); - $payerEl->appendChild($companyEl); - - $addressEl = $domTree->createElement('address'); - - $line1El = $domTree->createElement('line1'); - $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); - $addressEl->appendChild($line1El); - - $line2El = $domTree->createElement('line2'); - $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); - $addressEl->appendChild($line2El); - - $cityEl = $domTree->createElement('city'); - $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); - $addressEl->appendChild($cityEl); - - $countyEl = $domTree->createElement('county'); - $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); - $addressEl->appendChild($countyEl); - - $postcodeEl = $domTree->createElement('postcode'); - $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); - $addressEl->appendChild($postcodeEl); - - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - - $payerEl->appendChild($addressEl); - - $phonenumbersEl = $domTree->createElement('phonenumbers'); - $homeEl = $domTree->createElement('home'); - $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); - $phonenumbersEl->appendChild($homeEl); - $payerEl->appendChild($phonenumbersEl); - - $emailEl = $domTree->createElement('email'); - $emailEl->appendChild($domTree->createTextNode($card->getEmail())); - $payerEl->appendChild($emailEl); - - $root->appendChild($payerEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new CreateCustomerResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('AuthEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('AuthEndpoint', $value); - } } diff --git a/src/Omnipay/Realex/Message/CreateCustomerResponse.php b/src/Omnipay/Realex/Message/CreateCustomerResponse.php index 1e86394..7ae2a03 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerResponse.php +++ b/src/Omnipay/Realex/Message/CreateCustomerResponse.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,38 +7,33 @@ namespace Omnipay\Realex\Message; -class CreateCustomerResponse extends RemoteAbstractResponse -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function getMessage() - { - return (string) $this->xml->message; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } +class CreateCustomerResponse extends RemoteAbstractResponse { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } + } diff --git a/src/Omnipay/Realex/Message/DeleteCardRequest.php b/src/Omnipay/Realex/Message/DeleteCardRequest.php index 232c512..3ba7b64 100644 --- a/src/Omnipay/Realex/Message/DeleteCardRequest.php +++ b/src/Omnipay/Realex/Message/DeleteCardRequest.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,78 +7,72 @@ namespace Omnipay\Realex\Message; +class DeleteCardRequest extends RemoteAbstractRequest { + + public function getCustomerRef() { + return $this->getParameter('customerRef'); + } -class DeleteCardRequest extends RemoteAbstractRequest -{ + public function setCustomerRef($customerRef) { + $this->setParameter('customerRef', $customerRef); + } - public function getCustomerRef() - { - return $this->getParameter('customerRef'); - } + public function getData() { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); - public function setCustomerRef($customerRef) - { - $this->setParameter('customerRef', $customerRef); - } + $tmp = "$timestamp.$merchantId.$payerRef.{$this->getCardReference()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); - public function getData() - { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); + $domTree = new \DOMDocument('1.0', 'UTF-8'); - $tmp = "$timestamp.$merchantId.$payerRef.{$this->getCardReference()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-cancel-card'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); - $domTree = new \DOMDocument('1.0', 'UTF-8'); + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-cancel-card'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); + $cardEl = $domTree->createElement('card'); - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); - $cardEl = $domTree->createElement('card'); + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); + $root->appendChild($cardEl); - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); - $root->appendChild($cardEl); + $xmlString = $domTree->saveXML($root); - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); + return $xmlString; + } - $xmlString = $domTree->saveXML($root); + protected function createResponse($data) { + return $this->response = new DeleteCardResponse($this, $data); + } - return $xmlString; - } + public function getEndpoint() { + return $this->getParameter('AuthEndpoint'); + } - protected function createResponse($data) - { - return $this->response = new DeleteCardResponse($this, $data); - } + public function setAuthEndpoint($value) { + return $this->setParameter('AuthEndpoint', $value); + } - public function getEndpoint() - { - return $this->getParameter('AuthEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('AuthEndpoint', $value); - } } diff --git a/src/Omnipay/Realex/Message/DeleteCardResponse.php b/src/Omnipay/Realex/Message/DeleteCardResponse.php index cec43dc..705d5cd 100644 --- a/src/Omnipay/Realex/Message/DeleteCardResponse.php +++ b/src/Omnipay/Realex/Message/DeleteCardResponse.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,38 +7,33 @@ namespace Omnipay\Realex\Message; -class DeleteCardResponse extends RemoteAbstractResponse -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function getMessage() - { - return (string) $this->xml->message; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } +class DeleteCardResponse extends RemoteAbstractResponse { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } + } diff --git a/src/Omnipay/Realex/Message/EnrolmentRequest.php b/src/Omnipay/Realex/Message/EnrolmentRequest.php index a3efdbc..01445bb 100644 --- a/src/Omnipay/Realex/Message/EnrolmentRequest.php +++ b/src/Omnipay/Realex/Message/EnrolmentRequest.php @@ -7,128 +7,125 @@ /** * Realex 3D Secure enrolment request */ -class EnrolmentRequest extends RemoteAbstractRequest -{ - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() - { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', '3ds-verifyenrolled'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $cvnEl = $domTree->createElement('cvn'); - - $cvnNumberEl = $domTree->createElement('number'); - $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); - $cvnEl->appendChild($cvnNumberEl); - - $presIndEl = $domTree->createElement('presind', 1); - $cvnEl->appendChild($presIndEl); - - $cardEl->appendChild($cvnEl); - - $issueEl = $domTree->createElement('issueno'); - $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - /** - * We need to inspect this response to see if the customer is actually - * enrolled in the 3D Secure program. If they're not, we can go ahead - * and do a normal auth instead. - */ - $response = $this->response = new EnrolmentResponse($this, $data); - - if (!$response->isEnrolled()) { - $request = new AuthRequest($this->httpClient, $this->httpRequest); - $request->initialize($this->getParameters()); - - $response = $request->send(); - } - - return $response; - } +class EnrolmentRequest extends RemoteAbstractRequest { + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', '3ds-verifyenrolled'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $cvnEl = $domTree->createElement('cvn'); + + $cvnNumberEl = $domTree->createElement('number'); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); + $cvnEl->appendChild($cvnNumberEl); + + $presIndEl = $domTree->createElement('presind', 1); + $cvnEl->appendChild($presIndEl); + + $cardEl->appendChild($cvnEl); + + $issueEl = $domTree->createElement('issueno'); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + /** + * We need to inspect this response to see if the customer is actually + * enrolled in the 3D Secure program. If they're not, we can go ahead + * and do a normal auth instead. + */ + $response = $this->response = new EnrolmentResponse($this, $data); + + if (!$response->isEnrolled()) { + $request = new AuthRequest($this->httpClient, $this->httpRequest); + $request->initialize($this->getParameters()); + + $response = $request->send(); + } + + return $response; + } // public function getEndpoint() // { @@ -138,14 +135,13 @@ protected function createResponse($data) // { // return $this->setParameter('3dSecureEndpoint', $value); // } - - public function getEndpoint() - { - return $this->getParameter('authEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('authEndpoint', $value); - } - + + public function getEndpoint() { + return $this->getParameter('authEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('authEndpoint', $value); + } + } diff --git a/src/Omnipay/Realex/Message/EnrolmentResponse.php b/src/Omnipay/Realex/Message/EnrolmentResponse.php index ce563bb..3f2670b 100644 --- a/src/Omnipay/Realex/Message/EnrolmentResponse.php +++ b/src/Omnipay/Realex/Message/EnrolmentResponse.php @@ -14,86 +14,78 @@ * * @property EnrolmentRequest $request */ -class EnrolmentResponse extends RemoteAbstractResponse implements RedirectResponseInterface -{ - public function isSuccessful() - { - return false; - } - - public function isEnrolled() - { - return $this->xml->enrolled == 'Y'; - } - - public function getMessage() - { - $message = (string)$this->xml->message; - - return $message; - } - - public function getTransactionReference() - { - $transactionReference = !empty($this->xml->pasref) ? $this->xml->pasref : null; - - return $transactionReference; - } - - public function isRedirect() - { - if ($this->xml->result == '00' && $this->xml->enrolled == 'Y') { - return true; - } else { - return false; - } - } - - public function getRedirectUrl() - { - return (string)$this->xml->url; - } - - public function getRedirectMethod() - { - return 'POST'; - } - - /** - * Any encrypted data that we wish to have returned to us. - * Basically, this is all the card data that we will have to - * re-submit to to Realex in order to complete the authorisation. - */ - protected function getMerchantData() - { - /** - * @var CreditCard $card - */ - $card = $this->request->getCard(); - $data = array( - 'transactionId' => $this->request->getTransactionId(), - 'currency' => $this->request->getCurrency(), - 'amount' => $this->request->getAmount(), - 'number' => $card->getNumber(), - 'expiryMonth' => $card->getExpiryMonth(), - 'expiryYear' => $card->getExpiryYear(), - 'billingName' => $card->getBillingName(), - 'cvv' => $card->getCvv(), - 'issueNumber' => $card->getIssueNumber(), - 'billingCountry' => $card->getBillingCountry() - ); - $serialised = json_encode($data); - $encoded = base64_encode($serialised); - - return $encoded; - } - - public function getRedirectData() - { - return array( - 'PaReq' => (string)$this->xml->pareq, - 'TermUrl' => $this->request->getReturnUrl(), - 'MD' => $this->getMerchantData() - ); - } +class EnrolmentResponse extends RemoteAbstractResponse implements RedirectResponseInterface { + + public function isSuccessful() { + return false; + } + + public function isEnrolled() { + return $this->xml->enrolled == 'Y'; + } + + public function getMessage() { + $message = (string) $this->xml->message; + + return $message; + } + + public function getTransactionReference() { + $transactionReference = !empty($this->xml->pasref) ? $this->xml->pasref : null; + + return $transactionReference; + } + + public function isRedirect() { + if ($this->xml->result == '00' && $this->xml->enrolled == 'Y') { + return true; + } else { + return false; + } + } + + public function getRedirectUrl() { + return (string) $this->xml->url; + } + + public function getRedirectMethod() { + return 'POST'; + } + + /** + * Any encrypted data that we wish to have returned to us. + * Basically, this is all the card data that we will have to + * re-submit to to Realex in order to complete the authorisation. + */ + protected function getMerchantData() { + /** + * @var CreditCard $card + */ + $card = $this->request->getCard(); + $data = array( + 'transactionId' => $this->request->getTransactionId(), + 'currency' => $this->request->getCurrency(), + 'amount' => $this->request->getAmount(), + 'number' => $card->getNumber(), + 'expiryMonth' => $card->getExpiryMonth(), + 'expiryYear' => $card->getExpiryYear(), + 'billingName' => $card->getBillingName(), + 'cvv' => $card->getCvv(), + 'issueNumber' => $card->getIssueNumber(), + 'billingCountry' => $card->getBillingCountry() + ); + $serialised = json_encode($data); + $encoded = base64_encode($serialised); + + return $encoded; + } + + public function getRedirectData() { + return array( + 'PaReq' => (string) $this->xml->pareq, + 'TermUrl' => $this->request->getReturnUrl(), + 'MD' => $this->getMerchantData() + ); + } + } diff --git a/src/Omnipay/Realex/Message/FetchTransactionRequest.php b/src/Omnipay/Realex/Message/FetchTransactionRequest.php index 4b8e0d1..1273c64 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionRequest.php +++ b/src/Omnipay/Realex/Message/FetchTransactionRequest.php @@ -7,75 +7,72 @@ /** * Realex Query Request */ -class FetchTransactionRequest extends RemoteAbstractRequest -{ - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() - { - $this->validate('transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - // No amount, currency or card number for query requests but still needs to be in hash - $amount = ''; - $currency = ''; - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'query'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // original order ID - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($orderIdEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new FetchTransactionResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('3dSecureEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('3dSecureEndpoint', $value); - } +class FetchTransactionRequest extends RemoteAbstractRequest { + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() { + $this->validate('transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + // No amount, currency or card number for query requests but still needs to be in hash + $amount = ''; + $currency = ''; + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'query'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // original order ID + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($orderIdEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new FetchTransactionResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('3dSecureEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('3dSecureEndpoint', $value); + } + } diff --git a/src/Omnipay/Realex/Message/FetchTransactionResponse.php b/src/Omnipay/Realex/Message/FetchTransactionResponse.php index 721ab63..3eec6e6 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionResponse.php +++ b/src/Omnipay/Realex/Message/FetchTransactionResponse.php @@ -10,53 +10,45 @@ /** * Realex Query Response */ -class FetchTransactionResponse extends RemoteAbstractResponse implements RedirectResponseInterface -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function getMessage() - { - return (string)$this->xml->message; - } - - public function getTransactionId() - { - return ($this->xml->orderid) ? (string)$this->xml->orderid : null; - } - - public function getTransactionReference() - { - return ($this->xml->pasref) ? (string)$this->xml->pasref : null; - } - - public function getAuthCode() - { - return ($this->xml->authcode) ? (string)$this->xml->authcode : null; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } +class FetchTransactionResponse extends RemoteAbstractResponse implements RedirectResponseInterface { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function getTransactionId() { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } + } diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index 41704bd..e01c73d 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -1,175 +1,174 @@ getParameter('merchantId'); - } - public function setMerchantId($value) - { - return $this->setParameter('merchantId', $value); - } - public function getAccount() - { - return $this->getParameter('account'); - } - public function setAccount($value) - { - return $this->setParameter('account', $value); - } - public function getSecret() - { - return $this->getParameter('secret'); - } - public function setSecret($value) - { - return $this->setParameter('secret', $value); - } - public function setStore($value) - { - return $this->setParameter('store', $value); - } - public function getStore() - { - return $this->getParameters('store'); - } - public function getPares() - { - return $this->getParameter('pares'); - } - public function setPares($value) - { - return $this->setParameter('pares', $value); - } - public function setCavv($value) - { - return $this->setParameter('cavv', $value); - } - public function getCavv() - { - return $this->getParameter('cavv'); - } - public function setXid($value) - { - return $this->setParameter('xid', $value); - } - public function getXid() - { - return $this->getParameter('xid'); - } - public function setEci($value) - { - return $this->setParameter('eci', $value); - } - public function getEci() - { - return $this->getParameter('eci'); - } - public function setNotifyUrl($value) - { - return $this->setParameter('notifyUrl', $value); - } - public function getNotifyUrl() - { - return $this->getParameter('notifyUrl'); - } - public function setExtraData($value) - { - return $this->setParameter('extraData', $value); - } - public function getExtraData() - { - return $this->getParameter('extraData'); - } - public function getBaseData($autoSettle = true, $card = null) - { - $data = array( - 'EXTRA' => $this->getExtraData(), - 'MERCHANT_ID' => $this->getMerchantId(), - 'ORDER_ID' => $this->getTransactionId(), - 'CURRENCY' => $this->getCurrency(), - 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), - 'AMOUNT' => round( $this->getAmount() * 100 ), - 'TIMESTAMP' => gmdate('YmdHis'), - 'AUTO_SETTLE_FLAG' => $autoSettle - ); - $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); - return $data; - } - public function createSignature($data, $method = 'sha1', $card = null) - { - $hash = $method(rtrim(implode('.', array( - $data['TIMESTAMP'], - $data['MERCHANT_ID'], - $data['ORDER_ID'], - $data['AMOUNT'], - $data['CURRENCY'], - $card !== null ? $card->getNumber() : null - )), '.')); - - return $method($hash.'.'.$this->getSecret()); - } - public function getRequestXML($card, $autoSettle = true, $extraData = array(), $addressData = true, $cardData = true) - { - $data = $this->getBaseData($autoSettle, $card); - $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); - $request = new \SimpleXMLElement(''); - $request['timestamp'] = $data['TIMESTAMP']; - $request['type'] = $this->getType(); - $request->merchantid = $this->getMerchantId(); - $request->account = $this->getAccount(); - $request->orderid = $data['ORDER_ID']; - //$request->md5hash = $this->createSignature($data, 'md5', $card); - $request->custipaddress = $this->getClientIp(); - $request->amount = $data['AMOUNT']; - $request->amount['currency'] = $data['CURRENCY']; - $request->autosettle['flag'] = (int)$data['AUTO_SETTLE_FLAG']; - // Flesh out the XML structure - $request->addChild('card'); - $request->card->addChild('cvn'); - $request->card->number = $card->getNumber(); - $request->card->expdate = $card->getExpiryDate('my'); - $request->card->type = strtoupper($brand); - $request->card->chname = $card->getName(); - // Not all request want this data - if($cardData) { - $request->card->issueno = $card->getIssueNumber(); - $request->card->addChild('cvn'); - $request->card->cvn->addChild('number', $card->getCvv()); - $request->card->cvn->addChild('presind', 1); - } - // not all requests want this data - if($addressData) { - $request->address['type'] = 'billing'; - $request->address->code = $card->getBillingPostcode(); - $request->address->country = strtoupper($card->getBillingCountry()); - } - // Add in extra array data for any obscure fields - if(!empty($extraData)) { - foreach($extraData as $key => $value) { - $request->$key = $value; - } - } - $request->sha1hash = $data['SHA1HASH']; - return $request->asXML(); - } - protected function getType() - { - return 'auth'; - } - - public function getCheckoutEndpoint() - { - return $this->getParameter('checkoutEndpoint'); - } - - public function setCheckoutEndpoint($value) - { - return $this->setParameter('checkoutEndpoint', $value); - } - -} \ No newline at end of file +abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { + + public function getMerchantId() { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() { + return $this->getParameter('account'); + } + + public function setAccount($value) { + return $this->setParameter('account', $value); + } + + public function getSecret() { + return $this->getParameter('secret'); + } + + public function setSecret($value) { + return $this->setParameter('secret', $value); + } + + public function setStore($value) { + return $this->setParameter('store', $value); + } + + public function getStore() { + return $this->getParameters('store'); + } + + public function getPares() { + return $this->getParameter('pares'); + } + + public function setPares($value) { + return $this->setParameter('pares', $value); + } + + public function setCavv($value) { + return $this->setParameter('cavv', $value); + } + + public function getCavv() { + return $this->getParameter('cavv'); + } + + public function setXid($value) { + return $this->setParameter('xid', $value); + } + + public function getXid() { + return $this->getParameter('xid'); + } + + public function setEci($value) { + return $this->setParameter('eci', $value); + } + + public function getEci() { + return $this->getParameter('eci'); + } + + public function setNotifyUrl($value) { + return $this->setParameter('notifyUrl', $value); + } + + public function getNotifyUrl() { + return $this->getParameter('notifyUrl'); + } + + public function setExtraData($value) { + return $this->setParameter('extraData', $value); + } + + public function getExtraData() { + return $this->getParameter('extraData'); + } + + public function getBaseData($autoSettle = true, $card = null) { + $data = array( + 'EXTRA' => $this->getExtraData(), + 'MERCHANT_ID' => $this->getMerchantId(), + 'ORDER_ID' => $this->getTransactionId(), + 'CURRENCY' => $this->getCurrency(), + 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), + 'AMOUNT' => round($this->getAmount() * 100), + 'TIMESTAMP' => gmdate('YmdHis'), + 'AUTO_SETTLE_FLAG' => $autoSettle + ); + $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); + return $data; + } + + public function createSignature($data, $method = 'sha1', $card = null) { + $hash = $method(rtrim(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['AMOUNT'], + $data['CURRENCY'], + $card !== null ? $card->getNumber() : null + )), '.')); + + return $method($hash . '.' . $this->getSecret()); + } + + public function getRequestXML($card, $autoSettle = true, $extraData = array(), $addressData = true, $cardData = true) { + $data = $this->getBaseData($autoSettle, $card); + $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); + $request = new \SimpleXMLElement(''); + $request['timestamp'] = $data['TIMESTAMP']; + $request['type'] = $this->getType(); + $request->merchantid = $this->getMerchantId(); + $request->account = $this->getAccount(); + $request->orderid = $data['ORDER_ID']; + //$request->md5hash = $this->createSignature($data, 'md5', $card); + $request->custipaddress = $this->getClientIp(); + $request->amount = $data['AMOUNT']; + $request->amount['currency'] = $data['CURRENCY']; + $request->autosettle['flag'] = (int) $data['AUTO_SETTLE_FLAG']; + // Flesh out the XML structure + $request->addChild('card'); + $request->card->addChild('cvn'); + $request->card->number = $card->getNumber(); + $request->card->expdate = $card->getExpiryDate('my'); + $request->card->type = strtoupper($brand); + $request->card->chname = $card->getName(); + // Not all request want this data + if ($cardData) { + $request->card->issueno = $card->getIssueNumber(); + $request->card->addChild('cvn'); + $request->card->cvn->addChild('number', $card->getCvv()); + $request->card->cvn->addChild('presind', 1); + } + // not all requests want this data + if ($addressData) { + $request->address['type'] = 'billing'; + $request->address->code = $card->getBillingPostcode(); + $request->address->country = strtoupper($card->getBillingCountry()); + } + // Add in extra array data for any obscure fields + if (!empty($extraData)) { + foreach ($extraData as $key => $value) { + $request->$key = $value; + } + } + $request->sha1hash = $data['SHA1HASH']; + return $request->asXML(); + } + + protected function getType() { + return 'auth'; + } + + public function getCheckoutEndpoint() { + return $this->getParameter('checkoutEndpoint'); + } + + public function setCheckoutEndpoint($value) { + return $this->setParameter('checkoutEndpoint', $value); + } + +} diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php index b634244..1fb3117 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php @@ -5,20 +5,18 @@ /** * Realex Redirect Authorize Request */ -class RedirectAuthorizeRequest extends AbstractRequest -{ - public function getData() - { - return null; - } +class RedirectAuthorizeRequest extends AbstractRequest { - public function getRedirectData() - { - return $this->getBaseData(); - } + public function getData() { + return null; + } + + public function getRedirectData() { + return $this->getBaseData(); + } + + public function sendData($data) { + return $this->response = new RedirectAuthorizeResponse($this, $data); + } - public function sendData($data) - { - return $this->response = new RedirectAuthorizeResponse($this, $data); - } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php index 5837e2d..4e60f0c 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php @@ -7,37 +7,30 @@ /** * Realex Redirect Authorize Response */ -class RedirectAuthorizeResponse extends Response implements RedirectResponseInterface -{ - - public function isSuccessful() - { - return false; - } - - public function isRedirect() - { - return true; - } - - public function getRedirectUrl() - { - return $this->getRequest()->getCheckoutEndpoint(); - } - - public function getTransactionReference() - { - return $this->getRequest()->getTransactionId(); - } - - public function getRedirectMethod() - { - return 'POST'; - } - - public function getRedirectData() - { - return $this->getRequest()->getBaseData(false); - } +class RedirectAuthorizeResponse extends Response implements RedirectResponseInterface { + + public function isSuccessful() { + return false; + } + + public function isRedirect() { + return true; + } + + public function getRedirectUrl() { + return $this->getRequest()->getCheckoutEndpoint(); + } + + public function getTransactionReference() { + return $this->getRequest()->getTransactionId(); + } + + public function getRedirectMethod() { + return 'POST'; + } + + public function getRedirectData() { + return $this->getRequest()->getBaseData(false); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php index 8e35697..bc541da 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php @@ -7,31 +7,30 @@ /** * Realex Redirect Complete Authorize Request */ -class RedirectCompleteAuthorizeRequest extends AbstractRequest -{ - public function getData() - { - // Build initial hash - $hash = sha1(implode('.', array( - $this->httpRequest->request->get('TIMESTAMP'), - $this->httpRequest->request->get('MERCHANT_ID'), - $this->httpRequest->request->get('ORDER_ID'), - $this->httpRequest->request->get('RESULT'), - $this->httpRequest->request->get('MESSAGE'), - $this->httpRequest->request->get('PASREF'), - $this->httpRequest->request->get('AUTHCODE') - ))); - - // Validate signature - if ( $this->httpRequest->request->get('SHA1HASH') !== sha1($hash.'.'.$this->getSecret()) ) { - throw new InvalidResponseException; - } - - return $this->httpRequest->request->all(); - } - - public function sendData($data) - { - return $this->response = new Response($this, $data); - } +class RedirectCompleteAuthorizeRequest extends AbstractRequest { + + public function getData() { + // Build initial hash + $hash = sha1(implode('.', array( + $this->httpRequest->request->get('TIMESTAMP'), + $this->httpRequest->request->get('MERCHANT_ID'), + $this->httpRequest->request->get('ORDER_ID'), + $this->httpRequest->request->get('RESULT'), + $this->httpRequest->request->get('MESSAGE'), + $this->httpRequest->request->get('PASREF'), + $this->httpRequest->request->get('AUTHCODE') + ))); + + // Validate signature + if ($this->httpRequest->request->get('SHA1HASH') !== sha1($hash . '.' . $this->getSecret())) { + throw new InvalidResponseException; + } + + return $this->httpRequest->request->all(); + } + + public function sendData($data) { + return $this->response = new Response($this, $data); + } + } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php index aa7b30c..add0e61 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php @@ -7,18 +7,17 @@ /** * Realex Redirect Complete Authorize Request */ -class RedirectCompleteStoreCardRequest extends AbstractRequest -{ - public function getData() - { - +class RedirectCompleteStoreCardRequest extends AbstractRequest { + + public function getData() { + $data; foreach (json_decode($this->httpRequest->request->get('hppResponse')) AS $key => $value) { $data[$key] = base64_decode($value); } - // Build initial hash - $hash = sha1(implode('.', array( + // Build initial hash + $hash = sha1(implode('.', array( $data['TIMESTAMP'], $data['MERCHANT_ID'], $data['ORDER_ID'], @@ -26,18 +25,18 @@ public function getData() $data['MESSAGE'], $data['PASREF'], $data['AUTHCODE'], - ))); + ))); + + // Validate signature + if ($data['SHA1HASH'] !== sha1($hash . '.' . $this->getSecret())) { + throw new InvalidResponseException; + } - // Validate signature - if ( $data['SHA1HASH'] !== sha1($hash.'.'.$this->getSecret()) ) { - throw new InvalidResponseException; - } + return $data; + } - return $data; - } + public function sendData($data) { + return $this->response = new dataVaultResponse($this, $data); + } - public function sendData($data) - { - return $this->response = new dataVaultResponse($this, $data); - } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php index 7a907e3..e4f33b2 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php @@ -23,30 +23,31 @@ public function getBaseData($autoSettle = '1', $card = null) { 'AUTO_SETTLE_FLAG' => $autoSettle, 'HPP_VERSION' => 2 ); - - if(isset($this->getData()['extraData']) && is_array($this->getData()['extraData'])) { - $data = array_merge($data,$this->getData()['extraData']); + + if (isset($this->getData()['extraData']) && is_array($this->getData()['extraData'])) { + $data = array_merge($data, $this->getData()['extraData']); } $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); return $data; } + /* * "timestamp.merchantid.orderid.amount.currency.payerref.paymentmethod" */ - public function createSignature($data, $method = 'sha1', $card = null) - { - $hash = $method(implode('.', array( - $data['TIMESTAMP'], - $data['MERCHANT_ID'], - $data['ORDER_ID'], - $data['AMOUNT'], - $data['CURRENCY'], - $data['PAYER_REF'], + + public function createSignature($data, $method = 'sha1', $card = null) { + $hash = $method(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['AMOUNT'], + $data['CURRENCY'], + $data['PAYER_REF'], '' - ))); - - return $method($hash.'.'.$this->getSecret()); - } + ))); + + return $method($hash . '.' . $this->getSecret()); + } public function getRedirectData() { return $this->getBaseData(); diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php index e326f79..855727c 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php @@ -7,38 +7,31 @@ /** * Realex Redirect Authorize Response */ -class RedirectDataVaultResponse extends Response implements RedirectResponseInterface -{ - - public function isSuccessful() - { - return false; - } - - public function isRedirect() - { - return true; - } - - public function getRedirectUrl() - { - return $this->getRequest()->getCheckoutEndpoint(); - } - - public function getTransactionReference() - { - return $this->getRequest()->getTransactionId(); - } - - public function getRedirectMethod() - { - return 'POST'; - } - - public function getRedirectData() - { +class RedirectDataVaultResponse extends Response implements RedirectResponseInterface { + + public function isSuccessful() { + return false; + } + + public function isRedirect() { + return true; + } + + public function getRedirectUrl() { + return $this->getRequest()->getCheckoutEndpoint(); + } + + public function getTransactionReference() { + return $this->getRequest()->getTransactionId(); + } + + public function getRedirectMethod() { + return 'POST'; + } + + public function getRedirectData() { $data = $this->getRequest()->getBaseData(false); - return $data; - } + return $data; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php index 91d8365..fab5395 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php @@ -5,10 +5,10 @@ /** * Realex Redirect Purchase Request */ -class RedirectPurchaseRequest extends RedirectAuthorizeRequest -{ - public function sendData($data) - { - return $this->response = new RedirectPurchaseResponse($this, $data); - } +class RedirectPurchaseRequest extends RedirectAuthorizeRequest { + + public function sendData($data) { + return $this->response = new RedirectPurchaseResponse($this, $data); + } + } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php index afd4b15..221a515 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php @@ -7,10 +7,10 @@ /** * Realex Redirect Purchase Response */ -class RedirectPurchaseResponse extends RedirectAuthorizeResponse -{ - public function getRedirectData() - { - return $this->getRequest()->getBaseData(); - } +class RedirectPurchaseResponse extends RedirectAuthorizeResponse { + + public function getRedirectData() { + return $this->getRequest()->getBaseData(); + } + } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php index fe8bb9a..0fe48fd 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php @@ -5,73 +5,66 @@ /** * Realex Redirect Purchase Request */ -class RedirectStoreCardRequest extends RedirectDataVaultRequest -{ - public function getCustomerRef() - { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($data) - { - $this->setParameter('customerRef', $data); - } - public function getCustomerExists() - { - return $this->getParameter('customerExists'); - } - - public function setCustomerExists($data) - { - $this->setParameter('customerExists', $data); - } - public function getValidateCardOnly() - { - return $this->getParameter('validateCardOnly'); - } - - public function setValidateCardOnly($data) - { - $this->setParameter('validateCardOnly', $data); - } - public function getOfferSaveCard() - { - return $this->getParameter('offerSaveCard'); - } - - public function setOfferSaveCard($data) - { - $this->setParameter('offerSaveCard', $data); - } - public function getCardPaymentButton() - { - return $this->getParameter('cardPaymentButton'); - } - - public function setCardPaymentButton($data) - { - $this->setParameter('cardPaymentButton', $data); - } - public function getHPPPostDimensions() - { - return $this->getParameter('HPPPostDimensions'); - } - - public function setHPPPostDimensions($data) - { - $this->setParameter('HPPPostDimensions', $data); - } - public function getHPPPostResponse() - { - return $this->getParameter('HPPPostResponse'); - } - - public function setHPPPostResponse($data) - { - $this->setParameter('HPPPostResponse', $data); - } +class RedirectStoreCardRequest extends RedirectDataVaultRequest { + + public function getCustomerRef() { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($data) { + $this->setParameter('customerRef', $data); + } + + public function getCustomerExists() { + return $this->getParameter('customerExists'); + } + + public function setCustomerExists($data) { + $this->setParameter('customerExists', $data); + } + + public function getValidateCardOnly() { + return $this->getParameter('validateCardOnly'); + } + + public function setValidateCardOnly($data) { + $this->setParameter('validateCardOnly', $data); + } + + public function getOfferSaveCard() { + return $this->getParameter('offerSaveCard'); + } + + public function setOfferSaveCard($data) { + $this->setParameter('offerSaveCard', $data); + } + + public function getCardPaymentButton() { + return $this->getParameter('cardPaymentButton'); + } + + public function setCardPaymentButton($data) { + $this->setParameter('cardPaymentButton', $data); + } + + public function getHPPPostDimensions() { + return $this->getParameter('HPPPostDimensions'); + } + + public function setHPPPostDimensions($data) { + $this->setParameter('HPPPostDimensions', $data); + } + + public function getHPPPostResponse() { + return $this->getParameter('HPPPostResponse'); + } + + public function setHPPPostResponse($data) { + $this->setParameter('HPPPostResponse', $data); + } + public function getData() { - + $data['extraData'] = [ 'PAYER_REF' => $this->getCustomerRef(), 'PAYER_EXIST' => $this->getCustomerExists(), @@ -81,13 +74,13 @@ public function getData() { 'CARD_PAYMENT_BUTTON' => $this->getCardPaymentButton(), 'HPP_POST_DIMENSIONS' => $this->getHPPPostDimensions(), 'HPP_POST_RESPONSE' => $this->getHPPPostResponse(), - ]; + ]; return $data; } - public function sendData($data) - { - return $this->response = new RedirectStoreCardResponse($this, $data); - } - + + public function sendData($data) { + return $this->response = new RedirectStoreCardResponse($this, $data); + } + } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php index 2c59caa..0d5b77a 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php @@ -7,12 +7,12 @@ /** * Realex Redirect Purchase Response */ -class RedirectStoreCardResponse extends RedirectDataVaultResponse -{ - public function getRedirectData() - { +class RedirectStoreCardResponse extends RedirectDataVaultResponse { + + public function getRedirectData() { $data = $this->getRequest()->getRedirectData(); - return $data; - } + return $data; + } + } diff --git a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php index 0131f5c..5a710e0 100644 --- a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php @@ -1,55 +1,59 @@ request = $request; - $this->data = $data; - } - public function isSuccessful() - { - if(!$this->isPayerSetupSuccessful()){ +class dataVaultResponse extends AbstractResponse { + + public function __construct(RequestInterface $request, $data = array()) { + $this->request = $request; + $this->data = $data; + } + + public function isSuccessful() { + if (!$this->isPayerSetupSuccessful()) { return false; - } elseif(!$this->isPayerCardAddSuccessful()){ + } elseif (!$this->isPayerCardAddSuccessful()) { return false; } else { return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; } + } - } - public function getMessage() - { + public function getMessage() { $message; - if(isset($this->data['PMT_SETUP_MSG'])){ + if (isset($this->data['PMT_SETUP_MSG'])) { $message .= $this->data['PMT_SETUP_MSG'] . ' '; } - if(isset($this->data['PAYER_SETUP_MSG'])){ + if (isset($this->data['PAYER_SETUP_MSG'])) { $message .= $this->data['PAYER_SETUP_MSG'] . ' '; } - if(isset($this->data['MESSAGE'])){ + if (isset($this->data['MESSAGE'])) { $message .= $this->data['MESSAGE'] . ' '; } - - return $message; - } - public function getTransactionReference() - { - return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; - } - - public function isPayerSetupSuccessful(){ + + return $message; + } + + public function getTransactionReference() { + return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; + } + + public function isPayerSetupSuccessful() { return !isset($this->data['PAYER_SETUP']) || (isset($this->data['PAYER_SETUP']) && '00' === $this->data['PAYER_SETUP']); } - public function isPayerCardAddSuccessful(){ + + public function isPayerCardAddSuccessful() { return !isset($this->data['PMT_SETUP']) || (isset($this->data['PMT_SETUP']) && '00' === $this->data['PMT_SETUP']); } - public function getCardToken(){ + + public function getCardToken() { return isset($this->data['SAVED_PMT_REF']) ? $this->data['SAVED_PMT_REF'] : null; } -} \ No newline at end of file + +} diff --git a/src/Omnipay/Realex/Message/Redirect/response.php b/src/Omnipay/Realex/Message/Redirect/response.php index 3b7018f..3fe32e8 100644 --- a/src/Omnipay/Realex/Message/Redirect/response.php +++ b/src/Omnipay/Realex/Message/Redirect/response.php @@ -1,27 +1,30 @@ request = $request; - $this->data = $data; - } - public function isSuccessful() - { - return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; - } - public function getMessage() - { - return isset($this->data['MESSAGE']) ? $this->data['MESSAGE'] : null; - } - public function getTransactionReference() - { - return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; - } -} \ No newline at end of file +class Response extends AbstractResponse { + + public function __construct(RequestInterface $request, $data = array()) { + $this->request = $request; + $this->data = $data; + } + + public function isSuccessful() { + return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; + } + + public function getMessage() { + return isset($this->data['MESSAGE']) ? $this->data['MESSAGE'] : null; + } + + public function getTransactionReference() { + return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; + } + +} diff --git a/src/Omnipay/Realex/Message/RefundRequest.php b/src/Omnipay/Realex/Message/RefundRequest.php index 7a639cd..ef31e19 100644 --- a/src/Omnipay/Realex/Message/RefundRequest.php +++ b/src/Omnipay/Realex/Message/RefundRequest.php @@ -7,145 +7,128 @@ /** * Realex Refund Request */ -class RefundRequest extends RemoteAbstractRequest -{ - - public function getTransactionReference() - { - return $this->getParameter('transactionReference'); - } - - public function setTransactionReference($value) - { - return $this->setParameter('transactionReference', $value); - } - - public function getAuthCode() - { - return $this->getParameter('authCode'); - } - - public function setAuthCode($value) - { - return $this->setParameter('authCode', $value); - } - - public function getOriginalTransactionId() - { - return $this->getParameter('originalTransactionId'); - } - - public function setOriginalTransactionId($value) - { - return $this->setParameter('originalTransactionId', $value); - } - - public function getRefundPassword() - { - return $this->getParameter('refundPassword'); - } - - public function setRefundPassword($value) - { - return $this->setParameter('refundPassword', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() - { - $this->validate( - 'amount', - 'currency', - 'originalTransactionId', - 'transactionReference', - 'authCode', - 'refundPassword' - ); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $originalTransactionId = $this->getOriginalTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - // No card number for rebate requests but still needs to be in hash - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp - = "$timestamp.$merchantId.$originalTransactionId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'rebate'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // the ID of the original transaction (confusingly in a tag called 'orderid') - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); - $root->appendChild($orderIdEl); - - // pasref for the original transaction - $pasRefEl = $domTree->createElement('pasref'); - $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); - $root->appendChild($pasRefEl); - - // authcode returned for original transaction - $authCodeEl = $domTree->createElement('authcode'); - $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); - $root->appendChild($authCodeEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - // refund hash - $refundHash = sha1($this->getRefundPassword()); - $refundHashEl = $domTree->createElement('refundhash'); - $refundHashEl->appendChild($domTree->createTextNode($refundHash)); - $root->appendChild($refundHashEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new RefundResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('AuthEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('AuthEndpoint', $value); - } +class RefundRequest extends RemoteAbstractRequest { + + public function getTransactionReference() { + return $this->getParameter('transactionReference'); + } + + public function setTransactionReference($value) { + return $this->setParameter('transactionReference', $value); + } + + public function getAuthCode() { + return $this->getParameter('authCode'); + } + + public function setAuthCode($value) { + return $this->setParameter('authCode', $value); + } + + public function getOriginalTransactionId() { + return $this->getParameter('originalTransactionId'); + } + + public function setOriginalTransactionId($value) { + return $this->setParameter('originalTransactionId', $value); + } + + public function getRefundPassword() { + return $this->getParameter('refundPassword'); + } + + public function setRefundPassword($value) { + return $this->setParameter('refundPassword', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() { + $this->validate( + 'amount', 'currency', 'originalTransactionId', 'transactionReference', 'authCode', 'refundPassword' + ); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $originalTransactionId = $this->getOriginalTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + // No card number for rebate requests but still needs to be in hash + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$originalTransactionId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'rebate'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // the ID of the original transaction (confusingly in a tag called 'orderid') + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); + $root->appendChild($orderIdEl); + + // pasref for the original transaction + $pasRefEl = $domTree->createElement('pasref'); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); + $root->appendChild($pasRefEl); + + // authcode returned for original transaction + $authCodeEl = $domTree->createElement('authcode'); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); + $root->appendChild($authCodeEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + // refund hash + $refundHash = sha1($this->getRefundPassword()); + $refundHashEl = $domTree->createElement('refundhash'); + $refundHashEl->appendChild($domTree->createTextNode($refundHash)); + $root->appendChild($refundHashEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new RefundResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('AuthEndpoint', $value); + } + } diff --git a/src/Omnipay/Realex/Message/RefundResponse.php b/src/Omnipay/Realex/Message/RefundResponse.php index 8b77150..3ab9688 100644 --- a/src/Omnipay/Realex/Message/RefundResponse.php +++ b/src/Omnipay/Realex/Message/RefundResponse.php @@ -10,53 +10,45 @@ /** * Realex Refund Response */ -class RefundResponse extends RemoteAbstractResponse implements RedirectResponseInterface -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function getMessage() - { - return (string)$this->xml->message; - } - - public function getTransactionId() - { - return ($this->xml->orderid) ? (string)$this->xml->orderid : null; - } - - public function getTransactionReference() - { - return ($this->xml->pasref) ? (string)$this->xml->pasref : null; - } - - public function getAuthCode() - { - return ($this->xml->authcode) ? (string)$this->xml->authcode : null; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } +class RefundResponse extends RemoteAbstractResponse implements RedirectResponseInterface { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function getTransactionId() { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } + } diff --git a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php index f4c66dc..611ae30 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php @@ -8,85 +8,75 @@ /** * Realex Purchase Request */ -abstract class RemoteAbstractRequest extends AbstractRequest -{ - protected $cardBrandMap = array( - 'mastercard' => 'mc', - 'diners_club' => 'diners' - ); - - /** - * Override some of the default Omnipay card brand names - * - * @return mixed - */ - protected function getCardBrand() - { - $brand = $this->getCard()->getBrand(); - - if (isset($this->cardBrandMap[$brand])) { - $brand = $this->cardBrandMap[$brand]; - } - - return strtoupper($brand); - } - - public function getMerchantId() - { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) - { - return $this->setParameter('merchantId', $value); - } - - public function getAccount() - { - return $this->getParameter('account'); - } - - public function setAccount($value) - { - return $this->setParameter('account', $value); - } - - public function getSecret() - { - return $this->getParameter('secret'); - } - - public function setSecret($value) - { - return $this->setParameter('secret', $value); - } - - public function getReturnUrl() - { - return $this->getParameter('returnUrl'); - } - - public function setReturnUrl($value) - { - return $this->setParameter('returnUrl', $value); - } - - public function sendData($data) - { - // register the payment - $this->httpClient->setConfig(array( - 'curl.options' => array( - 'CURLOPT_SSLVERSION' => 1, - 'CURLOPT_SSL_VERIFYPEER' => false - ) - )); - - $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); - - return $this->createResponse($httpResponse->getBody(true)); - } - - abstract public function getEndpoint(); - - abstract protected function createResponse($data); +abstract class RemoteAbstractRequest extends AbstractRequest { + + protected $cardBrandMap = array( + 'mastercard' => 'mc', + 'diners_club' => 'diners' + ); + + /** + * Override some of the default Omnipay card brand names + * + * @return mixed + */ + protected function getCardBrand() { + $brand = $this->getCard()->getBrand(); + + if (isset($this->cardBrandMap[$brand])) { + $brand = $this->cardBrandMap[$brand]; + } + + return strtoupper($brand); + } + + public function getMerchantId() { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() { + return $this->getParameter('account'); + } + + public function setAccount($value) { + return $this->setParameter('account', $value); + } + + public function getSecret() { + return $this->getParameter('secret'); + } + + public function setSecret($value) { + return $this->setParameter('secret', $value); + } + + public function getReturnUrl() { + return $this->getParameter('returnUrl'); + } + + public function setReturnUrl($value) { + return $this->setParameter('returnUrl', $value); + } + + public function sendData($data) { + // register the payment + $this->httpClient->setConfig(array( + 'curl.options' => array( + 'CURLOPT_SSLVERSION' => 1, + 'CURLOPT_SSL_VERIFYPEER' => false + ) + )); + + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); + + return $this->createResponse($httpResponse->getBody(true)); + } + + abstract public function getEndpoint(); + + abstract protected function createResponse($data); } diff --git a/src/Omnipay/Realex/Message/RemoteAbstractResponse.php b/src/Omnipay/Realex/Message/RemoteAbstractResponse.php index b6bc005..7a0a1ba 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractResponse.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractResponse.php @@ -11,29 +11,28 @@ /** * Realex Abstract Response */ -abstract class RemoteAbstractResponse extends AbstractResponse implements RedirectResponseInterface -{ - protected $xml; - - public function __construct(RequestInterface $request, $data) - { - parent::__construct($request, $data); - - $this->xml = $this->parseXml($data); - } - - /** - * Turn the raw XML response string into a SimpleXMLElement - * - * @param string $data - * @return \SimpleXMLElement - */ - public function parseXml($data) - { - $data = str_replace(' ', ' ', $data); - $data = str_replace("\n", '', $data); - $data = str_replace("\r", '', $data); - - return new \SimpleXMLElement($data); - } +abstract class RemoteAbstractResponse extends AbstractResponse implements RedirectResponseInterface { + + protected $xml; + + public function __construct(RequestInterface $request, $data) { + parent::__construct($request, $data); + + $this->xml = $this->parseXml($data); + } + + /** + * Turn the raw XML response string into a SimpleXMLElement + * + * @param string $data + * @return \SimpleXMLElement + */ + public function parseXml($data) { + $data = str_replace(' ', ' ', $data); + $data = str_replace("\n", '', $data); + $data = str_replace("\r", '', $data); + + return new \SimpleXMLElement($data); + } + } diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index 15e57a6..1865199 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -8,167 +8,156 @@ /** * Realex Auth Request */ -class SavedAuthRequest extends RemoteAbstractRequest -{ - - public function getCavv() - { - return $this->getParameter('cavv'); - } - - public function setCavv($value) - { - return $this->setParameter('cavv', $value); - } - - public function getEci() - { - return $this->getParameter('eci'); - } - - public function setEci($value) - { - return $this->setParameter('eci', $value); - } - - public function getXid() - { - return $this->getParameter('xid'); - } - - public function setXid($value) - { - return $this->setParameter('xid', $value); - } - - public function getCustomerRef() - { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) - { - $this->setParameter('customerRef', $customerRef); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() - { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.{$this->getCustomerRef()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'receipt-in'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->setAttribute('currency', $this->getCurrency()); - $amountEl->appendChild($domTree->createTextNode($amount)); - $root->appendChild($amountEl); - - $paymentDataEl = $domTree->createElement('paymentdata'); - $cvnEl = $domTree->createElement('cvn'); - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getCvv())); - - $cvnEl->appendChild($numberEl); - $paymentDataEl->appendChild($cvnEl); - $root->appendChild($paymentDataEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $root->appendChild($payerRefEl); - - $paymentMethodEl = $domTree->createElement('paymentmethod'); - $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); - $root->appendChild($paymentMethodEl); - - $settleEl = $domTree->createElement('autosettle'); - $settleEl->setAttribute('flag', 1); - $root->appendChild($settleEl); - - // 3D Secure section - $mpiEl = $domTree->createElement('mpi'); - $cavvEl = $domTree->createElement('cavv'); - $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); - $xidEl = $domTree->createElement('xid'); - $xidEl->appendChild($domTree->createTextNode($this->getXid())); - $eciEl = $domTree->createElement('eci'); - $eciEl->appendChild($domTree->createTextNode($this->getEci())); - $mpiEl->appendChild($cavvEl); - $mpiEl->appendChild($xidEl); - $mpiEl->appendChild($eciEl); - $root->appendChild($mpiEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $tssEl = $domTree->createElement('tssinfo'); - $addressEl = $domTree->createElement('address'); - $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - $tssEl->appendChild($addressEl); - $root->appendChild($tssEl); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new AuthResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('SecureDataVaultEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } +class SavedAuthRequest extends RemoteAbstractRequest { + + public function getCavv() { + return $this->getParameter('cavv'); + } + + public function setCavv($value) { + return $this->setParameter('cavv', $value); + } + + public function getEci() { + return $this->getParameter('eci'); + } + + public function setEci($value) { + return $this->setParameter('eci', $value); + } + + public function getXid() { + return $this->getParameter('xid'); + } + + public function setXid($value) { + return $this->setParameter('xid', $value); + } + + public function getCustomerRef() { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) { + $this->setParameter('customerRef', $customerRef); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.{$this->getCustomerRef()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'receipt-in'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->setAttribute('currency', $this->getCurrency()); + $amountEl->appendChild($domTree->createTextNode($amount)); + $root->appendChild($amountEl); + + $paymentDataEl = $domTree->createElement('paymentdata'); + $cvnEl = $domTree->createElement('cvn'); + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getCvv())); + + $cvnEl->appendChild($numberEl); + $paymentDataEl->appendChild($cvnEl); + $root->appendChild($paymentDataEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $root->appendChild($payerRefEl); + + $paymentMethodEl = $domTree->createElement('paymentmethod'); + $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); + $root->appendChild($paymentMethodEl); + + $settleEl = $domTree->createElement('autosettle'); + $settleEl->setAttribute('flag', 1); + $root->appendChild($settleEl); + + // 3D Secure section + $mpiEl = $domTree->createElement('mpi'); + $cavvEl = $domTree->createElement('cavv'); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $xidEl = $domTree->createElement('xid'); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $eciEl = $domTree->createElement('eci'); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); + $mpiEl->appendChild($cavvEl); + $mpiEl->appendChild($xidEl); + $mpiEl->appendChild($eciEl); + $root->appendChild($mpiEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $tssEl = $domTree->createElement('tssinfo'); + $addressEl = $domTree->createElement('address'); + $addressEl->setAttribute('type', 'billing'); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + $tssEl->appendChild($addressEl); + $root->appendChild($tssEl); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new AuthResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } + } diff --git a/src/Omnipay/Realex/Message/UpdateCardRequest.php b/src/Omnipay/Realex/Message/UpdateCardRequest.php index 4a256f5..86db8bf 100644 --- a/src/Omnipay/Realex/Message/UpdateCardRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCardRequest.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,109 +7,104 @@ namespace Omnipay\Realex\Message; +class UpdateCardRequest extends RemoteAbstractRequest { + + public function getCustomerRef() { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-update-card'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $cardEl = $domTree->createElement('card'); + + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); + + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($numberEl); + + $expDateEl = $domTree->createElement('expdate'); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expDateEl); + + $chNameEl = $domTree->createElement('chname'); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($chNameEl); + + $typeEl = $domTree->createElement('type'); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($typeEl); + + $issueNoEl = $domTree->createElement('issueno'); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueNoEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new UpdateCardResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } -class UpdateCardRequest extends RemoteAbstractRequest -{ - public function getCustomerRef() - { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) - { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() - { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-update-card'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $cardEl = $domTree->createElement('card'); - - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); - - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($numberEl); - - $expDateEl = $domTree->createElement('expdate'); - $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expDateEl); - - $chNameEl = $domTree->createElement('chname'); - $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($chNameEl); - - $typeEl = $domTree->createElement('type'); - $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($typeEl); - - $issueNoEl = $domTree->createElement('issueno'); - $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueNoEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new UpdateCardResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('SecureDataVaultEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } } diff --git a/src/Omnipay/Realex/Message/UpdateCardResponse.php b/src/Omnipay/Realex/Message/UpdateCardResponse.php index 5f2f9c9..6343df9 100644 --- a/src/Omnipay/Realex/Message/UpdateCardResponse.php +++ b/src/Omnipay/Realex/Message/UpdateCardResponse.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,39 +7,33 @@ namespace Omnipay\Realex\Message; +class UpdateCardResponse extends RemoteAbstractResponse { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } -class UpdateCardResponse extends RemoteAbstractResponse -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function getMessage() - { - return (string) $this->xml->message; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } } diff --git a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php index b2f9be5..740521d 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,136 +7,132 @@ namespace Omnipay\Realex\Message; -class UpdateCustomerRequest extends RemoteAbstractRequest -{ - public function getCustomerRef() - { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) - { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() - { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'payer-edit'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $payerEl = $domTree->createElement('payer'); - $payerEl->setAttribute('type', 'Business'); - $payerEl->setAttribute('ref', $payerRef); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $titleEl = $domTree->createElement('title'); - $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); - $payerEl->appendChild($titleEl); - - $firstnameEl = $domTree->createElement('firstname'); - $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); - $payerEl->appendChild($firstnameEl); - - $lastnameEl = $domTree->createElement('surname'); - $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); - $payerEl->appendChild($lastnameEl); - - $companyEl = $domTree->createElement('company'); - $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); - $payerEl->appendChild($companyEl); - - $addressEl = $domTree->createElement('address'); - - $line1El = $domTree->createElement('line1'); - $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); - $addressEl->appendChild($line1El); - - $line2El = $domTree->createElement('line2'); - $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); - $addressEl->appendChild($line2El); - - $cityEl = $domTree->createElement('city'); - $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); - $addressEl->appendChild($cityEl); - - $countyEl = $domTree->createElement('county'); - $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); - $addressEl->appendChild($countyEl); - - $postcodeEl = $domTree->createElement('postcode'); - $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); - $addressEl->appendChild($postcodeEl); - - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - - $payerEl->appendChild($addressEl); - - $phonenumbersEl = $domTree->createElement('phonenumbers'); - $homeEl = $domTree->createElement('home'); - $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); - $phonenumbersEl->appendChild($homeEl); - $payerEl->appendChild($phonenumbersEl); - - $emailEl = $domTree->createElement('email'); - $emailEl->appendChild($domTree->createTextNode($card->getEmail())); - $payerEl->appendChild($emailEl); - - $root->appendChild($payerEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new UpdateCustomerResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('SecureDataVaultEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } +class UpdateCustomerRequest extends RemoteAbstractRequest { + + public function getCustomerRef() { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'payer-edit'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $payerEl = $domTree->createElement('payer'); + $payerEl->setAttribute('type', 'Business'); + $payerEl->setAttribute('ref', $payerRef); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $titleEl = $domTree->createElement('title'); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); + $payerEl->appendChild($titleEl); + + $firstnameEl = $domTree->createElement('firstname'); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); + $payerEl->appendChild($firstnameEl); + + $lastnameEl = $domTree->createElement('surname'); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); + $payerEl->appendChild($lastnameEl); + + $companyEl = $domTree->createElement('company'); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); + $payerEl->appendChild($companyEl); + + $addressEl = $domTree->createElement('address'); + + $line1El = $domTree->createElement('line1'); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); + $addressEl->appendChild($line1El); + + $line2El = $domTree->createElement('line2'); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); + $addressEl->appendChild($line2El); + + $cityEl = $domTree->createElement('city'); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); + $addressEl->appendChild($cityEl); + + $countyEl = $domTree->createElement('county'); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); + $addressEl->appendChild($countyEl); + + $postcodeEl = $domTree->createElement('postcode'); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); + $addressEl->appendChild($postcodeEl); + + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + + $payerEl->appendChild($addressEl); + + $phonenumbersEl = $domTree->createElement('phonenumbers'); + $homeEl = $domTree->createElement('home'); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); + $phonenumbersEl->appendChild($homeEl); + $payerEl->appendChild($phonenumbersEl); + + $emailEl = $domTree->createElement('email'); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); + $payerEl->appendChild($emailEl); + + $root->appendChild($payerEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new UpdateCustomerResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } + } diff --git a/src/Omnipay/Realex/Message/UpdateCustomerResponse.php b/src/Omnipay/Realex/Message/UpdateCustomerResponse.php index 8a7cff6..71594b4 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerResponse.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerResponse.php @@ -1,4 +1,5 @@ * Date: 04/08/15 @@ -6,38 +7,33 @@ namespace Omnipay\Realex\Message; -class UpdateCustomerResponse extends RemoteAbstractResponse -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function getMessage() - { - return (string) $this->xml->message; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } +class UpdateCustomerResponse extends RemoteAbstractResponse { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } + } diff --git a/src/Omnipay/Realex/Message/VerifySigRequest.php b/src/Omnipay/Realex/Message/VerifySigRequest.php index 2f23e91..5ee1d7b 100644 --- a/src/Omnipay/Realex/Message/VerifySigRequest.php +++ b/src/Omnipay/Realex/Message/VerifySigRequest.php @@ -9,169 +9,164 @@ /** * Realex Complete Auth Request */ -class VerifySigRequest extends RemoteAbstractRequest -{ - /** - * Decode our previously-encoded Merchant Data - * - * @param string $data - * @return array - */ - protected function decodeMerchantData($data) - { - $json = base64_decode($data); - $cardData = (array)json_decode($json); - - return $cardData; - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() - { - /** - * Data will be sent from the 3D Secure provider in two fields: MD and ParRes. - * MD contains our original data (encoded by us) and PaRes will be sent to the gateway. - */ - $returnedData = $this->decodeMerchantData($this->httpRequest->request->get('MD', '')); - - $this->setTransactionId($returnedData['transactionId']); - $this->setAmount($returnedData['amount']); - $this->setCurrency($returnedData['currency']); - $this->setCard(new CreditCard($returnedData)); - - $paRes = $this->httpRequest->request->get('PaRes', ''); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', '3ds-verifysig'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $root->appendChild($cardEl); - - $paResEl = $domTree->createElement('pares'); - $paResEl->appendChild($domTree->createTextNode($paRes)); - $root->appendChild($paResEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new VerifySigResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('authEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('authEndpoint', $value); - } - - /** - * @param mixed $parameters - * - * @return AuthResponse|VerifySigResponse - */ - public function sendData($parameters) - { - /** - * @var VerifySigResponse $response - */ - $response = parent::sendData($parameters); - - if ($response->isSuccessful()) { - // a few additional parameters that need to be passed for 3D-Secure transactions - $parameters = $this->getParameters(); - $parameters['cavv'] = $response->getParam('cavv'); - $parameters['eci'] = $response->getParam('eci'); - $parameters['xid'] = $response->getParam('xid'); - - /** - * Now finally, do our authorisation - * - * @var AuthRequest $request - * @var AuthResponse $response - */ - $request = new AuthRequest($this->httpClient, $this->httpRequest); - $request->initialize($parameters); - - $response = $request->send(); - - } - - return $response; - } +class VerifySigRequest extends RemoteAbstractRequest { + + /** + * Decode our previously-encoded Merchant Data + * + * @param string $data + * @return array + */ + protected function decodeMerchantData($data) { + $json = base64_decode($data); + $cardData = (array) json_decode($json); + + return $cardData; + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() { + /** + * Data will be sent from the 3D Secure provider in two fields: MD and ParRes. + * MD contains our original data (encoded by us) and PaRes will be sent to the gateway. + */ + $returnedData = $this->decodeMerchantData($this->httpRequest->request->get('MD', '')); + + $this->setTransactionId($returnedData['transactionId']); + $this->setAmount($returnedData['amount']); + $this->setCurrency($returnedData['currency']); + $this->setCard(new CreditCard($returnedData)); + + $paRes = $this->httpRequest->request->get('PaRes', ''); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', '3ds-verifysig'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $root->appendChild($cardEl); + + $paResEl = $domTree->createElement('pares'); + $paResEl->appendChild($domTree->createTextNode($paRes)); + $root->appendChild($paResEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new VerifySigResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('authEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('authEndpoint', $value); + } + + /** + * @param mixed $parameters + * + * @return AuthResponse|VerifySigResponse + */ + public function sendData($parameters) { + /** + * @var VerifySigResponse $response + */ + $response = parent::sendData($parameters); + + if ($response->isSuccessful()) { + // a few additional parameters that need to be passed for 3D-Secure transactions + $parameters = $this->getParameters(); + $parameters['cavv'] = $response->getParam('cavv'); + $parameters['eci'] = $response->getParam('eci'); + $parameters['xid'] = $response->getParam('xid'); + + /** + * Now finally, do our authorisation + * + * @var AuthRequest $request + * @var AuthResponse $response + */ + $request = new AuthRequest($this->httpClient, $this->httpRequest); + $request->initialize($parameters); + + $response = $request->send(); + } + + return $response; + } + } diff --git a/src/Omnipay/Realex/Message/VerifySigResponse.php b/src/Omnipay/Realex/Message/VerifySigResponse.php index d6e54a3..febbb3a 100644 --- a/src/Omnipay/Realex/Message/VerifySigResponse.php +++ b/src/Omnipay/Realex/Message/VerifySigResponse.php @@ -10,83 +10,75 @@ /** * Realex Verify 3D Secure signature Response */ -class VerifySigResponse extends RemoteAbstractResponse implements RedirectResponseInterface -{ - public function isSuccessful() - { - /** - * The 3D secure result is only counted as successful if is: - * - legitimate - (result = 00) - * - card holder correctly entered their password, or the 3DS systems are unavailable at the moment - */ - return ($this->xml->result == '00' && $this->xml->threedsecure->status != 'N'); - } +class VerifySigResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - /** - * Find the value of a named XML element in the response - * - * @param string $key - * @return string - */ - public function getParam($key) - { - $matches = $this->xml->xpath('//' . $key); - if (!empty($matches)) { - $value = (string)$matches[0]; - } else { - $value = ''; - } + public function isSuccessful() { + /** + * The 3D secure result is only counted as successful if is: + * - legitimate - (result = 00) + * - card holder correctly entered their password, or the 3DS systems are unavailable at the moment + */ + return ($this->xml->result == '00' && $this->xml->threedsecure->status != 'N'); + } - return $value; - } + /** + * Find the value of a named XML element in the response + * + * @param string $key + * @return string + */ + public function getParam($key) { + $matches = $this->xml->xpath('//' . $key); + if (!empty($matches)) { + $value = (string) $matches[0]; + } else { + $value = ''; + } - public function getMessage() - { - /** - * For some reason, the default message from the gateway - * says "Authentication Successful", even if the customer - * was shown to have used an incorrect password. For sane - * front-end reporting, let's override this. - */ - if ($this->xml->threedsecure->status == 'N') { - $message = '3D Secure Authentication Unsuccessful'; - } else { - $message = (string)$this->xml->message; - } + return $value; + } - return $message; - } + public function getMessage() { + /** + * For some reason, the default message from the gateway + * says "Authentication Successful", even if the customer + * was shown to have used an incorrect password. For sane + * front-end reporting, let's override this. + */ + if ($this->xml->threedsecure->status == 'N') { + $message = '3D Secure Authentication Unsuccessful'; + } else { + $message = (string) $this->xml->message; + } - public function getTransactionId() - { - return ($this->xml->orderid) ? (string)$this->xml->orderid : null; - } + return $message; + } - public function getTransactionReference() - { - return ($this->xml->pasref) ? $this->xml->pasref : null; - } + public function getTransactionId() { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } - public function isRedirect() - { - return false; - } + public function getTransactionReference() { + return ($this->xml->pasref) ? $this->xml->pasref : null; + } - public function getRedirectMethod() - { - return 'GET'; - } + public function isRedirect() { + return false; + } - public function getRedirectData() - { - return null; - } + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } } diff --git a/src/Omnipay/Realex/Message/VoidRequest.php b/src/Omnipay/Realex/Message/VoidRequest.php index 24e0904..daec5fc 100644 --- a/src/Omnipay/Realex/Message/VoidRequest.php +++ b/src/Omnipay/Realex/Message/VoidRequest.php @@ -7,104 +7,98 @@ /** * Realex Void Request */ -class VoidRequest extends RemoteAbstractRequest -{ - public function getTransactionReference() - { - return $this->getParameter('pasRef'); - } - - public function setTransactionReference($value) - { - return $this->setParameter('pasRef', $value); - } - - public function getAuthCode() - { - return $this->getParameter('authCode'); - } - - public function setAuthCode($value) - { - return $this->setParameter('authCode', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() - { - $this->validate('transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - // No amount, currency or card number for rebate requests but still needs to be in hash - $amount = ''; - $currency = ''; - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'void'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // original order ID - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($orderIdEl); - - // pasref returned for original transaction - $pasRefEl = $domTree->createElement('pasref'); - $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); - $root->appendChild($pasRefEl); - - // authcode returned for original transaction - $authCodeEl = $domTree->createElement('authcode'); - $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); - $root->appendChild($authCodeEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) - { - return $this->response = new VoidResponse($this, $data); - } - - public function getEndpoint() - { - return $this->getParameter('SecureDataVaultEndpoint'); - } - public function setAuthEndpoint($value) - { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } +class VoidRequest extends RemoteAbstractRequest { + + public function getTransactionReference() { + return $this->getParameter('pasRef'); + } + + public function setTransactionReference($value) { + return $this->setParameter('pasRef', $value); + } + + public function getAuthCode() { + return $this->getParameter('authCode'); + } + + public function setAuthCode($value) { + return $this->setParameter('authCode', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() { + $this->validate('transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + // No amount, currency or card number for rebate requests but still needs to be in hash + $amount = ''; + $currency = ''; + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'void'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // original order ID + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($orderIdEl); + + // pasref returned for original transaction + $pasRefEl = $domTree->createElement('pasref'); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); + $root->appendChild($pasRefEl); + + // authcode returned for original transaction + $authCodeEl = $domTree->createElement('authcode'); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); + $root->appendChild($authCodeEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) { + return $this->response = new VoidResponse($this, $data); + } + + public function getEndpoint() { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } + } diff --git a/src/Omnipay/Realex/Message/VoidResponse.php b/src/Omnipay/Realex/Message/VoidResponse.php index 9b0ad5e..1b3bbb2 100644 --- a/src/Omnipay/Realex/Message/VoidResponse.php +++ b/src/Omnipay/Realex/Message/VoidResponse.php @@ -10,53 +10,45 @@ /** * Realex Void Response */ -class VoidResponse extends RemoteAbstractResponse implements RedirectResponseInterface -{ - public function isSuccessful() - { - return ($this->xml->result == '00'); - } - - public function getMessage() - { - return (string)$this->xml->message; - } - - public function getTransactionId() - { - return ($this->xml->orderid) ? (string)$this->xml->orderid : null; - } - - public function getTransactionReference() - { - return ($this->xml->pasref) ? (string)$this->xml->pasref : null; - } - - public function getAuthCode() - { - return ($this->xml->authcode) ? (string)$this->xml->authcode : null; - } - - public function isRedirect() - { - return false; - } - - public function getRedirectMethod() - { - return 'GET'; - } - - public function getRedirectData() - { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() - { - return ''; - } +class VoidResponse extends RemoteAbstractResponse implements RedirectResponseInterface { + + public function isSuccessful() { + return ($this->xml->result == '00'); + } + + public function getMessage() { + return (string) $this->xml->message; + } + + public function getTransactionId() { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() { + return false; + } + + public function getRedirectMethod() { + return 'GET'; + } + + public function getRedirectData() { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() { + return ''; + } + } diff --git a/src/Omnipay/Realex/RedirectGateway.php b/src/Omnipay/Realex/RedirectGateway.php index 17078cf..4fd2afc 100644 --- a/src/Omnipay/Realex/RedirectGateway.php +++ b/src/Omnipay/Realex/RedirectGateway.php @@ -7,91 +7,76 @@ /** * Realex Redirect Class */ -class RedirectGateway extends AbstractGateway -{ - public function getName() - { - return 'Realex Redirect'; - } - - public function getDefaultParameters() - { - return array( - 'merchantId' => '', - 'secret' => '', - 'account' => 'internet', - 'testMode' => false, - 'checkoutEndpoint' => 'https://hpp.realexpayments.com/pay', - ); - } - - public function getMerchantId() - { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) - { - return $this->setParameter('merchantId', $value); - } - - public function getSecret() - { - return $this->getParameter('secret'); - } - - public function setSecret($value) - { - return $this->setParameter('secret', $value); - } - - public function getAccount() - { - return $this->getParameter('account'); - } - - public function setAccount($value) - { - return $this->setParameter('account', $value); - } - - public function getCheckoutEndpoint() - { - return $this->getParameter('checkoutEndpoint'); - } - - public function setCheckoutEndpoint($value) - { - return $this->setParameter('checkoutEndpoint', $value); - } - - public function authorize(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectAuthorizeRequest', $parameters); - } - - public function completeAuthorize(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteAuthorizeRequest', $parameters); - } - - public function purchase(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectPurchaseRequest', $parameters); - } - - public function completePurchase(array $parameters = array()) - { - return $this->completeAuthorize($parameters); - } - - public function storeCard(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectStoreCardRequest', $parameters); - } - public function completeStoreCard(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteStoreCardRequest', $parameters); - } - +class RedirectGateway extends AbstractGateway { + + public function getName() { + return 'Realex Redirect'; + } + + public function getDefaultParameters() { + return array( + 'merchantId' => '', + 'secret' => '', + 'account' => 'internet', + 'testMode' => false, + 'checkoutEndpoint' => 'https://hpp.realexpayments.com/pay', + ); + } + + public function getMerchantId() { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) { + return $this->setParameter('merchantId', $value); + } + + public function getSecret() { + return $this->getParameter('secret'); + } + + public function setSecret($value) { + return $this->setParameter('secret', $value); + } + + public function getAccount() { + return $this->getParameter('account'); + } + + public function setAccount($value) { + return $this->setParameter('account', $value); + } + + public function getCheckoutEndpoint() { + return $this->getParameter('checkoutEndpoint'); + } + + public function setCheckoutEndpoint($value) { + return $this->setParameter('checkoutEndpoint', $value); + } + + public function authorize(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectAuthorizeRequest', $parameters); + } + + public function completeAuthorize(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteAuthorizeRequest', $parameters); + } + + public function purchase(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectPurchaseRequest', $parameters); + } + + public function completePurchase(array $parameters = array()) { + return $this->completeAuthorize($parameters); + } + + public function storeCard(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectStoreCardRequest', $parameters); + } + + public function completeStoreCard(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteStoreCardRequest', $parameters); + } + } diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index a5941b3..138520c 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -12,179 +12,152 @@ /** * Realex Remote Gateway */ -class RemoteGateway extends AbstractGateway -{ - public function getName() - { - return 'Realex Remote'; - } - - public function getDefaultParameters() - { - return array( - 'merchantId' => '', - 'account' => '', - 'secret' => '', - '3dSecure' => 0, - 'authEndpoint'=>'https://epage.payandshop.com/epage-remote.cgi', - 'secureDataVaultEndpoint'=>'https://epage.payandshop.com/epage-remote-plugins.cgi', - '3dSecureEndpoint'=>'https://epage.payandshop.com/epage-3dsecure.cgi' - ); - } - - public function getMerchantId() - { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) - { - return $this->setParameter('merchantId', $value); - } - - public function getAccount() - { - return $this->getParameter('account'); - } - - public function setAccount($value) - { - return $this->setParameter('account', $value); - } - - public function getSecret() - { - return $this->getParameter('secret'); - } - - public function setSecret($value) - { - return $this->setParameter('secret', $value); - } - - public function getRefundPassword() - { - return $this->getParameter('refundPassword'); - } - - /** - * Although Omnipay terminology deals with 'refunds', you need - * to actually supply the 'rebate' password that Realex gives you - * in order for this to work. - * - * @param string $value The 'rebate' password supplied by Realex - * - * @return $this - */ - public function setRefundPassword($value) - { - return $this->setParameter('refundPassword', $value); - } - - public function get3dSecure() - { - return $this->getParameter('3dSecure'); - } - - public function set3dSecure($value) - { - return $this->setParameter('3dSecure', $value); - } - - public function purchase(array $parameters = array()) - { - - if (array_key_exists('cardReference', $parameters)) { - return $this->createRequest('\Omnipay\Realex\Message\SavedAuthRequest', $parameters); - } elseif ($this->get3dSecure()) { - return $this->createRequest('\Omnipay\Realex\Message\EnrolmentRequest', $parameters); - } else { - return $this->createRequest('\Omnipay\Realex\Message\AuthRequest', $parameters); - } - } - - /** - * This will always be called as the result of returning from 3D Secure. - * Verify that the 3D Secure message we've received is legit - */ - public function completePurchase(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\VerifySigRequest', $parameters); - } - - public function refund(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\RefundRequest', $parameters); - } - - public function void(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\VoidRequest', $parameters); - } - - public function fetchTransaction(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\FetchTransactionRequest', $parameters); - } - - /** - * Create/update/delete card/customer details - */ - public function createCard(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\CreateCardRequest', $parameters); - } - - public function updateCard(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\UpdateCardRequest', $parameters); - } - - public function deleteCard(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\DeleteCardRequest', $parameters); - } - - public function createCustomer(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\CreateCustomerRequest', $parameters); - } - - public function updateCustomer(array $parameters = array()) - { - return $this->createRequest('\Omnipay\Realex\Message\UpdateCustomerRequest', $parameters); - } - - /** - * Setup service endpoint links for different realex service providers - */ - public function setAuthEndpoint($value) - { - return $this->setParameter('authEndpoint', $value); - } - - public function getAuthEndpoint() - { - return $this->getParameter('authEndpoint'); - } - - public function setSecureDataVaultEndpoint($value) - { - return $this->setParameter('secureDataVaultEndpoint', $value); - } - - public function getSecureDataVaultEndpoint() - { - return $this->getParameter('secureDataVaultEndpoint'); - } - - public function set3DSecureEndpoint($value) - { - return $this->setParameter('3dSecureEndpoint', $value); - } - - public function get3DSecureEndpoint() - { - return $this->getParameter('3dSecureEndpoint'); - } +class RemoteGateway extends AbstractGateway { + + public function getName() { + return 'Realex Remote'; + } + + public function getDefaultParameters() { + return array( + 'merchantId' => '', + 'account' => '', + 'secret' => '', + '3dSecure' => 0, + 'authEndpoint' => 'https://epage.payandshop.com/epage-remote.cgi', + 'secureDataVaultEndpoint' => 'https://epage.payandshop.com/epage-remote-plugins.cgi', + '3dSecureEndpoint' => 'https://epage.payandshop.com/epage-3dsecure.cgi' + ); + } + + public function getMerchantId() { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() { + return $this->getParameter('account'); + } + + public function setAccount($value) { + return $this->setParameter('account', $value); + } + + public function getSecret() { + return $this->getParameter('secret'); + } + + public function setSecret($value) { + return $this->setParameter('secret', $value); + } + + public function getRefundPassword() { + return $this->getParameter('refundPassword'); + } + + /** + * Although Omnipay terminology deals with 'refunds', you need + * to actually supply the 'rebate' password that Realex gives you + * in order for this to work. + * + * @param string $value The 'rebate' password supplied by Realex + * + * @return $this + */ + public function setRefundPassword($value) { + return $this->setParameter('refundPassword', $value); + } + + public function get3dSecure() { + return $this->getParameter('3dSecure'); + } + + public function set3dSecure($value) { + return $this->setParameter('3dSecure', $value); + } + + public function purchase(array $parameters = array()) { + + if (array_key_exists('cardReference', $parameters)) { + return $this->createRequest('\Omnipay\Realex\Message\SavedAuthRequest', $parameters); + } elseif ($this->get3dSecure()) { + return $this->createRequest('\Omnipay\Realex\Message\EnrolmentRequest', $parameters); + } else { + return $this->createRequest('\Omnipay\Realex\Message\AuthRequest', $parameters); + } + } + + /** + * This will always be called as the result of returning from 3D Secure. + * Verify that the 3D Secure message we've received is legit + */ + public function completePurchase(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\VerifySigRequest', $parameters); + } + + public function refund(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\RefundRequest', $parameters); + } + + public function void(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\VoidRequest', $parameters); + } + + public function fetchTransaction(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\FetchTransactionRequest', $parameters); + } + + /** + * Create/update/delete card/customer details + */ + public function createCard(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\CreateCardRequest', $parameters); + } + + public function updateCard(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\UpdateCardRequest', $parameters); + } + + public function deleteCard(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\DeleteCardRequest', $parameters); + } + + public function createCustomer(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\CreateCustomerRequest', $parameters); + } + + public function updateCustomer(array $parameters = array()) { + return $this->createRequest('\Omnipay\Realex\Message\UpdateCustomerRequest', $parameters); + } + + /** + * Setup service endpoint links for different realex service providers + */ + public function setAuthEndpoint($value) { + return $this->setParameter('authEndpoint', $value); + } + + public function getAuthEndpoint() { + return $this->getParameter('authEndpoint'); + } + + public function setSecureDataVaultEndpoint($value) { + return $this->setParameter('secureDataVaultEndpoint', $value); + } + + public function getSecureDataVaultEndpoint() { + return $this->getParameter('secureDataVaultEndpoint'); + } + + public function set3DSecureEndpoint($value) { + return $this->setParameter('3dSecureEndpoint', $value); + } + + public function get3DSecureEndpoint() { + return $this->getParameter('3dSecureEndpoint'); + } + } From ddef3d6a3cd4f4946c4b37dacb2ddbb74e95ae24 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 10:29:28 +0100 Subject: [PATCH 14/29] cs fixer update --- .gitignore | 3 +- src/Omnipay/Realex/Message/AuthRequest.php | 335 ++++++++-------- src/Omnipay/Realex/Message/AuthResponse.php | 126 ++++--- .../Realex/Message/CreateCardRequest.php | 205 +++++----- .../Realex/Message/CreateCardResponse.php | 72 ++-- .../Realex/Message/CreateCustomerRequest.php | 255 +++++++------ .../Realex/Message/CreateCustomerResponse.php | 63 ++-- .../Realex/Message/DeleteCardRequest.php | 141 +++---- .../Realex/Message/DeleteCardResponse.php | 63 ++-- .../Realex/Message/EnrolmentRequest.php | 252 +++++++------ .../Realex/Message/EnrolmentResponse.php | 156 ++++---- .../Message/FetchTransactionRequest.php | 140 +++---- .../Message/FetchTransactionResponse.php | 90 +++-- .../Message/Redirect/AbstractRequest.php | 357 ++++++++++-------- .../Redirect/RedirectAuthorizeRequest.php | 26 +- .../Redirect/RedirectAuthorizeResponse.php | 57 +-- .../RedirectCompleteAuthorizeRequest.php | 53 +-- .../RedirectCompleteStoreCardRequest.php | 64 ++-- .../Redirect/RedirectDataVaultRequest.php | 106 +++--- .../Redirect/RedirectDataVaultResponse.php | 59 +-- .../Redirect/RedirectPurchaseRequest.php | 12 +- .../Redirect/RedirectPurchaseResponse.php | 12 +- .../Redirect/RedirectStoreCardRequest.php | 170 +++++---- .../Redirect/RedirectStoreCardResponse.php | 14 +- .../Message/Redirect/dataVaultResponse.php | 100 ++--- .../Realex/Message/Redirect/response.php | 41 +- src/Omnipay/Realex/Message/RefundRequest.php | 259 +++++++------ src/Omnipay/Realex/Message/RefundResponse.php | 90 +++-- .../Realex/Message/RemoteAbstractRequest.php | 152 ++++---- .../Realex/Message/RemoteAbstractResponse.php | 49 +-- .../Realex/Message/SavedAuthRequest.php | 315 ++++++++-------- .../Realex/Message/UpdateCardRequest.php | 205 +++++----- .../Realex/Message/UpdateCardResponse.php | 63 ++-- .../Realex/Message/UpdateCustomerRequest.php | 255 +++++++------ .../Realex/Message/UpdateCustomerResponse.php | 63 ++-- .../Realex/Message/VerifySigRequest.php | 326 ++++++++-------- .../Realex/Message/VerifySigResponse.php | 130 ++++--- src/Omnipay/Realex/Message/VoidRequest.php | 195 +++++----- src/Omnipay/Realex/Message/VoidResponse.php | 90 +++-- src/Omnipay/Realex/RedirectGateway.php | 159 ++++---- src/Omnipay/Realex/RemoteGateway.php | 322 ++++++++-------- 41 files changed, 2959 insertions(+), 2686 deletions(-) diff --git a/.gitignore b/.gitignore index 0d44bac..134f9dd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ composer.lock composer.phar phpunit.xml .idea -/nbproject/private/ \ No newline at end of file +/nbproject/private/ +.php_cs.cache \ No newline at end of file diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index 8391142..5213693 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -8,167 +8,176 @@ /** * Realex Auth Request */ -class AuthRequest extends RemoteAbstractRequest { - - public function getCavv() { - return $this->getParameter('cavv'); - } - - public function setCavv($value) { - return $this->setParameter('cavv', $value); - } - - public function getEci() { - return $this->getParameter('eci'); - } - - public function setEci($value) { - return $this->setParameter('eci', $value); - } - - public function getXid() { - return $this->getParameter('xid'); - } - - public function setXid($value) { - return $this->setParameter('xid', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'auth'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $cvnEl = $domTree->createElement('cvn'); - - $cvnNumberEl = $domTree->createElement('number'); - $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); - $cvnEl->appendChild($cvnNumberEl); - - $presIndEl = $domTree->createElement('presind', 1); - $cvnEl->appendChild($presIndEl); - - $cardEl->appendChild($cvnEl); - - $issueEl = $domTree->createElement('issueno'); - $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueEl); - - $root->appendChild($cardEl); - - $settleEl = $domTree->createElement('autosettle'); - $settleEl->setAttribute('flag', 1); - $root->appendChild($settleEl); - - // 3D Secure section - $mpiEl = $domTree->createElement('mpi'); - $cavvEl = $domTree->createElement('cavv'); - $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); - $xidEl = $domTree->createElement('xid'); - $xidEl->appendChild($domTree->createTextNode($this->getXid())); - $eciEl = $domTree->createElement('eci'); - $eciEl->appendChild($domTree->createTextNode($this->getEci())); - $mpiEl->appendChild($cavvEl); - $mpiEl->appendChild($xidEl); - $mpiEl->appendChild($eciEl); - $root->appendChild($mpiEl); - - $sha1El = $domTree->createElement('sha1hash', $sha1hash); - $root->appendChild($sha1El); - - $tssEl = $domTree->createElement('tssinfo'); - $addressEl = $domTree->createElement('address'); - $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - $tssEl->appendChild($addressEl); - $root->appendChild($tssEl); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new AuthResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } - +class AuthRequest extends RemoteAbstractRequest +{ + public function getCavv() + { + return $this->getParameter('cavv'); + } + + public function setCavv($value) + { + return $this->setParameter('cavv', $value); + } + + public function getEci() + { + return $this->getParameter('eci'); + } + + public function setEci($value) + { + return $this->setParameter('eci', $value); + } + + public function getXid() + { + return $this->getParameter('xid'); + } + + public function setXid($value) + { + return $this->setParameter('xid', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'auth'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $cvnEl = $domTree->createElement('cvn'); + + $cvnNumberEl = $domTree->createElement('number'); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); + $cvnEl->appendChild($cvnNumberEl); + + $presIndEl = $domTree->createElement('presind', 1); + $cvnEl->appendChild($presIndEl); + + $cardEl->appendChild($cvnEl); + + $issueEl = $domTree->createElement('issueno'); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueEl); + + $root->appendChild($cardEl); + + $settleEl = $domTree->createElement('autosettle'); + $settleEl->setAttribute('flag', 1); + $root->appendChild($settleEl); + + // 3D Secure section + $mpiEl = $domTree->createElement('mpi'); + $cavvEl = $domTree->createElement('cavv'); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $xidEl = $domTree->createElement('xid'); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $eciEl = $domTree->createElement('eci'); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); + $mpiEl->appendChild($cavvEl); + $mpiEl->appendChild($xidEl); + $mpiEl->appendChild($eciEl); + $root->appendChild($mpiEl); + + $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $root->appendChild($sha1El); + + $tssEl = $domTree->createElement('tssinfo'); + $addressEl = $domTree->createElement('address'); + $addressEl->setAttribute('type', 'billing'); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + $tssEl->appendChild($addressEl); + $root->appendChild($tssEl); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new AuthResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/AuthResponse.php b/src/Omnipay/Realex/Message/AuthResponse.php index d0d735e..77b97fa 100644 --- a/src/Omnipay/Realex/Message/AuthResponse.php +++ b/src/Omnipay/Realex/Message/AuthResponse.php @@ -10,61 +10,73 @@ /** * Realex Auth Response */ -class AuthResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function isDecline() { - return (substr($this->xml->result, 0, 1) == '1'); - } - - public function isBankSystemError() { - return (substr($this->xml->result, 0, 1) == '2'); - } - - public function isRealexSystemError() { - return (substr($this->xml->result, 0, 1) == '3'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } - - public function getTransactionReference() { - return ($this->xml->pasref) ? (string) $this->xml->pasref : null; - } - - public function getAuthCode() { - return ($this->xml->authcode) ? (string) $this->xml->authcode : null; - } - - public function getBatchId() { - return ($this->xml->batchid) ? (string) $this->xml->batchid : null; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class AuthResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function isDecline() + { + return (substr($this->xml->result, 0, 1) == '1'); + } + + public function isBankSystemError() + { + return (substr($this->xml->result, 0, 1) == '2'); + } + + public function isRealexSystemError() + { + return (substr($this->xml->result, 0, 1) == '3'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() + { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() + { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function getBatchId() + { + return ($this->xml->batchid) ? (string) $this->xml->batchid : null; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/CreateCardRequest.php b/src/Omnipay/Realex/Message/CreateCardRequest.php index 98f1b82..75709ac 100644 --- a/src/Omnipay/Realex/Message/CreateCardRequest.php +++ b/src/Omnipay/Realex/Message/CreateCardRequest.php @@ -7,104 +7,109 @@ namespace Omnipay\Realex\Message; -class CreateCardRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-new'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $cardEl = $domTree->createElement('card'); - - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); - - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($numberEl); - - $expDateEl = $domTree->createElement('expdate'); - $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expDateEl); - - $chNameEl = $domTree->createElement('chname'); - $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($chNameEl); - - $typeEl = $domTree->createElement('type'); - $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($typeEl); - - $issueNoEl = $domTree->createElement('issueno'); - $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueNoEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new CreateCardResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } - +class CreateCardRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-new'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $cardEl = $domTree->createElement('card'); + + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); + + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($numberEl); + + $expDateEl = $domTree->createElement('expdate'); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expDateEl); + + $chNameEl = $domTree->createElement('chname'); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($chNameEl); + + $typeEl = $domTree->createElement('type'); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($typeEl); + + $issueNoEl = $domTree->createElement('issueno'); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueNoEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new CreateCardResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/CreateCardResponse.php b/src/Omnipay/Realex/Message/CreateCardResponse.php index cdba215..9c646c0 100644 --- a/src/Omnipay/Realex/Message/CreateCardResponse.php +++ b/src/Omnipay/Realex/Message/CreateCardResponse.php @@ -7,37 +7,43 @@ namespace Omnipay\Realex\Message; -class CreateCardResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function customerDoesntExist() { - return ($this->xml->result == '520'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class CreateCardResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function customerDoesntExist() + { + return ($this->xml->result == '520'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/CreateCustomerRequest.php b/src/Omnipay/Realex/Message/CreateCustomerRequest.php index 427c9d3..84522cd 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/CreateCustomerRequest.php @@ -7,132 +7,137 @@ namespace Omnipay\Realex\Message; -class CreateCustomerRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); +class CreateCustomerRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'payer-new'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $payerEl = $domTree->createElement('payer'); + $payerEl->setAttribute('type', 'Business'); + $payerEl->setAttribute('ref', $payerRef); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $titleEl = $domTree->createElement('title'); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); + $payerEl->appendChild($titleEl); + + $firstnameEl = $domTree->createElement('firstname'); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); + $payerEl->appendChild($firstnameEl); + + $lastnameEl = $domTree->createElement('surname'); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); + $payerEl->appendChild($lastnameEl); + + $companyEl = $domTree->createElement('company'); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); + $payerEl->appendChild($companyEl); + + $addressEl = $domTree->createElement('address'); + + $line1El = $domTree->createElement('line1'); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); + $addressEl->appendChild($line1El); + + $line2El = $domTree->createElement('line2'); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); + $addressEl->appendChild($line2El); + + $cityEl = $domTree->createElement('city'); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); + $addressEl->appendChild($cityEl); + + $countyEl = $domTree->createElement('county'); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); + $addressEl->appendChild($countyEl); + + $postcodeEl = $domTree->createElement('postcode'); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); + $addressEl->appendChild($postcodeEl); + + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + + $payerEl->appendChild($addressEl); + + $phonenumbersEl = $domTree->createElement('phonenumbers'); + $homeEl = $domTree->createElement('home'); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); + $phonenumbersEl->appendChild($homeEl); + $payerEl->appendChild($phonenumbersEl); + + $emailEl = $domTree->createElement('email'); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); + $payerEl->appendChild($emailEl); + + $root->appendChild($payerEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); + protected function createResponse($data) + { + return $this->response = new CreateCustomerResponse($this, $data); + } - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'payer-new'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $payerEl = $domTree->createElement('payer'); - $payerEl->setAttribute('type', 'Business'); - $payerEl->setAttribute('ref', $payerRef); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $titleEl = $domTree->createElement('title'); - $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); - $payerEl->appendChild($titleEl); - - $firstnameEl = $domTree->createElement('firstname'); - $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); - $payerEl->appendChild($firstnameEl); - - $lastnameEl = $domTree->createElement('surname'); - $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); - $payerEl->appendChild($lastnameEl); - - $companyEl = $domTree->createElement('company'); - $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); - $payerEl->appendChild($companyEl); - - $addressEl = $domTree->createElement('address'); - - $line1El = $domTree->createElement('line1'); - $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); - $addressEl->appendChild($line1El); - - $line2El = $domTree->createElement('line2'); - $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); - $addressEl->appendChild($line2El); - - $cityEl = $domTree->createElement('city'); - $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); - $addressEl->appendChild($cityEl); - - $countyEl = $domTree->createElement('county'); - $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); - $addressEl->appendChild($countyEl); - - $postcodeEl = $domTree->createElement('postcode'); - $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); - $addressEl->appendChild($postcodeEl); - - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - - $payerEl->appendChild($addressEl); - - $phonenumbersEl = $domTree->createElement('phonenumbers'); - $homeEl = $domTree->createElement('home'); - $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); - $phonenumbersEl->appendChild($homeEl); - $payerEl->appendChild($phonenumbersEl); - - $emailEl = $domTree->createElement('email'); - $emailEl->appendChild($domTree->createTextNode($card->getEmail())); - $payerEl->appendChild($emailEl); - - $root->appendChild($payerEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new CreateCustomerResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/CreateCustomerResponse.php b/src/Omnipay/Realex/Message/CreateCustomerResponse.php index 7ae2a03..420f0f7 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerResponse.php +++ b/src/Omnipay/Realex/Message/CreateCustomerResponse.php @@ -7,33 +7,38 @@ namespace Omnipay\Realex\Message; -class CreateCustomerResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class CreateCustomerResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/DeleteCardRequest.php b/src/Omnipay/Realex/Message/DeleteCardRequest.php index 3ba7b64..ee3b0be 100644 --- a/src/Omnipay/Realex/Message/DeleteCardRequest.php +++ b/src/Omnipay/Realex/Message/DeleteCardRequest.php @@ -7,72 +7,77 @@ namespace Omnipay\Realex\Message; -class DeleteCardRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - $tmp = "$timestamp.$merchantId.$payerRef.{$this->getCardReference()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-cancel-card'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - $cardEl = $domTree->createElement('card'); - - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new DeleteCardResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } - +class DeleteCardRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + $tmp = "$timestamp.$merchantId.$payerRef.{$this->getCardReference()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-cancel-card'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + $cardEl = $domTree->createElement('card'); + + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new DeleteCardResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/DeleteCardResponse.php b/src/Omnipay/Realex/Message/DeleteCardResponse.php index 705d5cd..a2241e5 100644 --- a/src/Omnipay/Realex/Message/DeleteCardResponse.php +++ b/src/Omnipay/Realex/Message/DeleteCardResponse.php @@ -7,33 +7,38 @@ namespace Omnipay\Realex\Message; -class DeleteCardResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class DeleteCardResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/EnrolmentRequest.php b/src/Omnipay/Realex/Message/EnrolmentRequest.php index 01445bb..52ecbc9 100644 --- a/src/Omnipay/Realex/Message/EnrolmentRequest.php +++ b/src/Omnipay/Realex/Message/EnrolmentRequest.php @@ -7,125 +7,128 @@ /** * Realex 3D Secure enrolment request */ -class EnrolmentRequest extends RemoteAbstractRequest { - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', '3ds-verifyenrolled'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $cvnEl = $domTree->createElement('cvn'); - - $cvnNumberEl = $domTree->createElement('number'); - $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); - $cvnEl->appendChild($cvnNumberEl); - - $presIndEl = $domTree->createElement('presind', 1); - $cvnEl->appendChild($presIndEl); - - $cardEl->appendChild($cvnEl); - - $issueEl = $domTree->createElement('issueno'); - $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - /** - * We need to inspect this response to see if the customer is actually - * enrolled in the 3D Secure program. If they're not, we can go ahead - * and do a normal auth instead. - */ - $response = $this->response = new EnrolmentResponse($this, $data); +class EnrolmentRequest extends RemoteAbstractRequest +{ + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', '3ds-verifyenrolled'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $cvnEl = $domTree->createElement('cvn'); + + $cvnNumberEl = $domTree->createElement('number'); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); + $cvnEl->appendChild($cvnNumberEl); + + $presIndEl = $domTree->createElement('presind', 1); + $cvnEl->appendChild($presIndEl); + + $cardEl->appendChild($cvnEl); + + $issueEl = $domTree->createElement('issueno'); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + /** + * We need to inspect this response to see if the customer is actually + * enrolled in the 3D Secure program. If they're not, we can go ahead + * and do a normal auth instead. + */ + $response = $this->response = new EnrolmentResponse($this, $data); + + if (!$response->isEnrolled()) { + $request = new AuthRequest($this->httpClient, $this->httpRequest); + $request->initialize($this->getParameters()); - if (!$response->isEnrolled()) { - $request = new AuthRequest($this->httpClient, $this->httpRequest); - $request->initialize($this->getParameters()); + $response = $request->send(); + } - $response = $request->send(); - } - - return $response; - } + return $response; + } // public function getEndpoint() // { @@ -136,12 +139,13 @@ protected function createResponse($data) { // return $this->setParameter('3dSecureEndpoint', $value); // } - public function getEndpoint() { - return $this->getParameter('authEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('authEndpoint', $value); - } + public function getEndpoint() + { + return $this->getParameter('authEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('authEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/EnrolmentResponse.php b/src/Omnipay/Realex/Message/EnrolmentResponse.php index 3f2670b..8fd7d8a 100644 --- a/src/Omnipay/Realex/Message/EnrolmentResponse.php +++ b/src/Omnipay/Realex/Message/EnrolmentResponse.php @@ -14,78 +14,86 @@ * * @property EnrolmentRequest $request */ -class EnrolmentResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return false; - } - - public function isEnrolled() { - return $this->xml->enrolled == 'Y'; - } - - public function getMessage() { - $message = (string) $this->xml->message; - - return $message; - } - - public function getTransactionReference() { - $transactionReference = !empty($this->xml->pasref) ? $this->xml->pasref : null; - - return $transactionReference; - } - - public function isRedirect() { - if ($this->xml->result == '00' && $this->xml->enrolled == 'Y') { - return true; - } else { - return false; - } - } - - public function getRedirectUrl() { - return (string) $this->xml->url; - } - - public function getRedirectMethod() { - return 'POST'; - } - - /** - * Any encrypted data that we wish to have returned to us. - * Basically, this is all the card data that we will have to - * re-submit to to Realex in order to complete the authorisation. - */ - protected function getMerchantData() { - /** - * @var CreditCard $card - */ - $card = $this->request->getCard(); - $data = array( - 'transactionId' => $this->request->getTransactionId(), - 'currency' => $this->request->getCurrency(), - 'amount' => $this->request->getAmount(), - 'number' => $card->getNumber(), - 'expiryMonth' => $card->getExpiryMonth(), - 'expiryYear' => $card->getExpiryYear(), - 'billingName' => $card->getBillingName(), - 'cvv' => $card->getCvv(), - 'issueNumber' => $card->getIssueNumber(), - 'billingCountry' => $card->getBillingCountry() - ); - $serialised = json_encode($data); - $encoded = base64_encode($serialised); - - return $encoded; - } - - public function getRedirectData() { - return array( - 'PaReq' => (string) $this->xml->pareq, - 'TermUrl' => $this->request->getReturnUrl(), - 'MD' => $this->getMerchantData() - ); - } - +class EnrolmentResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return false; + } + + public function isEnrolled() + { + return $this->xml->enrolled == 'Y'; + } + + public function getMessage() + { + $message = (string) $this->xml->message; + + return $message; + } + + public function getTransactionReference() + { + $transactionReference = !empty($this->xml->pasref) ? $this->xml->pasref : null; + + return $transactionReference; + } + + public function isRedirect() + { + if ($this->xml->result == '00' && $this->xml->enrolled == 'Y') { + return true; + } else { + return false; + } + } + + public function getRedirectUrl() + { + return (string) $this->xml->url; + } + + public function getRedirectMethod() + { + return 'POST'; + } + + /** + * Any encrypted data that we wish to have returned to us. + * Basically, this is all the card data that we will have to + * re-submit to to Realex in order to complete the authorisation. + */ + protected function getMerchantData() + { + /** + * @var CreditCard $card + */ + $card = $this->request->getCard(); + $data = array( + 'transactionId' => $this->request->getTransactionId(), + 'currency' => $this->request->getCurrency(), + 'amount' => $this->request->getAmount(), + 'number' => $card->getNumber(), + 'expiryMonth' => $card->getExpiryMonth(), + 'expiryYear' => $card->getExpiryYear(), + 'billingName' => $card->getBillingName(), + 'cvv' => $card->getCvv(), + 'issueNumber' => $card->getIssueNumber(), + 'billingCountry' => $card->getBillingCountry() + ); + $serialised = json_encode($data); + $encoded = base64_encode($serialised); + + return $encoded; + } + + public function getRedirectData() + { + return array( + 'PaReq' => (string) $this->xml->pareq, + 'TermUrl' => $this->request->getReturnUrl(), + 'MD' => $this->getMerchantData() + ); + } } diff --git a/src/Omnipay/Realex/Message/FetchTransactionRequest.php b/src/Omnipay/Realex/Message/FetchTransactionRequest.php index 1273c64..9f8a1c9 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionRequest.php +++ b/src/Omnipay/Realex/Message/FetchTransactionRequest.php @@ -7,72 +7,76 @@ /** * Realex Query Request */ -class FetchTransactionRequest extends RemoteAbstractRequest { - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - // No amount, currency or card number for query requests but still needs to be in hash - $amount = ''; - $currency = ''; - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'query'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // original order ID - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($orderIdEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new FetchTransactionResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('3dSecureEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('3dSecureEndpoint', $value); - } - +class FetchTransactionRequest extends RemoteAbstractRequest +{ + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + // No amount, currency or card number for query requests but still needs to be in hash + $amount = ''; + $currency = ''; + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'query'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // original order ID + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($orderIdEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new FetchTransactionResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('3dSecureEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('3dSecureEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/FetchTransactionResponse.php b/src/Omnipay/Realex/Message/FetchTransactionResponse.php index 3eec6e6..554244f 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionResponse.php +++ b/src/Omnipay/Realex/Message/FetchTransactionResponse.php @@ -10,45 +10,53 @@ /** * Realex Query Response */ -class FetchTransactionResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } - - public function getTransactionReference() { - return ($this->xml->pasref) ? (string) $this->xml->pasref : null; - } - - public function getAuthCode() { - return ($this->xml->authcode) ? (string) $this->xml->authcode : null; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class FetchTransactionResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() + { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() + { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index e01c73d..f12ee85 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -5,170 +5,195 @@ /** * Realex Abstract Request */ -abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { - - public function getMerchantId() { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) { - return $this->setParameter('merchantId', $value); - } - - public function getAccount() { - return $this->getParameter('account'); - } - - public function setAccount($value) { - return $this->setParameter('account', $value); - } - - public function getSecret() { - return $this->getParameter('secret'); - } - - public function setSecret($value) { - return $this->setParameter('secret', $value); - } - - public function setStore($value) { - return $this->setParameter('store', $value); - } - - public function getStore() { - return $this->getParameters('store'); - } - - public function getPares() { - return $this->getParameter('pares'); - } - - public function setPares($value) { - return $this->setParameter('pares', $value); - } - - public function setCavv($value) { - return $this->setParameter('cavv', $value); - } - - public function getCavv() { - return $this->getParameter('cavv'); - } - - public function setXid($value) { - return $this->setParameter('xid', $value); - } - - public function getXid() { - return $this->getParameter('xid'); - } - - public function setEci($value) { - return $this->setParameter('eci', $value); - } - - public function getEci() { - return $this->getParameter('eci'); - } - - public function setNotifyUrl($value) { - return $this->setParameter('notifyUrl', $value); - } - - public function getNotifyUrl() { - return $this->getParameter('notifyUrl'); - } - - public function setExtraData($value) { - return $this->setParameter('extraData', $value); - } - - public function getExtraData() { - return $this->getParameter('extraData'); - } - - public function getBaseData($autoSettle = true, $card = null) { - $data = array( - 'EXTRA' => $this->getExtraData(), - 'MERCHANT_ID' => $this->getMerchantId(), - 'ORDER_ID' => $this->getTransactionId(), - 'CURRENCY' => $this->getCurrency(), - 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), - 'AMOUNT' => round($this->getAmount() * 100), - 'TIMESTAMP' => gmdate('YmdHis'), - 'AUTO_SETTLE_FLAG' => $autoSettle - ); - $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); - return $data; - } - - public function createSignature($data, $method = 'sha1', $card = null) { - $hash = $method(rtrim(implode('.', array( - $data['TIMESTAMP'], - $data['MERCHANT_ID'], - $data['ORDER_ID'], - $data['AMOUNT'], - $data['CURRENCY'], - $card !== null ? $card->getNumber() : null - )), '.')); - - return $method($hash . '.' . $this->getSecret()); - } - - public function getRequestXML($card, $autoSettle = true, $extraData = array(), $addressData = true, $cardData = true) { - $data = $this->getBaseData($autoSettle, $card); - $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); - $request = new \SimpleXMLElement(''); - $request['timestamp'] = $data['TIMESTAMP']; - $request['type'] = $this->getType(); - $request->merchantid = $this->getMerchantId(); - $request->account = $this->getAccount(); - $request->orderid = $data['ORDER_ID']; - //$request->md5hash = $this->createSignature($data, 'md5', $card); - $request->custipaddress = $this->getClientIp(); - $request->amount = $data['AMOUNT']; - $request->amount['currency'] = $data['CURRENCY']; - $request->autosettle['flag'] = (int) $data['AUTO_SETTLE_FLAG']; - // Flesh out the XML structure - $request->addChild('card'); - $request->card->addChild('cvn'); - $request->card->number = $card->getNumber(); - $request->card->expdate = $card->getExpiryDate('my'); - $request->card->type = strtoupper($brand); - $request->card->chname = $card->getName(); - // Not all request want this data - if ($cardData) { - $request->card->issueno = $card->getIssueNumber(); - $request->card->addChild('cvn'); - $request->card->cvn->addChild('number', $card->getCvv()); - $request->card->cvn->addChild('presind', 1); - } - // not all requests want this data - if ($addressData) { - $request->address['type'] = 'billing'; - $request->address->code = $card->getBillingPostcode(); - $request->address->country = strtoupper($card->getBillingCountry()); - } - // Add in extra array data for any obscure fields - if (!empty($extraData)) { - foreach ($extraData as $key => $value) { - $request->$key = $value; - } - } - $request->sha1hash = $data['SHA1HASH']; - return $request->asXML(); - } - - protected function getType() { - return 'auth'; - } - - public function getCheckoutEndpoint() { - return $this->getParameter('checkoutEndpoint'); - } - - public function setCheckoutEndpoint($value) { - return $this->setParameter('checkoutEndpoint', $value); - } - +abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest +{ + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function setStore($value) + { + return $this->setParameter('store', $value); + } + + public function getStore() + { + return $this->getParameters('store'); + } + + public function getPares() + { + return $this->getParameter('pares'); + } + + public function setPares($value) + { + return $this->setParameter('pares', $value); + } + + public function setCavv($value) + { + return $this->setParameter('cavv', $value); + } + + public function getCavv() + { + return $this->getParameter('cavv'); + } + + public function setXid($value) + { + return $this->setParameter('xid', $value); + } + + public function getXid() + { + return $this->getParameter('xid'); + } + + public function setEci($value) + { + return $this->setParameter('eci', $value); + } + + public function getEci() + { + return $this->getParameter('eci'); + } + + public function setNotifyUrl($value) + { + return $this->setParameter('notifyUrl', $value); + } + + public function getNotifyUrl() + { + return $this->getParameter('notifyUrl'); + } + + public function setExtraData($value) + { + return $this->setParameter('extraData', $value); + } + + public function getExtraData() + { + return $this->getParameter('extraData'); + } + + public function getBaseData($autoSettle = true, $card = null) + { + $data = array( + 'EXTRA' => $this->getExtraData(), + 'MERCHANT_ID' => $this->getMerchantId(), + 'ORDER_ID' => $this->getTransactionId(), + 'CURRENCY' => $this->getCurrency(), + 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), + 'AMOUNT' => round($this->getAmount() * 100), + 'TIMESTAMP' => gmdate('YmdHis'), + 'AUTO_SETTLE_FLAG' => $autoSettle + ); + $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); + return $data; + } + + public function createSignature($data, $method = 'sha1', $card = null) + { + $hash = $method(rtrim(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['AMOUNT'], + $data['CURRENCY'], + $card !== null ? $card->getNumber() : null + )), '.')); + + return $method($hash . '.' . $this->getSecret()); + } + + public function getRequestXML($card, $autoSettle = true, $extraData = array(), $addressData = true, $cardData = true) + { + $data = $this->getBaseData($autoSettle, $card); + $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); + $request = new \SimpleXMLElement(''); + $request['timestamp'] = $data['TIMESTAMP']; + $request['type'] = $this->getType(); + $request->merchantid = $this->getMerchantId(); + $request->account = $this->getAccount(); + $request->orderid = $data['ORDER_ID']; + //$request->md5hash = $this->createSignature($data, 'md5', $card); + $request->custipaddress = $this->getClientIp(); + $request->amount = $data['AMOUNT']; + $request->amount['currency'] = $data['CURRENCY']; + $request->autosettle['flag'] = (int) $data['AUTO_SETTLE_FLAG']; + // Flesh out the XML structure + $request->addChild('card'); + $request->card->addChild('cvn'); + $request->card->number = $card->getNumber(); + $request->card->expdate = $card->getExpiryDate('my'); + $request->card->type = strtoupper($brand); + $request->card->chname = $card->getName(); + // Not all request want this data + if ($cardData) { + $request->card->issueno = $card->getIssueNumber(); + $request->card->addChild('cvn'); + $request->card->cvn->addChild('number', $card->getCvv()); + $request->card->cvn->addChild('presind', 1); + } + // not all requests want this data + if ($addressData) { + $request->address['type'] = 'billing'; + $request->address->code = $card->getBillingPostcode(); + $request->address->country = strtoupper($card->getBillingCountry()); + } + // Add in extra array data for any obscure fields + if (!empty($extraData)) { + foreach ($extraData as $key => $value) { + $request->$key = $value; + } + } + $request->sha1hash = $data['SHA1HASH']; + return $request->asXML(); + } + + protected function getType() + { + return 'auth'; + } + + public function getCheckoutEndpoint() + { + return $this->getParameter('checkoutEndpoint'); + } + + public function setCheckoutEndpoint($value) + { + return $this->setParameter('checkoutEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php index 1fb3117..b634244 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php @@ -5,18 +5,20 @@ /** * Realex Redirect Authorize Request */ -class RedirectAuthorizeRequest extends AbstractRequest { +class RedirectAuthorizeRequest extends AbstractRequest +{ + public function getData() + { + return null; + } - public function getData() { - return null; - } - - public function getRedirectData() { - return $this->getBaseData(); - } - - public function sendData($data) { - return $this->response = new RedirectAuthorizeResponse($this, $data); - } + public function getRedirectData() + { + return $this->getBaseData(); + } + public function sendData($data) + { + return $this->response = new RedirectAuthorizeResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php index 4e60f0c..68e12ec 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php @@ -7,30 +7,35 @@ /** * Realex Redirect Authorize Response */ -class RedirectAuthorizeResponse extends Response implements RedirectResponseInterface { - - public function isSuccessful() { - return false; - } - - public function isRedirect() { - return true; - } - - public function getRedirectUrl() { - return $this->getRequest()->getCheckoutEndpoint(); - } - - public function getTransactionReference() { - return $this->getRequest()->getTransactionId(); - } - - public function getRedirectMethod() { - return 'POST'; - } - - public function getRedirectData() { - return $this->getRequest()->getBaseData(false); - } - +class RedirectAuthorizeResponse extends Response implements RedirectResponseInterface +{ + public function isSuccessful() + { + return false; + } + + public function isRedirect() + { + return true; + } + + public function getRedirectUrl() + { + return $this->getRequest()->getCheckoutEndpoint(); + } + + public function getTransactionReference() + { + return $this->getRequest()->getTransactionId(); + } + + public function getRedirectMethod() + { + return 'POST'; + } + + public function getRedirectData() + { + return $this->getRequest()->getBaseData(false); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php index bc541da..1a25b47 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php @@ -7,30 +7,31 @@ /** * Realex Redirect Complete Authorize Request */ -class RedirectCompleteAuthorizeRequest extends AbstractRequest { - - public function getData() { - // Build initial hash - $hash = sha1(implode('.', array( - $this->httpRequest->request->get('TIMESTAMP'), - $this->httpRequest->request->get('MERCHANT_ID'), - $this->httpRequest->request->get('ORDER_ID'), - $this->httpRequest->request->get('RESULT'), - $this->httpRequest->request->get('MESSAGE'), - $this->httpRequest->request->get('PASREF'), - $this->httpRequest->request->get('AUTHCODE') - ))); - - // Validate signature - if ($this->httpRequest->request->get('SHA1HASH') !== sha1($hash . '.' . $this->getSecret())) { - throw new InvalidResponseException; - } - - return $this->httpRequest->request->all(); - } - - public function sendData($data) { - return $this->response = new Response($this, $data); - } - +class RedirectCompleteAuthorizeRequest extends AbstractRequest +{ + public function getData() + { + // Build initial hash + $hash = sha1(implode('.', array( + $this->httpRequest->request->get('TIMESTAMP'), + $this->httpRequest->request->get('MERCHANT_ID'), + $this->httpRequest->request->get('ORDER_ID'), + $this->httpRequest->request->get('RESULT'), + $this->httpRequest->request->get('MESSAGE'), + $this->httpRequest->request->get('PASREF'), + $this->httpRequest->request->get('AUTHCODE') + ))); + + // Validate signature + if ($this->httpRequest->request->get('SHA1HASH') !== sha1($hash . '.' . $this->getSecret())) { + throw new InvalidResponseException; + } + + return $this->httpRequest->request->all(); + } + + public function sendData($data) + { + return $this->response = new Response($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php index add0e61..f3d3702 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php @@ -7,36 +7,36 @@ /** * Realex Redirect Complete Authorize Request */ -class RedirectCompleteStoreCardRequest extends AbstractRequest { - - public function getData() { - - $data; - foreach (json_decode($this->httpRequest->request->get('hppResponse')) AS $key => $value) { - $data[$key] = base64_decode($value); - } - - // Build initial hash - $hash = sha1(implode('.', array( - $data['TIMESTAMP'], - $data['MERCHANT_ID'], - $data['ORDER_ID'], - $data['RESULT'], - $data['MESSAGE'], - $data['PASREF'], - $data['AUTHCODE'], - ))); - - // Validate signature - if ($data['SHA1HASH'] !== sha1($hash . '.' . $this->getSecret())) { - throw new InvalidResponseException; - } - - return $data; - } - - public function sendData($data) { - return $this->response = new dataVaultResponse($this, $data); - } - +class RedirectCompleteStoreCardRequest extends AbstractRequest +{ + public function getData() + { + $data; + foreach (json_decode($this->httpRequest->request->get('hppResponse')) as $key => $value) { + $data[$key] = base64_decode($value); + } + + // Build initial hash + $hash = sha1(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['RESULT'], + $data['MESSAGE'], + $data['PASREF'], + $data['AUTHCODE'], + ))); + + // Validate signature + if ($data['SHA1HASH'] !== sha1($hash . '.' . $this->getSecret())) { + throw new InvalidResponseException; + } + + return $data; + } + + public function sendData($data) + { + return $this->response = new dataVaultResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php index e4f33b2..3fa7be9 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php @@ -5,56 +5,60 @@ /** * Realex Redirect Authorize Request */ -class RedirectDataVaultRequest extends AbstractRequest { - - public function getData() { - return null; - } - - public function getBaseData($autoSettle = '1', $card = null) { - $data = array( - 'ACCOUNT' => $this->getAccount(), - 'MERCHANT_ID' => $this->getMerchantId(), - 'ORDER_ID' => $this->getTransactionId(), - 'CURRENCY' => $this->getCurrency(), - 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), - 'AMOUNT' => round($this->getAmount() * 100), - 'TIMESTAMP' => gmdate('YmdHis'), - 'AUTO_SETTLE_FLAG' => $autoSettle, - 'HPP_VERSION' => 2 - ); - - if (isset($this->getData()['extraData']) && is_array($this->getData()['extraData'])) { - $data = array_merge($data, $this->getData()['extraData']); - } - $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); - return $data; - } - - /* - * "timestamp.merchantid.orderid.amount.currency.payerref.paymentmethod" - */ - - public function createSignature($data, $method = 'sha1', $card = null) { - $hash = $method(implode('.', array( - $data['TIMESTAMP'], - $data['MERCHANT_ID'], - $data['ORDER_ID'], - $data['AMOUNT'], - $data['CURRENCY'], - $data['PAYER_REF'], - '' - ))); - - return $method($hash . '.' . $this->getSecret()); - } - - public function getRedirectData() { - return $this->getBaseData(); - } - - public function sendData($data) { - return $this->response = new RedirectDataVaultResponse($this, $data); - } +class RedirectDataVaultRequest extends AbstractRequest +{ + public function getData() + { + return null; + } + public function getBaseData($autoSettle = '1', $card = null) + { + $data = array( + 'ACCOUNT' => $this->getAccount(), + 'MERCHANT_ID' => $this->getMerchantId(), + 'ORDER_ID' => $this->getTransactionId(), + 'CURRENCY' => $this->getCurrency(), + 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), + 'AMOUNT' => round($this->getAmount() * 100), + 'TIMESTAMP' => gmdate('YmdHis'), + 'AUTO_SETTLE_FLAG' => $autoSettle, + 'HPP_VERSION' => 2 + ); + + if (isset($this->getData()['extraData']) && is_array($this->getData()['extraData'])) { + $data = array_merge($data, $this->getData()['extraData']); + } + $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); + return $data; + } + + /* + * "timestamp.merchantid.orderid.amount.currency.payerref.paymentmethod" + */ + + public function createSignature($data, $method = 'sha1', $card = null) + { + $hash = $method(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['AMOUNT'], + $data['CURRENCY'], + $data['PAYER_REF'], + '' + ))); + + return $method($hash . '.' . $this->getSecret()); + } + + public function getRedirectData() + { + return $this->getBaseData(); + } + + public function sendData($data) + { + return $this->response = new RedirectDataVaultResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php index 855727c..b38a7aa 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php @@ -7,31 +7,36 @@ /** * Realex Redirect Authorize Response */ -class RedirectDataVaultResponse extends Response implements RedirectResponseInterface { - - public function isSuccessful() { - return false; - } - - public function isRedirect() { - return true; - } - - public function getRedirectUrl() { - return $this->getRequest()->getCheckoutEndpoint(); - } - - public function getTransactionReference() { - return $this->getRequest()->getTransactionId(); - } - - public function getRedirectMethod() { - return 'POST'; - } - - public function getRedirectData() { - $data = $this->getRequest()->getBaseData(false); - return $data; - } - +class RedirectDataVaultResponse extends Response implements RedirectResponseInterface +{ + public function isSuccessful() + { + return false; + } + + public function isRedirect() + { + return true; + } + + public function getRedirectUrl() + { + return $this->getRequest()->getCheckoutEndpoint(); + } + + public function getTransactionReference() + { + return $this->getRequest()->getTransactionId(); + } + + public function getRedirectMethod() + { + return 'POST'; + } + + public function getRedirectData() + { + $data = $this->getRequest()->getBaseData(false); + return $data; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php index fab5395..91d8365 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php @@ -5,10 +5,10 @@ /** * Realex Redirect Purchase Request */ -class RedirectPurchaseRequest extends RedirectAuthorizeRequest { - - public function sendData($data) { - return $this->response = new RedirectPurchaseResponse($this, $data); - } - +class RedirectPurchaseRequest extends RedirectAuthorizeRequest +{ + public function sendData($data) + { + return $this->response = new RedirectPurchaseResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php index 221a515..afd4b15 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php @@ -7,10 +7,10 @@ /** * Realex Redirect Purchase Response */ -class RedirectPurchaseResponse extends RedirectAuthorizeResponse { - - public function getRedirectData() { - return $this->getRequest()->getBaseData(); - } - +class RedirectPurchaseResponse extends RedirectAuthorizeResponse +{ + public function getRedirectData() + { + return $this->getRequest()->getBaseData(); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php index 0fe48fd..e854454 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php @@ -5,82 +5,96 @@ /** * Realex Redirect Purchase Request */ -class RedirectStoreCardRequest extends RedirectDataVaultRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($data) { - $this->setParameter('customerRef', $data); - } - - public function getCustomerExists() { - return $this->getParameter('customerExists'); - } - - public function setCustomerExists($data) { - $this->setParameter('customerExists', $data); - } - - public function getValidateCardOnly() { - return $this->getParameter('validateCardOnly'); - } - - public function setValidateCardOnly($data) { - $this->setParameter('validateCardOnly', $data); - } - - public function getOfferSaveCard() { - return $this->getParameter('offerSaveCard'); - } - - public function setOfferSaveCard($data) { - $this->setParameter('offerSaveCard', $data); - } - - public function getCardPaymentButton() { - return $this->getParameter('cardPaymentButton'); - } - - public function setCardPaymentButton($data) { - $this->setParameter('cardPaymentButton', $data); - } - - public function getHPPPostDimensions() { - return $this->getParameter('HPPPostDimensions'); - } - - public function setHPPPostDimensions($data) { - $this->setParameter('HPPPostDimensions', $data); - } - - public function getHPPPostResponse() { - return $this->getParameter('HPPPostResponse'); - } - - public function setHPPPostResponse($data) { - $this->setParameter('HPPPostResponse', $data); - } - - public function getData() { - - $data['extraData'] = [ - 'PAYER_REF' => $this->getCustomerRef(), - 'PAYER_EXIST' => $this->getCustomerExists(), - 'VALIDATE_CARD_ONLY' => $this->getValidateCardOnly(), - 'OFFER_SAVE_CARD' => $this->getOfferSaveCard(), - 'CARD_STORAGE_ENABLE' => '1', - 'CARD_PAYMENT_BUTTON' => $this->getCardPaymentButton(), - 'HPP_POST_DIMENSIONS' => $this->getHPPPostDimensions(), - 'HPP_POST_RESPONSE' => $this->getHPPPostResponse(), - ]; - - return $data; - } - - public function sendData($data) { - return $this->response = new RedirectStoreCardResponse($this, $data); - } - +class RedirectStoreCardRequest extends RedirectDataVaultRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($data) + { + $this->setParameter('customerRef', $data); + } + + public function getCustomerExists() + { + return $this->getParameter('customerExists'); + } + + public function setCustomerExists($data) + { + $this->setParameter('customerExists', $data); + } + + public function getValidateCardOnly() + { + return $this->getParameter('validateCardOnly'); + } + + public function setValidateCardOnly($data) + { + $this->setParameter('validateCardOnly', $data); + } + + public function getOfferSaveCard() + { + return $this->getParameter('offerSaveCard'); + } + + public function setOfferSaveCard($data) + { + $this->setParameter('offerSaveCard', $data); + } + + public function getCardPaymentButton() + { + return $this->getParameter('cardPaymentButton'); + } + + public function setCardPaymentButton($data) + { + $this->setParameter('cardPaymentButton', $data); + } + + public function getHPPPostDimensions() + { + return $this->getParameter('HPPPostDimensions'); + } + + public function setHPPPostDimensions($data) + { + $this->setParameter('HPPPostDimensions', $data); + } + + public function getHPPPostResponse() + { + return $this->getParameter('HPPPostResponse'); + } + + public function setHPPPostResponse($data) + { + $this->setParameter('HPPPostResponse', $data); + } + + public function getData() + { + $data['extraData'] = [ + 'PAYER_REF' => $this->getCustomerRef(), + 'PAYER_EXIST' => $this->getCustomerExists(), + 'VALIDATE_CARD_ONLY' => $this->getValidateCardOnly(), + 'OFFER_SAVE_CARD' => $this->getOfferSaveCard(), + 'CARD_STORAGE_ENABLE' => '1', + 'CARD_PAYMENT_BUTTON' => $this->getCardPaymentButton(), + 'HPP_POST_DIMENSIONS' => $this->getHPPPostDimensions(), + 'HPP_POST_RESPONSE' => $this->getHPPPostResponse(), + ]; + + return $data; + } + + public function sendData($data) + { + return $this->response = new RedirectStoreCardResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php index 0d5b77a..208feb3 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php @@ -7,12 +7,12 @@ /** * Realex Redirect Purchase Response */ -class RedirectStoreCardResponse extends RedirectDataVaultResponse { - - public function getRedirectData() { - $data = $this->getRequest()->getRedirectData(); - - return $data; - } +class RedirectStoreCardResponse extends RedirectDataVaultResponse +{ + public function getRedirectData() + { + $data = $this->getRequest()->getRedirectData(); + return $data; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php index 5a710e0..cd2c537 100644 --- a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php @@ -8,52 +8,58 @@ /** * Realex Response */ -class dataVaultResponse extends AbstractResponse { - - public function __construct(RequestInterface $request, $data = array()) { - $this->request = $request; - $this->data = $data; - } - - public function isSuccessful() { - if (!$this->isPayerSetupSuccessful()) { - return false; - } elseif (!$this->isPayerCardAddSuccessful()) { - return false; - } else { - return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; - } - } - - public function getMessage() { - $message; - if (isset($this->data['PMT_SETUP_MSG'])) { - $message .= $this->data['PMT_SETUP_MSG'] . ' '; - } - if (isset($this->data['PAYER_SETUP_MSG'])) { - $message .= $this->data['PAYER_SETUP_MSG'] . ' '; - } - if (isset($this->data['MESSAGE'])) { - $message .= $this->data['MESSAGE'] . ' '; - } - - return $message; - } - - public function getTransactionReference() { - return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; - } - - public function isPayerSetupSuccessful() { - return !isset($this->data['PAYER_SETUP']) || (isset($this->data['PAYER_SETUP']) && '00' === $this->data['PAYER_SETUP']); - } - - public function isPayerCardAddSuccessful() { - return !isset($this->data['PMT_SETUP']) || (isset($this->data['PMT_SETUP']) && '00' === $this->data['PMT_SETUP']); - } - - public function getCardToken() { - return isset($this->data['SAVED_PMT_REF']) ? $this->data['SAVED_PMT_REF'] : null; - } +class dataVaultResponse extends AbstractResponse +{ + public function __construct(RequestInterface $request, $data = array()) + { + $this->request = $request; + $this->data = $data; + } + public function isSuccessful() + { + if (!$this->isPayerSetupSuccessful()) { + return false; + } elseif (!$this->isPayerCardAddSuccessful()) { + return false; + } else { + return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; + } + } + + public function getMessage() + { + $message; + if (isset($this->data['PMT_SETUP_MSG'])) { + $message .= $this->data['PMT_SETUP_MSG'] . ' '; + } + if (isset($this->data['PAYER_SETUP_MSG'])) { + $message .= $this->data['PAYER_SETUP_MSG'] . ' '; + } + if (isset($this->data['MESSAGE'])) { + $message .= $this->data['MESSAGE'] . ' '; + } + + return $message; + } + + public function getTransactionReference() + { + return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; + } + + public function isPayerSetupSuccessful() + { + return !isset($this->data['PAYER_SETUP']) || (isset($this->data['PAYER_SETUP']) && '00' === $this->data['PAYER_SETUP']); + } + + public function isPayerCardAddSuccessful() + { + return !isset($this->data['PMT_SETUP']) || (isset($this->data['PMT_SETUP']) && '00' === $this->data['PMT_SETUP']); + } + + public function getCardToken() + { + return isset($this->data['SAVED_PMT_REF']) ? $this->data['SAVED_PMT_REF'] : null; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/response.php b/src/Omnipay/Realex/Message/Redirect/response.php index 3fe32e8..e3d1599 100644 --- a/src/Omnipay/Realex/Message/Redirect/response.php +++ b/src/Omnipay/Realex/Message/Redirect/response.php @@ -8,23 +8,26 @@ /** * Realex Response */ -class Response extends AbstractResponse { - - public function __construct(RequestInterface $request, $data = array()) { - $this->request = $request; - $this->data = $data; - } - - public function isSuccessful() { - return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; - } - - public function getMessage() { - return isset($this->data['MESSAGE']) ? $this->data['MESSAGE'] : null; - } - - public function getTransactionReference() { - return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; - } - +class Response extends AbstractResponse +{ + public function __construct(RequestInterface $request, $data = array()) + { + $this->request = $request; + $this->data = $data; + } + + public function isSuccessful() + { + return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; + } + + public function getMessage() + { + return isset($this->data['MESSAGE']) ? $this->data['MESSAGE'] : null; + } + + public function getTransactionReference() + { + return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; + } } diff --git a/src/Omnipay/Realex/Message/RefundRequest.php b/src/Omnipay/Realex/Message/RefundRequest.php index ef31e19..b41a590 100644 --- a/src/Omnipay/Realex/Message/RefundRequest.php +++ b/src/Omnipay/Realex/Message/RefundRequest.php @@ -7,128 +7,139 @@ /** * Realex Refund Request */ -class RefundRequest extends RemoteAbstractRequest { - - public function getTransactionReference() { - return $this->getParameter('transactionReference'); - } - - public function setTransactionReference($value) { - return $this->setParameter('transactionReference', $value); - } - - public function getAuthCode() { - return $this->getParameter('authCode'); - } - - public function setAuthCode($value) { - return $this->setParameter('authCode', $value); - } - - public function getOriginalTransactionId() { - return $this->getParameter('originalTransactionId'); - } - - public function setOriginalTransactionId($value) { - return $this->setParameter('originalTransactionId', $value); - } - - public function getRefundPassword() { - return $this->getParameter('refundPassword'); - } - - public function setRefundPassword($value) { - return $this->setParameter('refundPassword', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate( - 'amount', 'currency', 'originalTransactionId', 'transactionReference', 'authCode', 'refundPassword' - ); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $originalTransactionId = $this->getOriginalTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - // No card number for rebate requests but still needs to be in hash - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$originalTransactionId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'rebate'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // the ID of the original transaction (confusingly in a tag called 'orderid') - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); - $root->appendChild($orderIdEl); - - // pasref for the original transaction - $pasRefEl = $domTree->createElement('pasref'); - $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); - $root->appendChild($pasRefEl); - - // authcode returned for original transaction - $authCodeEl = $domTree->createElement('authcode'); - $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); - $root->appendChild($authCodeEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - // refund hash - $refundHash = sha1($this->getRefundPassword()); - $refundHashEl = $domTree->createElement('refundhash'); - $refundHashEl->appendChild($domTree->createTextNode($refundHash)); - $root->appendChild($refundHashEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new RefundResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } - +class RefundRequest extends RemoteAbstractRequest +{ + public function getTransactionReference() + { + return $this->getParameter('transactionReference'); + } + + public function setTransactionReference($value) + { + return $this->setParameter('transactionReference', $value); + } + + public function getAuthCode() + { + return $this->getParameter('authCode'); + } + + public function setAuthCode($value) + { + return $this->setParameter('authCode', $value); + } + + public function getOriginalTransactionId() + { + return $this->getParameter('originalTransactionId'); + } + + public function setOriginalTransactionId($value) + { + return $this->setParameter('originalTransactionId', $value); + } + + public function getRefundPassword() + { + return $this->getParameter('refundPassword'); + } + + public function setRefundPassword($value) + { + return $this->setParameter('refundPassword', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate( + 'amount', 'currency', 'originalTransactionId', 'transactionReference', 'authCode', 'refundPassword' + ); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $originalTransactionId = $this->getOriginalTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + // No card number for rebate requests but still needs to be in hash + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$originalTransactionId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'rebate'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // the ID of the original transaction (confusingly in a tag called 'orderid') + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); + $root->appendChild($orderIdEl); + + // pasref for the original transaction + $pasRefEl = $domTree->createElement('pasref'); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); + $root->appendChild($pasRefEl); + + // authcode returned for original transaction + $authCodeEl = $domTree->createElement('authcode'); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); + $root->appendChild($authCodeEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + // refund hash + $refundHash = sha1($this->getRefundPassword()); + $refundHashEl = $domTree->createElement('refundhash'); + $refundHashEl->appendChild($domTree->createTextNode($refundHash)); + $root->appendChild($refundHashEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new RefundResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/RefundResponse.php b/src/Omnipay/Realex/Message/RefundResponse.php index 3ab9688..ec4dc60 100644 --- a/src/Omnipay/Realex/Message/RefundResponse.php +++ b/src/Omnipay/Realex/Message/RefundResponse.php @@ -10,45 +10,53 @@ /** * Realex Refund Response */ -class RefundResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } - - public function getTransactionReference() { - return ($this->xml->pasref) ? (string) $this->xml->pasref : null; - } - - public function getAuthCode() { - return ($this->xml->authcode) ? (string) $this->xml->authcode : null; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class RefundResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() + { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() + { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php index 611ae30..d600577 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php @@ -8,75 +8,85 @@ /** * Realex Purchase Request */ -abstract class RemoteAbstractRequest extends AbstractRequest { - - protected $cardBrandMap = array( - 'mastercard' => 'mc', - 'diners_club' => 'diners' - ); - - /** - * Override some of the default Omnipay card brand names - * - * @return mixed - */ - protected function getCardBrand() { - $brand = $this->getCard()->getBrand(); - - if (isset($this->cardBrandMap[$brand])) { - $brand = $this->cardBrandMap[$brand]; - } - - return strtoupper($brand); - } - - public function getMerchantId() { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) { - return $this->setParameter('merchantId', $value); - } - - public function getAccount() { - return $this->getParameter('account'); - } - - public function setAccount($value) { - return $this->setParameter('account', $value); - } - - public function getSecret() { - return $this->getParameter('secret'); - } - - public function setSecret($value) { - return $this->setParameter('secret', $value); - } - - public function getReturnUrl() { - return $this->getParameter('returnUrl'); - } - - public function setReturnUrl($value) { - return $this->setParameter('returnUrl', $value); - } - - public function sendData($data) { - // register the payment - $this->httpClient->setConfig(array( - 'curl.options' => array( - 'CURLOPT_SSLVERSION' => 1, - 'CURLOPT_SSL_VERIFYPEER' => false - ) - )); - - $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); - - return $this->createResponse($httpResponse->getBody(true)); - } - - abstract public function getEndpoint(); - - abstract protected function createResponse($data); +abstract class RemoteAbstractRequest extends AbstractRequest +{ + protected $cardBrandMap = array( + 'mastercard' => 'mc', + 'diners_club' => 'diners' + ); + + /** + * Override some of the default Omnipay card brand names + * + * @return mixed + */ + protected function getCardBrand() + { + $brand = $this->getCard()->getBrand(); + + if (isset($this->cardBrandMap[$brand])) { + $brand = $this->cardBrandMap[$brand]; + } + + return strtoupper($brand); + } + + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getReturnUrl() + { + return $this->getParameter('returnUrl'); + } + + public function setReturnUrl($value) + { + return $this->setParameter('returnUrl', $value); + } + + public function sendData($data) + { + // register the payment + $this->httpClient->setConfig(array( + 'curl.options' => array( + 'CURLOPT_SSLVERSION' => 1, + 'CURLOPT_SSL_VERIFYPEER' => false + ) + )); + + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); + + return $this->createResponse($httpResponse->getBody(true)); + } + + abstract public function getEndpoint(); + + abstract protected function createResponse($data); } diff --git a/src/Omnipay/Realex/Message/RemoteAbstractResponse.php b/src/Omnipay/Realex/Message/RemoteAbstractResponse.php index 7a0a1ba..b6bc005 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractResponse.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractResponse.php @@ -11,28 +11,29 @@ /** * Realex Abstract Response */ -abstract class RemoteAbstractResponse extends AbstractResponse implements RedirectResponseInterface { - - protected $xml; - - public function __construct(RequestInterface $request, $data) { - parent::__construct($request, $data); - - $this->xml = $this->parseXml($data); - } - - /** - * Turn the raw XML response string into a SimpleXMLElement - * - * @param string $data - * @return \SimpleXMLElement - */ - public function parseXml($data) { - $data = str_replace(' ', ' ', $data); - $data = str_replace("\n", '', $data); - $data = str_replace("\r", '', $data); - - return new \SimpleXMLElement($data); - } - +abstract class RemoteAbstractResponse extends AbstractResponse implements RedirectResponseInterface +{ + protected $xml; + + public function __construct(RequestInterface $request, $data) + { + parent::__construct($request, $data); + + $this->xml = $this->parseXml($data); + } + + /** + * Turn the raw XML response string into a SimpleXMLElement + * + * @param string $data + * @return \SimpleXMLElement + */ + public function parseXml($data) + { + $data = str_replace(' ', ' ', $data); + $data = str_replace("\n", '', $data); + $data = str_replace("\r", '', $data); + + return new \SimpleXMLElement($data); + } } diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index 1865199..1f287d8 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -8,156 +8,167 @@ /** * Realex Auth Request */ -class SavedAuthRequest extends RemoteAbstractRequest { - - public function getCavv() { - return $this->getParameter('cavv'); - } - - public function setCavv($value) { - return $this->setParameter('cavv', $value); - } - - public function getEci() { - return $this->getParameter('eci'); - } - - public function setEci($value) { - return $this->setParameter('eci', $value); - } - - public function getXid() { - return $this->getParameter('xid'); - } - - public function setXid($value) { - return $this->setParameter('xid', $value); - } - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.{$this->getCustomerRef()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'receipt-in'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->setAttribute('currency', $this->getCurrency()); - $amountEl->appendChild($domTree->createTextNode($amount)); - $root->appendChild($amountEl); - - $paymentDataEl = $domTree->createElement('paymentdata'); - $cvnEl = $domTree->createElement('cvn'); - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getCvv())); - - $cvnEl->appendChild($numberEl); - $paymentDataEl->appendChild($cvnEl); - $root->appendChild($paymentDataEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $root->appendChild($payerRefEl); - - $paymentMethodEl = $domTree->createElement('paymentmethod'); - $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); - $root->appendChild($paymentMethodEl); - - $settleEl = $domTree->createElement('autosettle'); - $settleEl->setAttribute('flag', 1); - $root->appendChild($settleEl); - - // 3D Secure section - $mpiEl = $domTree->createElement('mpi'); - $cavvEl = $domTree->createElement('cavv'); - $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); - $xidEl = $domTree->createElement('xid'); - $xidEl->appendChild($domTree->createTextNode($this->getXid())); - $eciEl = $domTree->createElement('eci'); - $eciEl->appendChild($domTree->createTextNode($this->getEci())); - $mpiEl->appendChild($cavvEl); - $mpiEl->appendChild($xidEl); - $mpiEl->appendChild($eciEl); - $root->appendChild($mpiEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $tssEl = $domTree->createElement('tssinfo'); - $addressEl = $domTree->createElement('address'); - $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - $tssEl->appendChild($addressEl); - $root->appendChild($tssEl); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new AuthResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } - +class SavedAuthRequest extends RemoteAbstractRequest +{ + public function getCavv() + { + return $this->getParameter('cavv'); + } + + public function setCavv($value) + { + return $this->setParameter('cavv', $value); + } + + public function getEci() + { + return $this->getParameter('eci'); + } + + public function setEci($value) + { + return $this->setParameter('eci', $value); + } + + public function getXid() + { + return $this->getParameter('xid'); + } + + public function setXid($value) + { + return $this->setParameter('xid', $value); + } + + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.{$this->getCustomerRef()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'receipt-in'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->setAttribute('currency', $this->getCurrency()); + $amountEl->appendChild($domTree->createTextNode($amount)); + $root->appendChild($amountEl); + + $paymentDataEl = $domTree->createElement('paymentdata'); + $cvnEl = $domTree->createElement('cvn'); + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getCvv())); + + $cvnEl->appendChild($numberEl); + $paymentDataEl->appendChild($cvnEl); + $root->appendChild($paymentDataEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $root->appendChild($payerRefEl); + + $paymentMethodEl = $domTree->createElement('paymentmethod'); + $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); + $root->appendChild($paymentMethodEl); + + $settleEl = $domTree->createElement('autosettle'); + $settleEl->setAttribute('flag', 1); + $root->appendChild($settleEl); + + // 3D Secure section + $mpiEl = $domTree->createElement('mpi'); + $cavvEl = $domTree->createElement('cavv'); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $xidEl = $domTree->createElement('xid'); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $eciEl = $domTree->createElement('eci'); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); + $mpiEl->appendChild($cavvEl); + $mpiEl->appendChild($xidEl); + $mpiEl->appendChild($eciEl); + $root->appendChild($mpiEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $tssEl = $domTree->createElement('tssinfo'); + $addressEl = $domTree->createElement('address'); + $addressEl->setAttribute('type', 'billing'); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + $tssEl->appendChild($addressEl); + $root->appendChild($tssEl); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new AuthResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/UpdateCardRequest.php b/src/Omnipay/Realex/Message/UpdateCardRequest.php index 86db8bf..b4f5fd8 100644 --- a/src/Omnipay/Realex/Message/UpdateCardRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCardRequest.php @@ -7,104 +7,109 @@ namespace Omnipay\Realex\Message; -class UpdateCardRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-update-card'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $cardEl = $domTree->createElement('card'); - - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); - - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($numberEl); - - $expDateEl = $domTree->createElement('expdate'); - $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expDateEl); - - $chNameEl = $domTree->createElement('chname'); - $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($chNameEl); - - $typeEl = $domTree->createElement('type'); - $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($typeEl); - - $issueNoEl = $domTree->createElement('issueno'); - $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueNoEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new UpdateCardResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } - +class UpdateCardRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-update-card'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $cardEl = $domTree->createElement('card'); + + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); + + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($numberEl); + + $expDateEl = $domTree->createElement('expdate'); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expDateEl); + + $chNameEl = $domTree->createElement('chname'); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($chNameEl); + + $typeEl = $domTree->createElement('type'); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($typeEl); + + $issueNoEl = $domTree->createElement('issueno'); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueNoEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new UpdateCardResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/UpdateCardResponse.php b/src/Omnipay/Realex/Message/UpdateCardResponse.php index 6343df9..dd0a562 100644 --- a/src/Omnipay/Realex/Message/UpdateCardResponse.php +++ b/src/Omnipay/Realex/Message/UpdateCardResponse.php @@ -7,33 +7,38 @@ namespace Omnipay\Realex\Message; -class UpdateCardResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class UpdateCardResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php index 740521d..2cd75b3 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php @@ -7,132 +7,137 @@ namespace Omnipay\Realex\Message; -class UpdateCustomerRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); +class UpdateCustomerRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'payer-edit'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $payerEl = $domTree->createElement('payer'); + $payerEl->setAttribute('type', 'Business'); + $payerEl->setAttribute('ref', $payerRef); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $titleEl = $domTree->createElement('title'); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); + $payerEl->appendChild($titleEl); + + $firstnameEl = $domTree->createElement('firstname'); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); + $payerEl->appendChild($firstnameEl); + + $lastnameEl = $domTree->createElement('surname'); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); + $payerEl->appendChild($lastnameEl); + + $companyEl = $domTree->createElement('company'); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); + $payerEl->appendChild($companyEl); + + $addressEl = $domTree->createElement('address'); + + $line1El = $domTree->createElement('line1'); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); + $addressEl->appendChild($line1El); + + $line2El = $domTree->createElement('line2'); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); + $addressEl->appendChild($line2El); + + $cityEl = $domTree->createElement('city'); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); + $addressEl->appendChild($cityEl); + + $countyEl = $domTree->createElement('county'); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); + $addressEl->appendChild($countyEl); + + $postcodeEl = $domTree->createElement('postcode'); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); + $addressEl->appendChild($postcodeEl); + + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + + $payerEl->appendChild($addressEl); + + $phonenumbersEl = $domTree->createElement('phonenumbers'); + $homeEl = $domTree->createElement('home'); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); + $phonenumbersEl->appendChild($homeEl); + $payerEl->appendChild($phonenumbersEl); + + $emailEl = $domTree->createElement('email'); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); + $payerEl->appendChild($emailEl); + + $root->appendChild($payerEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); + protected function createResponse($data) + { + return $this->response = new UpdateCustomerResponse($this, $data); + } - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'payer-edit'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $payerEl = $domTree->createElement('payer'); - $payerEl->setAttribute('type', 'Business'); - $payerEl->setAttribute('ref', $payerRef); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $titleEl = $domTree->createElement('title'); - $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); - $payerEl->appendChild($titleEl); - - $firstnameEl = $domTree->createElement('firstname'); - $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); - $payerEl->appendChild($firstnameEl); - - $lastnameEl = $domTree->createElement('surname'); - $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); - $payerEl->appendChild($lastnameEl); - - $companyEl = $domTree->createElement('company'); - $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); - $payerEl->appendChild($companyEl); - - $addressEl = $domTree->createElement('address'); - - $line1El = $domTree->createElement('line1'); - $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); - $addressEl->appendChild($line1El); - - $line2El = $domTree->createElement('line2'); - $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); - $addressEl->appendChild($line2El); - - $cityEl = $domTree->createElement('city'); - $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); - $addressEl->appendChild($cityEl); - - $countyEl = $domTree->createElement('county'); - $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); - $addressEl->appendChild($countyEl); - - $postcodeEl = $domTree->createElement('postcode'); - $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); - $addressEl->appendChild($postcodeEl); - - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - - $payerEl->appendChild($addressEl); - - $phonenumbersEl = $domTree->createElement('phonenumbers'); - $homeEl = $domTree->createElement('home'); - $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); - $phonenumbersEl->appendChild($homeEl); - $payerEl->appendChild($phonenumbersEl); - - $emailEl = $domTree->createElement('email'); - $emailEl->appendChild($domTree->createTextNode($card->getEmail())); - $payerEl->appendChild($emailEl); - - $root->appendChild($payerEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new UpdateCustomerResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } + public function getEndpoint() + { + return $this->getParameter('SecureDataVaultEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/UpdateCustomerResponse.php b/src/Omnipay/Realex/Message/UpdateCustomerResponse.php index 71594b4..34a583e 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerResponse.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerResponse.php @@ -7,33 +7,38 @@ namespace Omnipay\Realex\Message; -class UpdateCustomerResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class UpdateCustomerResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/VerifySigRequest.php b/src/Omnipay/Realex/Message/VerifySigRequest.php index 5ee1d7b..33a0241 100644 --- a/src/Omnipay/Realex/Message/VerifySigRequest.php +++ b/src/Omnipay/Realex/Message/VerifySigRequest.php @@ -9,164 +9,170 @@ /** * Realex Complete Auth Request */ -class VerifySigRequest extends RemoteAbstractRequest { - - /** - * Decode our previously-encoded Merchant Data - * - * @param string $data - * @return array - */ - protected function decodeMerchantData($data) { - $json = base64_decode($data); - $cardData = (array) json_decode($json); - - return $cardData; - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - /** - * Data will be sent from the 3D Secure provider in two fields: MD and ParRes. - * MD contains our original data (encoded by us) and PaRes will be sent to the gateway. - */ - $returnedData = $this->decodeMerchantData($this->httpRequest->request->get('MD', '')); - - $this->setTransactionId($returnedData['transactionId']); - $this->setAmount($returnedData['amount']); - $this->setCurrency($returnedData['currency']); - $this->setCard(new CreditCard($returnedData)); - - $paRes = $this->httpRequest->request->get('PaRes', ''); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', '3ds-verifysig'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $root->appendChild($cardEl); - - $paResEl = $domTree->createElement('pares'); - $paResEl->appendChild($domTree->createTextNode($paRes)); - $root->appendChild($paResEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new VerifySigResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('authEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('authEndpoint', $value); - } - - /** - * @param mixed $parameters - * - * @return AuthResponse|VerifySigResponse - */ - public function sendData($parameters) { - /** - * @var VerifySigResponse $response - */ - $response = parent::sendData($parameters); - - if ($response->isSuccessful()) { - // a few additional parameters that need to be passed for 3D-Secure transactions - $parameters = $this->getParameters(); - $parameters['cavv'] = $response->getParam('cavv'); - $parameters['eci'] = $response->getParam('eci'); - $parameters['xid'] = $response->getParam('xid'); - - /** - * Now finally, do our authorisation - * - * @var AuthRequest $request - * @var AuthResponse $response - */ - $request = new AuthRequest($this->httpClient, $this->httpRequest); - $request->initialize($parameters); - - $response = $request->send(); - } - - return $response; - } - +class VerifySigRequest extends RemoteAbstractRequest +{ + + /** + * Decode our previously-encoded Merchant Data + * + * @param string $data + * @return array + */ + protected function decodeMerchantData($data) + { + $json = base64_decode($data); + $cardData = (array) json_decode($json); + + return $cardData; + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + /** + * Data will be sent from the 3D Secure provider in two fields: MD and ParRes. + * MD contains our original data (encoded by us) and PaRes will be sent to the gateway. + */ + $returnedData = $this->decodeMerchantData($this->httpRequest->request->get('MD', '')); + + $this->setTransactionId($returnedData['transactionId']); + $this->setAmount($returnedData['amount']); + $this->setCurrency($returnedData['currency']); + $this->setCard(new CreditCard($returnedData)); + + $paRes = $this->httpRequest->request->get('PaRes', ''); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', '3ds-verifysig'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $root->appendChild($cardEl); + + $paResEl = $domTree->createElement('pares'); + $paResEl->appendChild($domTree->createTextNode($paRes)); + $root->appendChild($paResEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new VerifySigResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('authEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('authEndpoint', $value); + } + + /** + * @param mixed $parameters + * + * @return AuthResponse|VerifySigResponse + */ + public function sendData($parameters) + { + /** + * @var VerifySigResponse $response + */ + $response = parent::sendData($parameters); + + if ($response->isSuccessful()) { + // a few additional parameters that need to be passed for 3D-Secure transactions + $parameters = $this->getParameters(); + $parameters['cavv'] = $response->getParam('cavv'); + $parameters['eci'] = $response->getParam('eci'); + $parameters['xid'] = $response->getParam('xid'); + + /** + * Now finally, do our authorisation + * + * @var AuthRequest $request + * @var AuthResponse $response + */ + $request = new AuthRequest($this->httpClient, $this->httpRequest); + $request->initialize($parameters); + + $response = $request->send(); + } + + return $response; + } } diff --git a/src/Omnipay/Realex/Message/VerifySigResponse.php b/src/Omnipay/Realex/Message/VerifySigResponse.php index febbb3a..e9905fc 100644 --- a/src/Omnipay/Realex/Message/VerifySigResponse.php +++ b/src/Omnipay/Realex/Message/VerifySigResponse.php @@ -10,75 +10,83 @@ /** * Realex Verify 3D Secure signature Response */ -class VerifySigResponse extends RemoteAbstractResponse implements RedirectResponseInterface { +class VerifySigResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + /** + * The 3D secure result is only counted as successful if is: + * - legitimate - (result = 00) + * - card holder correctly entered their password, or the 3DS systems are unavailable at the moment + */ + return ($this->xml->result == '00' && $this->xml->threedsecure->status != 'N'); + } - public function isSuccessful() { - /** - * The 3D secure result is only counted as successful if is: - * - legitimate - (result = 00) - * - card holder correctly entered their password, or the 3DS systems are unavailable at the moment - */ - return ($this->xml->result == '00' && $this->xml->threedsecure->status != 'N'); - } + /** + * Find the value of a named XML element in the response + * + * @param string $key + * @return string + */ + public function getParam($key) + { + $matches = $this->xml->xpath('//' . $key); + if (!empty($matches)) { + $value = (string) $matches[0]; + } else { + $value = ''; + } - /** - * Find the value of a named XML element in the response - * - * @param string $key - * @return string - */ - public function getParam($key) { - $matches = $this->xml->xpath('//' . $key); - if (!empty($matches)) { - $value = (string) $matches[0]; - } else { - $value = ''; - } + return $value; + } - return $value; - } + public function getMessage() + { + /** + * For some reason, the default message from the gateway + * says "Authentication Successful", even if the customer + * was shown to have used an incorrect password. For sane + * front-end reporting, let's override this. + */ + if ($this->xml->threedsecure->status == 'N') { + $message = '3D Secure Authentication Unsuccessful'; + } else { + $message = (string) $this->xml->message; + } - public function getMessage() { - /** - * For some reason, the default message from the gateway - * says "Authentication Successful", even if the customer - * was shown to have used an incorrect password. For sane - * front-end reporting, let's override this. - */ - if ($this->xml->threedsecure->status == 'N') { - $message = '3D Secure Authentication Unsuccessful'; - } else { - $message = (string) $this->xml->message; - } + return $message; + } - return $message; - } + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } + public function getTransactionReference() + { + return ($this->xml->pasref) ? $this->xml->pasref : null; + } - public function getTransactionReference() { - return ($this->xml->pasref) ? $this->xml->pasref : null; - } + public function isRedirect() + { + return false; + } - public function isRedirect() { - return false; - } + public function getRedirectMethod() + { + return 'GET'; + } - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } + public function getRedirectData() + { + return null; + } + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/VoidRequest.php b/src/Omnipay/Realex/Message/VoidRequest.php index daec5fc..cb13010 100644 --- a/src/Omnipay/Realex/Message/VoidRequest.php +++ b/src/Omnipay/Realex/Message/VoidRequest.php @@ -7,98 +7,105 @@ /** * Realex Void Request */ -class VoidRequest extends RemoteAbstractRequest { - - public function getTransactionReference() { - return $this->getParameter('pasRef'); - } - - public function setTransactionReference($value) { - return $this->setParameter('pasRef', $value); - } - - public function getAuthCode() { - return $this->getParameter('authCode'); - } - - public function setAuthCode($value) { - return $this->setParameter('authCode', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - // No amount, currency or card number for rebate requests but still needs to be in hash - $amount = ''; - $currency = ''; - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'void'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // original order ID - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($orderIdEl); - - // pasref returned for original transaction - $pasRefEl = $domTree->createElement('pasref'); - $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); - $root->appendChild($pasRefEl); - - // authcode returned for original transaction - $authCodeEl = $domTree->createElement('authcode'); - $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); - $root->appendChild($authCodeEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new VoidResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } - +class VoidRequest extends RemoteAbstractRequest +{ + public function getTransactionReference() + { + return $this->getParameter('pasRef'); + } + + public function setTransactionReference($value) + { + return $this->setParameter('pasRef', $value); + } + + public function getAuthCode() + { + return $this->getParameter('authCode'); + } + + public function setAuthCode($value) + { + return $this->setParameter('authCode', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + // No amount, currency or card number for rebate requests but still needs to be in hash + $amount = ''; + $currency = ''; + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'void'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // original order ID + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($orderIdEl); + + // pasref returned for original transaction + $pasRefEl = $domTree->createElement('pasref'); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); + $root->appendChild($pasRefEl); + + // authcode returned for original transaction + $authCodeEl = $domTree->createElement('authcode'); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); + $root->appendChild($authCodeEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new VoidResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/VoidResponse.php b/src/Omnipay/Realex/Message/VoidResponse.php index 1b3bbb2..7c8120d 100644 --- a/src/Omnipay/Realex/Message/VoidResponse.php +++ b/src/Omnipay/Realex/Message/VoidResponse.php @@ -10,45 +10,53 @@ /** * Realex Void Response */ -class VoidResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } - - public function getTransactionReference() { - return ($this->xml->pasref) ? (string) $this->xml->pasref : null; - } - - public function getAuthCode() { - return ($this->xml->authcode) ? (string) $this->xml->authcode : null; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class VoidResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() + { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() + { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/RedirectGateway.php b/src/Omnipay/Realex/RedirectGateway.php index 4fd2afc..bddba27 100644 --- a/src/Omnipay/Realex/RedirectGateway.php +++ b/src/Omnipay/Realex/RedirectGateway.php @@ -7,76 +7,91 @@ /** * Realex Redirect Class */ -class RedirectGateway extends AbstractGateway { - - public function getName() { - return 'Realex Redirect'; - } - - public function getDefaultParameters() { - return array( - 'merchantId' => '', - 'secret' => '', - 'account' => 'internet', - 'testMode' => false, - 'checkoutEndpoint' => 'https://hpp.realexpayments.com/pay', - ); - } - - public function getMerchantId() { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) { - return $this->setParameter('merchantId', $value); - } - - public function getSecret() { - return $this->getParameter('secret'); - } - - public function setSecret($value) { - return $this->setParameter('secret', $value); - } - - public function getAccount() { - return $this->getParameter('account'); - } - - public function setAccount($value) { - return $this->setParameter('account', $value); - } - - public function getCheckoutEndpoint() { - return $this->getParameter('checkoutEndpoint'); - } - - public function setCheckoutEndpoint($value) { - return $this->setParameter('checkoutEndpoint', $value); - } - - public function authorize(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectAuthorizeRequest', $parameters); - } - - public function completeAuthorize(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteAuthorizeRequest', $parameters); - } - - public function purchase(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectPurchaseRequest', $parameters); - } - - public function completePurchase(array $parameters = array()) { - return $this->completeAuthorize($parameters); - } - - public function storeCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectStoreCardRequest', $parameters); - } - - public function completeStoreCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteStoreCardRequest', $parameters); - } - +class RedirectGateway extends AbstractGateway +{ + public function getName() + { + return 'Realex Redirect'; + } + + public function getDefaultParameters() + { + return array( + 'merchantId' => '', + 'secret' => '', + 'account' => 'internet', + 'testMode' => false, + 'checkoutEndpoint' => 'https://hpp.realexpayments.com/pay', + ); + } + + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getCheckoutEndpoint() + { + return $this->getParameter('checkoutEndpoint'); + } + + public function setCheckoutEndpoint($value) + { + return $this->setParameter('checkoutEndpoint', $value); + } + + public function authorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectAuthorizeRequest', $parameters); + } + + public function completeAuthorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteAuthorizeRequest', $parameters); + } + + public function purchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectPurchaseRequest', $parameters); + } + + public function completePurchase(array $parameters = array()) + { + return $this->completeAuthorize($parameters); + } + + public function storeCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectStoreCardRequest', $parameters); + } + + public function completeStoreCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteStoreCardRequest', $parameters); + } } diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index 138520c..f5453bb 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -12,152 +12,178 @@ /** * Realex Remote Gateway */ -class RemoteGateway extends AbstractGateway { - - public function getName() { - return 'Realex Remote'; - } - - public function getDefaultParameters() { - return array( - 'merchantId' => '', - 'account' => '', - 'secret' => '', - '3dSecure' => 0, - 'authEndpoint' => 'https://epage.payandshop.com/epage-remote.cgi', - 'secureDataVaultEndpoint' => 'https://epage.payandshop.com/epage-remote-plugins.cgi', - '3dSecureEndpoint' => 'https://epage.payandshop.com/epage-3dsecure.cgi' - ); - } - - public function getMerchantId() { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) { - return $this->setParameter('merchantId', $value); - } - - public function getAccount() { - return $this->getParameter('account'); - } - - public function setAccount($value) { - return $this->setParameter('account', $value); - } - - public function getSecret() { - return $this->getParameter('secret'); - } - - public function setSecret($value) { - return $this->setParameter('secret', $value); - } - - public function getRefundPassword() { - return $this->getParameter('refundPassword'); - } - - /** - * Although Omnipay terminology deals with 'refunds', you need - * to actually supply the 'rebate' password that Realex gives you - * in order for this to work. - * - * @param string $value The 'rebate' password supplied by Realex - * - * @return $this - */ - public function setRefundPassword($value) { - return $this->setParameter('refundPassword', $value); - } - - public function get3dSecure() { - return $this->getParameter('3dSecure'); - } - - public function set3dSecure($value) { - return $this->setParameter('3dSecure', $value); - } - - public function purchase(array $parameters = array()) { - - if (array_key_exists('cardReference', $parameters)) { - return $this->createRequest('\Omnipay\Realex\Message\SavedAuthRequest', $parameters); - } elseif ($this->get3dSecure()) { - return $this->createRequest('\Omnipay\Realex\Message\EnrolmentRequest', $parameters); - } else { - return $this->createRequest('\Omnipay\Realex\Message\AuthRequest', $parameters); - } - } - - /** - * This will always be called as the result of returning from 3D Secure. - * Verify that the 3D Secure message we've received is legit - */ - public function completePurchase(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\VerifySigRequest', $parameters); - } - - public function refund(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\RefundRequest', $parameters); - } - - public function void(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\VoidRequest', $parameters); - } - - public function fetchTransaction(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\FetchTransactionRequest', $parameters); - } - - /** - * Create/update/delete card/customer details - */ - public function createCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\CreateCardRequest', $parameters); - } - - public function updateCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\UpdateCardRequest', $parameters); - } - - public function deleteCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\DeleteCardRequest', $parameters); - } - - public function createCustomer(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\CreateCustomerRequest', $parameters); - } - - public function updateCustomer(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\UpdateCustomerRequest', $parameters); - } - - /** - * Setup service endpoint links for different realex service providers - */ - public function setAuthEndpoint($value) { - return $this->setParameter('authEndpoint', $value); - } - - public function getAuthEndpoint() { - return $this->getParameter('authEndpoint'); - } - - public function setSecureDataVaultEndpoint($value) { - return $this->setParameter('secureDataVaultEndpoint', $value); - } - - public function getSecureDataVaultEndpoint() { - return $this->getParameter('secureDataVaultEndpoint'); - } - - public function set3DSecureEndpoint($value) { - return $this->setParameter('3dSecureEndpoint', $value); - } - - public function get3DSecureEndpoint() { - return $this->getParameter('3dSecureEndpoint'); - } - +class RemoteGateway extends AbstractGateway +{ + public function getName() + { + return 'Realex Remote'; + } + + public function getDefaultParameters() + { + return array( + 'merchantId' => '', + 'account' => '', + 'secret' => '', + '3dSecure' => 0, + 'authEndpoint' => 'https://epage.payandshop.com/epage-remote.cgi', + 'secureDataVaultEndpoint' => 'https://epage.payandshop.com/epage-remote-plugins.cgi', + '3dSecureEndpoint' => 'https://epage.payandshop.com/epage-3dsecure.cgi' + ); + } + + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getRefundPassword() + { + return $this->getParameter('refundPassword'); + } + + /** + * Although Omnipay terminology deals with 'refunds', you need + * to actually supply the 'rebate' password that Realex gives you + * in order for this to work. + * + * @param string $value The 'rebate' password supplied by Realex + * + * @return $this + */ + public function setRefundPassword($value) + { + return $this->setParameter('refundPassword', $value); + } + + public function get3dSecure() + { + return $this->getParameter('3dSecure'); + } + + public function set3dSecure($value) + { + return $this->setParameter('3dSecure', $value); + } + + public function purchase(array $parameters = array()) + { + if (array_key_exists('cardReference', $parameters)) { + return $this->createRequest('\Omnipay\Realex\Message\SavedAuthRequest', $parameters); + } elseif ($this->get3dSecure()) { + return $this->createRequest('\Omnipay\Realex\Message\EnrolmentRequest', $parameters); + } else { + return $this->createRequest('\Omnipay\Realex\Message\AuthRequest', $parameters); + } + } + + /** + * This will always be called as the result of returning from 3D Secure. + * Verify that the 3D Secure message we've received is legit + */ + public function completePurchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\VerifySigRequest', $parameters); + } + + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\RefundRequest', $parameters); + } + + public function void(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\VoidRequest', $parameters); + } + + public function fetchTransaction(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\FetchTransactionRequest', $parameters); + } + + /** + * Create/update/delete card/customer details + */ + public function createCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\CreateCardRequest', $parameters); + } + + public function updateCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\UpdateCardRequest', $parameters); + } + + public function deleteCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\DeleteCardRequest', $parameters); + } + + public function createCustomer(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\CreateCustomerRequest', $parameters); + } + + public function updateCustomer(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\UpdateCustomerRequest', $parameters); + } + + /** + * Setup service endpoint links for different realex service providers + */ + public function setAuthEndpoint($value) + { + return $this->setParameter('authEndpoint', $value); + } + + public function getAuthEndpoint() + { + return $this->getParameter('authEndpoint'); + } + + public function setSecureDataVaultEndpoint($value) + { + return $this->setParameter('secureDataVaultEndpoint', $value); + } + + public function getSecureDataVaultEndpoint() + { + return $this->getParameter('secureDataVaultEndpoint'); + } + + public function set3DSecureEndpoint($value) + { + return $this->setParameter('3dSecureEndpoint', $value); + } + + public function get3DSecureEndpoint() + { + return $this->getParameter('3dSecureEndpoint'); + } } From c40724acc51e472d2bac491759d219f74fa253cd Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 11:02:14 +0100 Subject: [PATCH 15/29] Format fix's --- src/Omnipay/Realex/Message/RefundRequest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Omnipay/Realex/Message/RefundRequest.php b/src/Omnipay/Realex/Message/RefundRequest.php index b41a590..d149fb1 100644 --- a/src/Omnipay/Realex/Message/RefundRequest.php +++ b/src/Omnipay/Realex/Message/RefundRequest.php @@ -57,7 +57,12 @@ public function setRefundPassword($value) public function getData() { $this->validate( - 'amount', 'currency', 'originalTransactionId', 'transactionReference', 'authCode', 'refundPassword' + 'amount', + 'currency', + 'originalTransactionId', + 'transactionReference', + 'authCode', + 'refundPassword' ); // Create the hash From dc32d8e07545d21ab721878f14fc8a52f427cdf1 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 11:02:20 +0100 Subject: [PATCH 16/29] more formatting --- src/Omnipay/Realex/Message/Redirect/AbstractRequest.php | 7 ++++++- src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index f12ee85..81b14b8 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -137,7 +137,12 @@ public function createSignature($data, $method = 'sha1', $card = null) return $method($hash . '.' . $this->getSecret()); } - public function getRequestXML($card, $autoSettle = true, $extraData = array(), $addressData = true, $cardData = true) + public function getRequestXML( + $card, + $autoSettle = true, + $extraData = array(), + $addressData = true, + $cardData = true) { $data = $this->getBaseData($autoSettle, $card); $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); diff --git a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php index cd2c537..64d1aac 100644 --- a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php @@ -8,7 +8,7 @@ /** * Realex Response */ -class dataVaultResponse extends AbstractResponse +class DataVaultResponse extends AbstractResponse { public function __construct(RequestInterface $request, $data = array()) { @@ -50,12 +50,14 @@ public function getTransactionReference() public function isPayerSetupSuccessful() { - return !isset($this->data['PAYER_SETUP']) || (isset($this->data['PAYER_SETUP']) && '00' === $this->data['PAYER_SETUP']); + return !isset($this->data['PAYER_SETUP']) || + (isset($this->data['PAYER_SETUP']) && '00' === $this->data['PAYER_SETUP']); } public function isPayerCardAddSuccessful() { - return !isset($this->data['PMT_SETUP']) || (isset($this->data['PMT_SETUP']) && '00' === $this->data['PMT_SETUP']); + return !isset($this->data['PMT_SETUP']) || + (isset($this->data['PMT_SETUP']) && '00' === $this->data['PMT_SETUP']); } public function getCardToken() From 8b929e4e1abda22b654672411a2e58553ea17365 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 11:30:08 +0100 Subject: [PATCH 17/29] formatting issue --- src/Omnipay/Realex/Message/Redirect/AbstractRequest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index 81b14b8..a6e17cc 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -142,7 +142,8 @@ public function getRequestXML( $autoSettle = true, $extraData = array(), $addressData = true, - $cardData = true) + $cardData = true + ) { $data = $this->getBaseData($autoSettle, $card); $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); From 53e342d9d5df931ebd115be0cd1adf9e97445e78 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 11:42:58 +0100 Subject: [PATCH 18/29] formatting --- src/Omnipay/Realex/Message/Redirect/AbstractRequest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index a6e17cc..4885459 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -143,8 +143,7 @@ public function getRequestXML( $extraData = array(), $addressData = true, $cardData = true - ) - { + ) { $data = $this->getBaseData($autoSettle, $card); $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); $request = new \SimpleXMLElement(''); From bad47ad13738438fe33e7f381df90e7805e06af6 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 12:11:41 +0100 Subject: [PATCH 19/29] format issue --- .../Realex/Message/Redirect/AbstractRequest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index 4885459..377c521 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -138,11 +138,11 @@ public function createSignature($data, $method = 'sha1', $card = null) } public function getRequestXML( - $card, - $autoSettle = true, - $extraData = array(), - $addressData = true, - $cardData = true + $card, + $autoSettle = true, + $extraData = array(), + $addressData = true, + $cardData = true ) { $data = $this->getBaseData($autoSettle, $card); $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); From 0802aab09ecd1ab7d867296dff178d9f30a25a2c Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 12:15:38 +0100 Subject: [PATCH 20/29] Multi line format issue --- .../Realex/Message/Redirect/AbstractRequest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index 377c521..6c14a0c 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -137,13 +137,13 @@ public function createSignature($data, $method = 'sha1', $card = null) return $method($hash . '.' . $this->getSecret()); } - public function getRequestXML( - $card, - $autoSettle = true, - $extraData = array(), - $addressData = true, - $cardData = true - ) { + public function getRequestXML( + $card, + $autoSettle = true, + $extraData = array(), + $addressData = true, + $cardData = true + ) { $data = $this->getBaseData($autoSettle, $card); $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); $request = new \SimpleXMLElement(''); From 948b7379f02f9776312189c22dad6fbe6218fa99 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 12:17:34 +0100 Subject: [PATCH 21/29] formatting --- .../Realex/Message/Redirect/AbstractRequest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index 6c14a0c..e467e96 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -137,13 +137,13 @@ public function createSignature($data, $method = 'sha1', $card = null) return $method($hash . '.' . $this->getSecret()); } - public function getRequestXML( - $card, - $autoSettle = true, - $extraData = array(), - $addressData = true, - $cardData = true - ) { + public function getRequestXML( + $card, + $autoSettle = true, + $extraData = array(), + $addressData = true, + $cardData = true + ) { $data = $this->getBaseData($autoSettle, $card); $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); $request = new \SimpleXMLElement(''); From 3b832478a2231e2df64faac50970365bd3099a7f Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 12:29:38 +0100 Subject: [PATCH 22/29] formatting issue --- .../Realex/Message/Redirect/AbstractRequest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index e467e96..85ecb85 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -138,11 +138,11 @@ public function createSignature($data, $method = 'sha1', $card = null) } public function getRequestXML( - $card, - $autoSettle = true, - $extraData = array(), - $addressData = true, - $cardData = true + $card, + $autoSettle = true, + $extraData = array(), + $addressData = true, + $cardData = true ) { $data = $this->getBaseData($autoSettle, $card); $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); From 71ecb9ab519f6d6e0a119c2f87aa6eb7858e9758 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Fri, 16 Jun 2017 12:41:59 +0100 Subject: [PATCH 23/29] formatting last attempt --- .../Realex/Message/Redirect/AbstractRequest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index 85ecb85..e467e96 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -138,11 +138,11 @@ public function createSignature($data, $method = 'sha1', $card = null) } public function getRequestXML( - $card, - $autoSettle = true, - $extraData = array(), - $addressData = true, - $cardData = true + $card, + $autoSettle = true, + $extraData = array(), + $addressData = true, + $cardData = true ) { $data = $this->getBaseData($autoSettle, $card); $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); From d270e3c3415a7de410b72d9017eadda2d3ada314 Mon Sep 17 00:00:00 2001 From: Dean Sanderson Date: Mon, 16 Apr 2018 08:58:04 +0100 Subject: [PATCH 24/29] Code Tidy --- nbproject/project.properties | 7 - nbproject/project.xml | 9 - src/Omnipay/Realex/Message/AuthRequest.php | 335 ++++++++-------- src/Omnipay/Realex/Message/AuthResponse.php | 126 +++--- .../Realex/Message/CreateCardRequest.php | 205 +++++----- .../Realex/Message/CreateCardResponse.php | 72 ++-- .../Realex/Message/CreateCustomerRequest.php | 255 ++++++------ .../Realex/Message/CreateCustomerResponse.php | 63 +-- .../Realex/Message/DeleteCardRequest.php | 141 +++---- .../Realex/Message/DeleteCardResponse.php | 63 +-- .../Realex/Message/EnrolmentRequest.php | 267 +++++++------ .../Realex/Message/EnrolmentResponse.php | 156 ++++---- .../Message/FetchTransactionRequest.php | 140 +++---- .../Message/FetchTransactionResponse.php | 90 +++-- .../Message/Redirect/AbstractRequest.php | 362 ++++++++++-------- .../Redirect/RedirectAuthorizeRequest.php | 26 +- .../Redirect/RedirectAuthorizeResponse.php | 57 +-- .../RedirectCompleteAuthorizeRequest.php | 53 +-- .../RedirectCompleteStoreCardRequest.php | 64 ++-- .../Redirect/RedirectDataVaultRequest.php | 106 ++--- .../Redirect/RedirectDataVaultResponse.php | 59 +-- .../Redirect/RedirectPurchaseRequest.php | 12 +- .../Redirect/RedirectPurchaseResponse.php | 12 +- .../Redirect/RedirectStoreCardRequest.php | 170 ++++---- .../Redirect/RedirectStoreCardResponse.php | 14 +- .../Message/Redirect/dataVaultResponse.php | 102 ++--- .../Realex/Message/Redirect/response.php | 41 +- src/Omnipay/Realex/Message/RefundRequest.php | 264 +++++++------ src/Omnipay/Realex/Message/RefundResponse.php | 90 +++-- .../Realex/Message/RemoteAbstractRequest.php | 152 ++++---- .../Realex/Message/RemoteAbstractResponse.php | 49 +-- .../Realex/Message/SavedAuthRequest.php | 315 +++++++-------- .../Realex/Message/UpdateCardRequest.php | 205 +++++----- .../Realex/Message/UpdateCardResponse.php | 63 +-- .../Realex/Message/UpdateCustomerRequest.php | 255 ++++++------ .../Realex/Message/UpdateCustomerResponse.php | 63 +-- .../Realex/Message/VerifySigRequest.php | 326 ++++++++-------- .../Realex/Message/VerifySigResponse.php | 130 ++++--- src/Omnipay/Realex/Message/VoidRequest.php | 195 +++++----- src/Omnipay/Realex/Message/VoidResponse.php | 90 +++-- src/Omnipay/Realex/RedirectGateway.php | 159 ++++---- src/Omnipay/Realex/RemoteGateway.php | 322 +++++++++------- 42 files changed, 2972 insertions(+), 2713 deletions(-) delete mode 100644 nbproject/project.properties delete mode 100644 nbproject/project.xml diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index 76f6f91..0000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,7 +0,0 @@ -include.path=${php.global.include.path} -php.version=PHP_56 -source.encoding=UTF-8 -src.dir=. -tags.asp=false -tags.short=false -web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index 9db1515..0000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - org.netbeans.modules.php.project - - - omnipay-realex - - - diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index 8391142..5213693 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -8,167 +8,176 @@ /** * Realex Auth Request */ -class AuthRequest extends RemoteAbstractRequest { - - public function getCavv() { - return $this->getParameter('cavv'); - } - - public function setCavv($value) { - return $this->setParameter('cavv', $value); - } - - public function getEci() { - return $this->getParameter('eci'); - } - - public function setEci($value) { - return $this->setParameter('eci', $value); - } - - public function getXid() { - return $this->getParameter('xid'); - } - - public function setXid($value) { - return $this->setParameter('xid', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'auth'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $cvnEl = $domTree->createElement('cvn'); - - $cvnNumberEl = $domTree->createElement('number'); - $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); - $cvnEl->appendChild($cvnNumberEl); - - $presIndEl = $domTree->createElement('presind', 1); - $cvnEl->appendChild($presIndEl); - - $cardEl->appendChild($cvnEl); - - $issueEl = $domTree->createElement('issueno'); - $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueEl); - - $root->appendChild($cardEl); - - $settleEl = $domTree->createElement('autosettle'); - $settleEl->setAttribute('flag', 1); - $root->appendChild($settleEl); - - // 3D Secure section - $mpiEl = $domTree->createElement('mpi'); - $cavvEl = $domTree->createElement('cavv'); - $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); - $xidEl = $domTree->createElement('xid'); - $xidEl->appendChild($domTree->createTextNode($this->getXid())); - $eciEl = $domTree->createElement('eci'); - $eciEl->appendChild($domTree->createTextNode($this->getEci())); - $mpiEl->appendChild($cavvEl); - $mpiEl->appendChild($xidEl); - $mpiEl->appendChild($eciEl); - $root->appendChild($mpiEl); - - $sha1El = $domTree->createElement('sha1hash', $sha1hash); - $root->appendChild($sha1El); - - $tssEl = $domTree->createElement('tssinfo'); - $addressEl = $domTree->createElement('address'); - $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - $tssEl->appendChild($addressEl); - $root->appendChild($tssEl); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new AuthResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } - +class AuthRequest extends RemoteAbstractRequest +{ + public function getCavv() + { + return $this->getParameter('cavv'); + } + + public function setCavv($value) + { + return $this->setParameter('cavv', $value); + } + + public function getEci() + { + return $this->getParameter('eci'); + } + + public function setEci($value) + { + return $this->setParameter('eci', $value); + } + + public function getXid() + { + return $this->getParameter('xid'); + } + + public function setXid($value) + { + return $this->setParameter('xid', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'auth'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $cvnEl = $domTree->createElement('cvn'); + + $cvnNumberEl = $domTree->createElement('number'); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); + $cvnEl->appendChild($cvnNumberEl); + + $presIndEl = $domTree->createElement('presind', 1); + $cvnEl->appendChild($presIndEl); + + $cardEl->appendChild($cvnEl); + + $issueEl = $domTree->createElement('issueno'); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueEl); + + $root->appendChild($cardEl); + + $settleEl = $domTree->createElement('autosettle'); + $settleEl->setAttribute('flag', 1); + $root->appendChild($settleEl); + + // 3D Secure section + $mpiEl = $domTree->createElement('mpi'); + $cavvEl = $domTree->createElement('cavv'); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $xidEl = $domTree->createElement('xid'); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $eciEl = $domTree->createElement('eci'); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); + $mpiEl->appendChild($cavvEl); + $mpiEl->appendChild($xidEl); + $mpiEl->appendChild($eciEl); + $root->appendChild($mpiEl); + + $sha1El = $domTree->createElement('sha1hash', $sha1hash); + $root->appendChild($sha1El); + + $tssEl = $domTree->createElement('tssinfo'); + $addressEl = $domTree->createElement('address'); + $addressEl->setAttribute('type', 'billing'); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + $tssEl->appendChild($addressEl); + $root->appendChild($tssEl); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new AuthResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/AuthResponse.php b/src/Omnipay/Realex/Message/AuthResponse.php index d0d735e..77b97fa 100644 --- a/src/Omnipay/Realex/Message/AuthResponse.php +++ b/src/Omnipay/Realex/Message/AuthResponse.php @@ -10,61 +10,73 @@ /** * Realex Auth Response */ -class AuthResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function isDecline() { - return (substr($this->xml->result, 0, 1) == '1'); - } - - public function isBankSystemError() { - return (substr($this->xml->result, 0, 1) == '2'); - } - - public function isRealexSystemError() { - return (substr($this->xml->result, 0, 1) == '3'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } - - public function getTransactionReference() { - return ($this->xml->pasref) ? (string) $this->xml->pasref : null; - } - - public function getAuthCode() { - return ($this->xml->authcode) ? (string) $this->xml->authcode : null; - } - - public function getBatchId() { - return ($this->xml->batchid) ? (string) $this->xml->batchid : null; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class AuthResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function isDecline() + { + return (substr($this->xml->result, 0, 1) == '1'); + } + + public function isBankSystemError() + { + return (substr($this->xml->result, 0, 1) == '2'); + } + + public function isRealexSystemError() + { + return (substr($this->xml->result, 0, 1) == '3'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() + { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() + { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function getBatchId() + { + return ($this->xml->batchid) ? (string) $this->xml->batchid : null; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/CreateCardRequest.php b/src/Omnipay/Realex/Message/CreateCardRequest.php index 98f1b82..75709ac 100644 --- a/src/Omnipay/Realex/Message/CreateCardRequest.php +++ b/src/Omnipay/Realex/Message/CreateCardRequest.php @@ -7,104 +7,109 @@ namespace Omnipay\Realex\Message; -class CreateCardRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-new'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $cardEl = $domTree->createElement('card'); - - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); - - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($numberEl); - - $expDateEl = $domTree->createElement('expdate'); - $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expDateEl); - - $chNameEl = $domTree->createElement('chname'); - $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($chNameEl); - - $typeEl = $domTree->createElement('type'); - $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($typeEl); - - $issueNoEl = $domTree->createElement('issueno'); - $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueNoEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new CreateCardResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } - +class CreateCardRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-new'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $cardEl = $domTree->createElement('card'); + + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); + + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($numberEl); + + $expDateEl = $domTree->createElement('expdate'); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expDateEl); + + $chNameEl = $domTree->createElement('chname'); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($chNameEl); + + $typeEl = $domTree->createElement('type'); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($typeEl); + + $issueNoEl = $domTree->createElement('issueno'); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueNoEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new CreateCardResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/CreateCardResponse.php b/src/Omnipay/Realex/Message/CreateCardResponse.php index cdba215..9c646c0 100644 --- a/src/Omnipay/Realex/Message/CreateCardResponse.php +++ b/src/Omnipay/Realex/Message/CreateCardResponse.php @@ -7,37 +7,43 @@ namespace Omnipay\Realex\Message; -class CreateCardResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function customerDoesntExist() { - return ($this->xml->result == '520'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class CreateCardResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function customerDoesntExist() + { + return ($this->xml->result == '520'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/CreateCustomerRequest.php b/src/Omnipay/Realex/Message/CreateCustomerRequest.php index 427c9d3..84522cd 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/CreateCustomerRequest.php @@ -7,132 +7,137 @@ namespace Omnipay\Realex\Message; -class CreateCustomerRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); +class CreateCustomerRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'payer-new'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $payerEl = $domTree->createElement('payer'); + $payerEl->setAttribute('type', 'Business'); + $payerEl->setAttribute('ref', $payerRef); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $titleEl = $domTree->createElement('title'); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); + $payerEl->appendChild($titleEl); + + $firstnameEl = $domTree->createElement('firstname'); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); + $payerEl->appendChild($firstnameEl); + + $lastnameEl = $domTree->createElement('surname'); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); + $payerEl->appendChild($lastnameEl); + + $companyEl = $domTree->createElement('company'); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); + $payerEl->appendChild($companyEl); + + $addressEl = $domTree->createElement('address'); + + $line1El = $domTree->createElement('line1'); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); + $addressEl->appendChild($line1El); + + $line2El = $domTree->createElement('line2'); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); + $addressEl->appendChild($line2El); + + $cityEl = $domTree->createElement('city'); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); + $addressEl->appendChild($cityEl); + + $countyEl = $domTree->createElement('county'); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); + $addressEl->appendChild($countyEl); + + $postcodeEl = $domTree->createElement('postcode'); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); + $addressEl->appendChild($postcodeEl); + + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + + $payerEl->appendChild($addressEl); + + $phonenumbersEl = $domTree->createElement('phonenumbers'); + $homeEl = $domTree->createElement('home'); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); + $phonenumbersEl->appendChild($homeEl); + $payerEl->appendChild($phonenumbersEl); + + $emailEl = $domTree->createElement('email'); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); + $payerEl->appendChild($emailEl); + + $root->appendChild($payerEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); + protected function createResponse($data) + { + return $this->response = new CreateCustomerResponse($this, $data); + } - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'payer-new'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $payerEl = $domTree->createElement('payer'); - $payerEl->setAttribute('type', 'Business'); - $payerEl->setAttribute('ref', $payerRef); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $titleEl = $domTree->createElement('title'); - $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); - $payerEl->appendChild($titleEl); - - $firstnameEl = $domTree->createElement('firstname'); - $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); - $payerEl->appendChild($firstnameEl); - - $lastnameEl = $domTree->createElement('surname'); - $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); - $payerEl->appendChild($lastnameEl); - - $companyEl = $domTree->createElement('company'); - $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); - $payerEl->appendChild($companyEl); - - $addressEl = $domTree->createElement('address'); - - $line1El = $domTree->createElement('line1'); - $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); - $addressEl->appendChild($line1El); - - $line2El = $domTree->createElement('line2'); - $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); - $addressEl->appendChild($line2El); - - $cityEl = $domTree->createElement('city'); - $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); - $addressEl->appendChild($cityEl); - - $countyEl = $domTree->createElement('county'); - $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); - $addressEl->appendChild($countyEl); - - $postcodeEl = $domTree->createElement('postcode'); - $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); - $addressEl->appendChild($postcodeEl); - - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - - $payerEl->appendChild($addressEl); - - $phonenumbersEl = $domTree->createElement('phonenumbers'); - $homeEl = $domTree->createElement('home'); - $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); - $phonenumbersEl->appendChild($homeEl); - $payerEl->appendChild($phonenumbersEl); - - $emailEl = $domTree->createElement('email'); - $emailEl->appendChild($domTree->createTextNode($card->getEmail())); - $payerEl->appendChild($emailEl); - - $root->appendChild($payerEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new CreateCustomerResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/CreateCustomerResponse.php b/src/Omnipay/Realex/Message/CreateCustomerResponse.php index 7ae2a03..420f0f7 100644 --- a/src/Omnipay/Realex/Message/CreateCustomerResponse.php +++ b/src/Omnipay/Realex/Message/CreateCustomerResponse.php @@ -7,33 +7,38 @@ namespace Omnipay\Realex\Message; -class CreateCustomerResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class CreateCustomerResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/DeleteCardRequest.php b/src/Omnipay/Realex/Message/DeleteCardRequest.php index 3ba7b64..ee3b0be 100644 --- a/src/Omnipay/Realex/Message/DeleteCardRequest.php +++ b/src/Omnipay/Realex/Message/DeleteCardRequest.php @@ -7,72 +7,77 @@ namespace Omnipay\Realex\Message; -class DeleteCardRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - $tmp = "$timestamp.$merchantId.$payerRef.{$this->getCardReference()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-cancel-card'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - $cardEl = $domTree->createElement('card'); - - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new DeleteCardResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } - +class DeleteCardRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + $tmp = "$timestamp.$merchantId.$payerRef.{$this->getCardReference()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-cancel-card'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + $cardEl = $domTree->createElement('card'); + + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new DeleteCardResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/DeleteCardResponse.php b/src/Omnipay/Realex/Message/DeleteCardResponse.php index 705d5cd..a2241e5 100644 --- a/src/Omnipay/Realex/Message/DeleteCardResponse.php +++ b/src/Omnipay/Realex/Message/DeleteCardResponse.php @@ -7,33 +7,38 @@ namespace Omnipay\Realex\Message; -class DeleteCardResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class DeleteCardResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/EnrolmentRequest.php b/src/Omnipay/Realex/Message/EnrolmentRequest.php index 01445bb..17e8b61 100644 --- a/src/Omnipay/Realex/Message/EnrolmentRequest.php +++ b/src/Omnipay/Realex/Message/EnrolmentRequest.php @@ -7,141 +7,136 @@ /** * Realex 3D Secure enrolment request */ -class EnrolmentRequest extends RemoteAbstractRequest { - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', '3ds-verifyenrolled'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $cvnEl = $domTree->createElement('cvn'); - - $cvnNumberEl = $domTree->createElement('number'); - $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); - $cvnEl->appendChild($cvnNumberEl); - - $presIndEl = $domTree->createElement('presind', 1); - $cvnEl->appendChild($presIndEl); - - $cardEl->appendChild($cvnEl); - - $issueEl = $domTree->createElement('issueno'); - $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - /** - * We need to inspect this response to see if the customer is actually - * enrolled in the 3D Secure program. If they're not, we can go ahead - * and do a normal auth instead. - */ - $response = $this->response = new EnrolmentResponse($this, $data); - - if (!$response->isEnrolled()) { - $request = new AuthRequest($this->httpClient, $this->httpRequest); - $request->initialize($this->getParameters()); - - $response = $request->send(); - } - - return $response; - } - -// public function getEndpoint() -// { -// return $this->getParameter('3dSecureEndpoint'); -// } -// public function setAuthEndpoint($value) -// { -// return $this->setParameter('3dSecureEndpoint', $value); -// } - - public function getEndpoint() { - return $this->getParameter('authEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('authEndpoint', $value); - } +class EnrolmentRequest extends RemoteAbstractRequest +{ + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', '3ds-verifyenrolled'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $cvnEl = $domTree->createElement('cvn'); + + $cvnNumberEl = $domTree->createElement('number'); + $cvnNumberEl->appendChild($domTree->createTextNode($card->getCvv())); + $cvnEl->appendChild($cvnNumberEl); + + $presIndEl = $domTree->createElement('presind', 1); + $cvnEl->appendChild($presIndEl); + + $cardEl->appendChild($cvnEl); + + $issueEl = $domTree->createElement('issueno'); + $issueEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + /** + * We need to inspect this response to see if the customer is actually + * enrolled in the 3D Secure program. If they're not, we can go ahead + * and do a normal auth instead. + */ + $response = $this->response = new EnrolmentResponse($this, $data); + + if (!$response->isEnrolled()) { + $request = new AuthRequest($this->httpClient, $this->httpRequest); + $request->initialize($this->getParameters()); + + $response = $request->send(); + } + + return $response; + } + public function getEndpoint() + { + return $this->getParameter('authEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('authEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/EnrolmentResponse.php b/src/Omnipay/Realex/Message/EnrolmentResponse.php index 3f2670b..8fd7d8a 100644 --- a/src/Omnipay/Realex/Message/EnrolmentResponse.php +++ b/src/Omnipay/Realex/Message/EnrolmentResponse.php @@ -14,78 +14,86 @@ * * @property EnrolmentRequest $request */ -class EnrolmentResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return false; - } - - public function isEnrolled() { - return $this->xml->enrolled == 'Y'; - } - - public function getMessage() { - $message = (string) $this->xml->message; - - return $message; - } - - public function getTransactionReference() { - $transactionReference = !empty($this->xml->pasref) ? $this->xml->pasref : null; - - return $transactionReference; - } - - public function isRedirect() { - if ($this->xml->result == '00' && $this->xml->enrolled == 'Y') { - return true; - } else { - return false; - } - } - - public function getRedirectUrl() { - return (string) $this->xml->url; - } - - public function getRedirectMethod() { - return 'POST'; - } - - /** - * Any encrypted data that we wish to have returned to us. - * Basically, this is all the card data that we will have to - * re-submit to to Realex in order to complete the authorisation. - */ - protected function getMerchantData() { - /** - * @var CreditCard $card - */ - $card = $this->request->getCard(); - $data = array( - 'transactionId' => $this->request->getTransactionId(), - 'currency' => $this->request->getCurrency(), - 'amount' => $this->request->getAmount(), - 'number' => $card->getNumber(), - 'expiryMonth' => $card->getExpiryMonth(), - 'expiryYear' => $card->getExpiryYear(), - 'billingName' => $card->getBillingName(), - 'cvv' => $card->getCvv(), - 'issueNumber' => $card->getIssueNumber(), - 'billingCountry' => $card->getBillingCountry() - ); - $serialised = json_encode($data); - $encoded = base64_encode($serialised); - - return $encoded; - } - - public function getRedirectData() { - return array( - 'PaReq' => (string) $this->xml->pareq, - 'TermUrl' => $this->request->getReturnUrl(), - 'MD' => $this->getMerchantData() - ); - } - +class EnrolmentResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return false; + } + + public function isEnrolled() + { + return $this->xml->enrolled == 'Y'; + } + + public function getMessage() + { + $message = (string) $this->xml->message; + + return $message; + } + + public function getTransactionReference() + { + $transactionReference = !empty($this->xml->pasref) ? $this->xml->pasref : null; + + return $transactionReference; + } + + public function isRedirect() + { + if ($this->xml->result == '00' && $this->xml->enrolled == 'Y') { + return true; + } else { + return false; + } + } + + public function getRedirectUrl() + { + return (string) $this->xml->url; + } + + public function getRedirectMethod() + { + return 'POST'; + } + + /** + * Any encrypted data that we wish to have returned to us. + * Basically, this is all the card data that we will have to + * re-submit to to Realex in order to complete the authorisation. + */ + protected function getMerchantData() + { + /** + * @var CreditCard $card + */ + $card = $this->request->getCard(); + $data = array( + 'transactionId' => $this->request->getTransactionId(), + 'currency' => $this->request->getCurrency(), + 'amount' => $this->request->getAmount(), + 'number' => $card->getNumber(), + 'expiryMonth' => $card->getExpiryMonth(), + 'expiryYear' => $card->getExpiryYear(), + 'billingName' => $card->getBillingName(), + 'cvv' => $card->getCvv(), + 'issueNumber' => $card->getIssueNumber(), + 'billingCountry' => $card->getBillingCountry() + ); + $serialised = json_encode($data); + $encoded = base64_encode($serialised); + + return $encoded; + } + + public function getRedirectData() + { + return array( + 'PaReq' => (string) $this->xml->pareq, + 'TermUrl' => $this->request->getReturnUrl(), + 'MD' => $this->getMerchantData() + ); + } } diff --git a/src/Omnipay/Realex/Message/FetchTransactionRequest.php b/src/Omnipay/Realex/Message/FetchTransactionRequest.php index 1273c64..9f8a1c9 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionRequest.php +++ b/src/Omnipay/Realex/Message/FetchTransactionRequest.php @@ -7,72 +7,76 @@ /** * Realex Query Request */ -class FetchTransactionRequest extends RemoteAbstractRequest { - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - // No amount, currency or card number for query requests but still needs to be in hash - $amount = ''; - $currency = ''; - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'query'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // original order ID - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($orderIdEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new FetchTransactionResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('3dSecureEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('3dSecureEndpoint', $value); - } - +class FetchTransactionRequest extends RemoteAbstractRequest +{ + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + // No amount, currency or card number for query requests but still needs to be in hash + $amount = ''; + $currency = ''; + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'query'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // original order ID + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($orderIdEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new FetchTransactionResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('3dSecureEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('3dSecureEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/FetchTransactionResponse.php b/src/Omnipay/Realex/Message/FetchTransactionResponse.php index 3eec6e6..554244f 100644 --- a/src/Omnipay/Realex/Message/FetchTransactionResponse.php +++ b/src/Omnipay/Realex/Message/FetchTransactionResponse.php @@ -10,45 +10,53 @@ /** * Realex Query Response */ -class FetchTransactionResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } - - public function getTransactionReference() { - return ($this->xml->pasref) ? (string) $this->xml->pasref : null; - } - - public function getAuthCode() { - return ($this->xml->authcode) ? (string) $this->xml->authcode : null; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class FetchTransactionResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() + { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() + { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php index e01c73d..e467e96 100644 --- a/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/AbstractRequest.php @@ -5,170 +5,200 @@ /** * Realex Abstract Request */ -abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { - - public function getMerchantId() { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) { - return $this->setParameter('merchantId', $value); - } - - public function getAccount() { - return $this->getParameter('account'); - } - - public function setAccount($value) { - return $this->setParameter('account', $value); - } - - public function getSecret() { - return $this->getParameter('secret'); - } - - public function setSecret($value) { - return $this->setParameter('secret', $value); - } - - public function setStore($value) { - return $this->setParameter('store', $value); - } - - public function getStore() { - return $this->getParameters('store'); - } - - public function getPares() { - return $this->getParameter('pares'); - } - - public function setPares($value) { - return $this->setParameter('pares', $value); - } - - public function setCavv($value) { - return $this->setParameter('cavv', $value); - } - - public function getCavv() { - return $this->getParameter('cavv'); - } - - public function setXid($value) { - return $this->setParameter('xid', $value); - } - - public function getXid() { - return $this->getParameter('xid'); - } - - public function setEci($value) { - return $this->setParameter('eci', $value); - } - - public function getEci() { - return $this->getParameter('eci'); - } - - public function setNotifyUrl($value) { - return $this->setParameter('notifyUrl', $value); - } - - public function getNotifyUrl() { - return $this->getParameter('notifyUrl'); - } - - public function setExtraData($value) { - return $this->setParameter('extraData', $value); - } - - public function getExtraData() { - return $this->getParameter('extraData'); - } - - public function getBaseData($autoSettle = true, $card = null) { - $data = array( - 'EXTRA' => $this->getExtraData(), - 'MERCHANT_ID' => $this->getMerchantId(), - 'ORDER_ID' => $this->getTransactionId(), - 'CURRENCY' => $this->getCurrency(), - 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), - 'AMOUNT' => round($this->getAmount() * 100), - 'TIMESTAMP' => gmdate('YmdHis'), - 'AUTO_SETTLE_FLAG' => $autoSettle - ); - $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); - return $data; - } - - public function createSignature($data, $method = 'sha1', $card = null) { - $hash = $method(rtrim(implode('.', array( - $data['TIMESTAMP'], - $data['MERCHANT_ID'], - $data['ORDER_ID'], - $data['AMOUNT'], - $data['CURRENCY'], - $card !== null ? $card->getNumber() : null - )), '.')); - - return $method($hash . '.' . $this->getSecret()); - } - - public function getRequestXML($card, $autoSettle = true, $extraData = array(), $addressData = true, $cardData = true) { - $data = $this->getBaseData($autoSettle, $card); - $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); - $request = new \SimpleXMLElement(''); - $request['timestamp'] = $data['TIMESTAMP']; - $request['type'] = $this->getType(); - $request->merchantid = $this->getMerchantId(); - $request->account = $this->getAccount(); - $request->orderid = $data['ORDER_ID']; - //$request->md5hash = $this->createSignature($data, 'md5', $card); - $request->custipaddress = $this->getClientIp(); - $request->amount = $data['AMOUNT']; - $request->amount['currency'] = $data['CURRENCY']; - $request->autosettle['flag'] = (int) $data['AUTO_SETTLE_FLAG']; - // Flesh out the XML structure - $request->addChild('card'); - $request->card->addChild('cvn'); - $request->card->number = $card->getNumber(); - $request->card->expdate = $card->getExpiryDate('my'); - $request->card->type = strtoupper($brand); - $request->card->chname = $card->getName(); - // Not all request want this data - if ($cardData) { - $request->card->issueno = $card->getIssueNumber(); - $request->card->addChild('cvn'); - $request->card->cvn->addChild('number', $card->getCvv()); - $request->card->cvn->addChild('presind', 1); - } - // not all requests want this data - if ($addressData) { - $request->address['type'] = 'billing'; - $request->address->code = $card->getBillingPostcode(); - $request->address->country = strtoupper($card->getBillingCountry()); - } - // Add in extra array data for any obscure fields - if (!empty($extraData)) { - foreach ($extraData as $key => $value) { - $request->$key = $value; - } - } - $request->sha1hash = $data['SHA1HASH']; - return $request->asXML(); - } - - protected function getType() { - return 'auth'; - } - - public function getCheckoutEndpoint() { - return $this->getParameter('checkoutEndpoint'); - } - - public function setCheckoutEndpoint($value) { - return $this->setParameter('checkoutEndpoint', $value); - } - +abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest +{ + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function setStore($value) + { + return $this->setParameter('store', $value); + } + + public function getStore() + { + return $this->getParameters('store'); + } + + public function getPares() + { + return $this->getParameter('pares'); + } + + public function setPares($value) + { + return $this->setParameter('pares', $value); + } + + public function setCavv($value) + { + return $this->setParameter('cavv', $value); + } + + public function getCavv() + { + return $this->getParameter('cavv'); + } + + public function setXid($value) + { + return $this->setParameter('xid', $value); + } + + public function getXid() + { + return $this->getParameter('xid'); + } + + public function setEci($value) + { + return $this->setParameter('eci', $value); + } + + public function getEci() + { + return $this->getParameter('eci'); + } + + public function setNotifyUrl($value) + { + return $this->setParameter('notifyUrl', $value); + } + + public function getNotifyUrl() + { + return $this->getParameter('notifyUrl'); + } + + public function setExtraData($value) + { + return $this->setParameter('extraData', $value); + } + + public function getExtraData() + { + return $this->getParameter('extraData'); + } + + public function getBaseData($autoSettle = true, $card = null) + { + $data = array( + 'EXTRA' => $this->getExtraData(), + 'MERCHANT_ID' => $this->getMerchantId(), + 'ORDER_ID' => $this->getTransactionId(), + 'CURRENCY' => $this->getCurrency(), + 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), + 'AMOUNT' => round($this->getAmount() * 100), + 'TIMESTAMP' => gmdate('YmdHis'), + 'AUTO_SETTLE_FLAG' => $autoSettle + ); + $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); + return $data; + } + + public function createSignature($data, $method = 'sha1', $card = null) + { + $hash = $method(rtrim(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['AMOUNT'], + $data['CURRENCY'], + $card !== null ? $card->getNumber() : null + )), '.')); + + return $method($hash . '.' . $this->getSecret()); + } + + public function getRequestXML( + $card, + $autoSettle = true, + $extraData = array(), + $addressData = true, + $cardData = true + ) { + $data = $this->getBaseData($autoSettle, $card); + $brand = (strcasecmp($card->getBrand(), "mastercard") == 0) ? "mc" : $card->getBrand(); + $request = new \SimpleXMLElement(''); + $request['timestamp'] = $data['TIMESTAMP']; + $request['type'] = $this->getType(); + $request->merchantid = $this->getMerchantId(); + $request->account = $this->getAccount(); + $request->orderid = $data['ORDER_ID']; + //$request->md5hash = $this->createSignature($data, 'md5', $card); + $request->custipaddress = $this->getClientIp(); + $request->amount = $data['AMOUNT']; + $request->amount['currency'] = $data['CURRENCY']; + $request->autosettle['flag'] = (int) $data['AUTO_SETTLE_FLAG']; + // Flesh out the XML structure + $request->addChild('card'); + $request->card->addChild('cvn'); + $request->card->number = $card->getNumber(); + $request->card->expdate = $card->getExpiryDate('my'); + $request->card->type = strtoupper($brand); + $request->card->chname = $card->getName(); + // Not all request want this data + if ($cardData) { + $request->card->issueno = $card->getIssueNumber(); + $request->card->addChild('cvn'); + $request->card->cvn->addChild('number', $card->getCvv()); + $request->card->cvn->addChild('presind', 1); + } + // not all requests want this data + if ($addressData) { + $request->address['type'] = 'billing'; + $request->address->code = $card->getBillingPostcode(); + $request->address->country = strtoupper($card->getBillingCountry()); + } + // Add in extra array data for any obscure fields + if (!empty($extraData)) { + foreach ($extraData as $key => $value) { + $request->$key = $value; + } + } + $request->sha1hash = $data['SHA1HASH']; + return $request->asXML(); + } + + protected function getType() + { + return 'auth'; + } + + public function getCheckoutEndpoint() + { + return $this->getParameter('checkoutEndpoint'); + } + + public function setCheckoutEndpoint($value) + { + return $this->setParameter('checkoutEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php index 1fb3117..b634244 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeRequest.php @@ -5,18 +5,20 @@ /** * Realex Redirect Authorize Request */ -class RedirectAuthorizeRequest extends AbstractRequest { +class RedirectAuthorizeRequest extends AbstractRequest +{ + public function getData() + { + return null; + } - public function getData() { - return null; - } - - public function getRedirectData() { - return $this->getBaseData(); - } - - public function sendData($data) { - return $this->response = new RedirectAuthorizeResponse($this, $data); - } + public function getRedirectData() + { + return $this->getBaseData(); + } + public function sendData($data) + { + return $this->response = new RedirectAuthorizeResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php index 4e60f0c..68e12ec 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectAuthorizeResponse.php @@ -7,30 +7,35 @@ /** * Realex Redirect Authorize Response */ -class RedirectAuthorizeResponse extends Response implements RedirectResponseInterface { - - public function isSuccessful() { - return false; - } - - public function isRedirect() { - return true; - } - - public function getRedirectUrl() { - return $this->getRequest()->getCheckoutEndpoint(); - } - - public function getTransactionReference() { - return $this->getRequest()->getTransactionId(); - } - - public function getRedirectMethod() { - return 'POST'; - } - - public function getRedirectData() { - return $this->getRequest()->getBaseData(false); - } - +class RedirectAuthorizeResponse extends Response implements RedirectResponseInterface +{ + public function isSuccessful() + { + return false; + } + + public function isRedirect() + { + return true; + } + + public function getRedirectUrl() + { + return $this->getRequest()->getCheckoutEndpoint(); + } + + public function getTransactionReference() + { + return $this->getRequest()->getTransactionId(); + } + + public function getRedirectMethod() + { + return 'POST'; + } + + public function getRedirectData() + { + return $this->getRequest()->getBaseData(false); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php index bc541da..1a25b47 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteAuthorizeRequest.php @@ -7,30 +7,31 @@ /** * Realex Redirect Complete Authorize Request */ -class RedirectCompleteAuthorizeRequest extends AbstractRequest { - - public function getData() { - // Build initial hash - $hash = sha1(implode('.', array( - $this->httpRequest->request->get('TIMESTAMP'), - $this->httpRequest->request->get('MERCHANT_ID'), - $this->httpRequest->request->get('ORDER_ID'), - $this->httpRequest->request->get('RESULT'), - $this->httpRequest->request->get('MESSAGE'), - $this->httpRequest->request->get('PASREF'), - $this->httpRequest->request->get('AUTHCODE') - ))); - - // Validate signature - if ($this->httpRequest->request->get('SHA1HASH') !== sha1($hash . '.' . $this->getSecret())) { - throw new InvalidResponseException; - } - - return $this->httpRequest->request->all(); - } - - public function sendData($data) { - return $this->response = new Response($this, $data); - } - +class RedirectCompleteAuthorizeRequest extends AbstractRequest +{ + public function getData() + { + // Build initial hash + $hash = sha1(implode('.', array( + $this->httpRequest->request->get('TIMESTAMP'), + $this->httpRequest->request->get('MERCHANT_ID'), + $this->httpRequest->request->get('ORDER_ID'), + $this->httpRequest->request->get('RESULT'), + $this->httpRequest->request->get('MESSAGE'), + $this->httpRequest->request->get('PASREF'), + $this->httpRequest->request->get('AUTHCODE') + ))); + + // Validate signature + if ($this->httpRequest->request->get('SHA1HASH') !== sha1($hash . '.' . $this->getSecret())) { + throw new InvalidResponseException; + } + + return $this->httpRequest->request->all(); + } + + public function sendData($data) + { + return $this->response = new Response($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php index add0e61..f3d3702 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php @@ -7,36 +7,36 @@ /** * Realex Redirect Complete Authorize Request */ -class RedirectCompleteStoreCardRequest extends AbstractRequest { - - public function getData() { - - $data; - foreach (json_decode($this->httpRequest->request->get('hppResponse')) AS $key => $value) { - $data[$key] = base64_decode($value); - } - - // Build initial hash - $hash = sha1(implode('.', array( - $data['TIMESTAMP'], - $data['MERCHANT_ID'], - $data['ORDER_ID'], - $data['RESULT'], - $data['MESSAGE'], - $data['PASREF'], - $data['AUTHCODE'], - ))); - - // Validate signature - if ($data['SHA1HASH'] !== sha1($hash . '.' . $this->getSecret())) { - throw new InvalidResponseException; - } - - return $data; - } - - public function sendData($data) { - return $this->response = new dataVaultResponse($this, $data); - } - +class RedirectCompleteStoreCardRequest extends AbstractRequest +{ + public function getData() + { + $data; + foreach (json_decode($this->httpRequest->request->get('hppResponse')) as $key => $value) { + $data[$key] = base64_decode($value); + } + + // Build initial hash + $hash = sha1(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['RESULT'], + $data['MESSAGE'], + $data['PASREF'], + $data['AUTHCODE'], + ))); + + // Validate signature + if ($data['SHA1HASH'] !== sha1($hash . '.' . $this->getSecret())) { + throw new InvalidResponseException; + } + + return $data; + } + + public function sendData($data) + { + return $this->response = new dataVaultResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php index e4f33b2..3fa7be9 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultRequest.php @@ -5,56 +5,60 @@ /** * Realex Redirect Authorize Request */ -class RedirectDataVaultRequest extends AbstractRequest { - - public function getData() { - return null; - } - - public function getBaseData($autoSettle = '1', $card = null) { - $data = array( - 'ACCOUNT' => $this->getAccount(), - 'MERCHANT_ID' => $this->getMerchantId(), - 'ORDER_ID' => $this->getTransactionId(), - 'CURRENCY' => $this->getCurrency(), - 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), - 'AMOUNT' => round($this->getAmount() * 100), - 'TIMESTAMP' => gmdate('YmdHis'), - 'AUTO_SETTLE_FLAG' => $autoSettle, - 'HPP_VERSION' => 2 - ); - - if (isset($this->getData()['extraData']) && is_array($this->getData()['extraData'])) { - $data = array_merge($data, $this->getData()['extraData']); - } - $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); - return $data; - } - - /* - * "timestamp.merchantid.orderid.amount.currency.payerref.paymentmethod" - */ - - public function createSignature($data, $method = 'sha1', $card = null) { - $hash = $method(implode('.', array( - $data['TIMESTAMP'], - $data['MERCHANT_ID'], - $data['ORDER_ID'], - $data['AMOUNT'], - $data['CURRENCY'], - $data['PAYER_REF'], - '' - ))); - - return $method($hash . '.' . $this->getSecret()); - } - - public function getRedirectData() { - return $this->getBaseData(); - } - - public function sendData($data) { - return $this->response = new RedirectDataVaultResponse($this, $data); - } +class RedirectDataVaultRequest extends AbstractRequest +{ + public function getData() + { + return null; + } + public function getBaseData($autoSettle = '1', $card = null) + { + $data = array( + 'ACCOUNT' => $this->getAccount(), + 'MERCHANT_ID' => $this->getMerchantId(), + 'ORDER_ID' => $this->getTransactionId(), + 'CURRENCY' => $this->getCurrency(), + 'MERCHANT_RESPONSE_URL' => $this->getReturnUrl(), + 'AMOUNT' => round($this->getAmount() * 100), + 'TIMESTAMP' => gmdate('YmdHis'), + 'AUTO_SETTLE_FLAG' => $autoSettle, + 'HPP_VERSION' => 2 + ); + + if (isset($this->getData()['extraData']) && is_array($this->getData()['extraData'])) { + $data = array_merge($data, $this->getData()['extraData']); + } + $data['SHA1HASH'] = $this->createSignature($data, 'sha1', $card); + return $data; + } + + /* + * "timestamp.merchantid.orderid.amount.currency.payerref.paymentmethod" + */ + + public function createSignature($data, $method = 'sha1', $card = null) + { + $hash = $method(implode('.', array( + $data['TIMESTAMP'], + $data['MERCHANT_ID'], + $data['ORDER_ID'], + $data['AMOUNT'], + $data['CURRENCY'], + $data['PAYER_REF'], + '' + ))); + + return $method($hash . '.' . $this->getSecret()); + } + + public function getRedirectData() + { + return $this->getBaseData(); + } + + public function sendData($data) + { + return $this->response = new RedirectDataVaultResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php index 855727c..b38a7aa 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectDataVaultResponse.php @@ -7,31 +7,36 @@ /** * Realex Redirect Authorize Response */ -class RedirectDataVaultResponse extends Response implements RedirectResponseInterface { - - public function isSuccessful() { - return false; - } - - public function isRedirect() { - return true; - } - - public function getRedirectUrl() { - return $this->getRequest()->getCheckoutEndpoint(); - } - - public function getTransactionReference() { - return $this->getRequest()->getTransactionId(); - } - - public function getRedirectMethod() { - return 'POST'; - } - - public function getRedirectData() { - $data = $this->getRequest()->getBaseData(false); - return $data; - } - +class RedirectDataVaultResponse extends Response implements RedirectResponseInterface +{ + public function isSuccessful() + { + return false; + } + + public function isRedirect() + { + return true; + } + + public function getRedirectUrl() + { + return $this->getRequest()->getCheckoutEndpoint(); + } + + public function getTransactionReference() + { + return $this->getRequest()->getTransactionId(); + } + + public function getRedirectMethod() + { + return 'POST'; + } + + public function getRedirectData() + { + $data = $this->getRequest()->getBaseData(false); + return $data; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php index fab5395..91d8365 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseRequest.php @@ -5,10 +5,10 @@ /** * Realex Redirect Purchase Request */ -class RedirectPurchaseRequest extends RedirectAuthorizeRequest { - - public function sendData($data) { - return $this->response = new RedirectPurchaseResponse($this, $data); - } - +class RedirectPurchaseRequest extends RedirectAuthorizeRequest +{ + public function sendData($data) + { + return $this->response = new RedirectPurchaseResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php index 221a515..afd4b15 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectPurchaseResponse.php @@ -7,10 +7,10 @@ /** * Realex Redirect Purchase Response */ -class RedirectPurchaseResponse extends RedirectAuthorizeResponse { - - public function getRedirectData() { - return $this->getRequest()->getBaseData(); - } - +class RedirectPurchaseResponse extends RedirectAuthorizeResponse +{ + public function getRedirectData() + { + return $this->getRequest()->getBaseData(); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php index 0fe48fd..e854454 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardRequest.php @@ -5,82 +5,96 @@ /** * Realex Redirect Purchase Request */ -class RedirectStoreCardRequest extends RedirectDataVaultRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($data) { - $this->setParameter('customerRef', $data); - } - - public function getCustomerExists() { - return $this->getParameter('customerExists'); - } - - public function setCustomerExists($data) { - $this->setParameter('customerExists', $data); - } - - public function getValidateCardOnly() { - return $this->getParameter('validateCardOnly'); - } - - public function setValidateCardOnly($data) { - $this->setParameter('validateCardOnly', $data); - } - - public function getOfferSaveCard() { - return $this->getParameter('offerSaveCard'); - } - - public function setOfferSaveCard($data) { - $this->setParameter('offerSaveCard', $data); - } - - public function getCardPaymentButton() { - return $this->getParameter('cardPaymentButton'); - } - - public function setCardPaymentButton($data) { - $this->setParameter('cardPaymentButton', $data); - } - - public function getHPPPostDimensions() { - return $this->getParameter('HPPPostDimensions'); - } - - public function setHPPPostDimensions($data) { - $this->setParameter('HPPPostDimensions', $data); - } - - public function getHPPPostResponse() { - return $this->getParameter('HPPPostResponse'); - } - - public function setHPPPostResponse($data) { - $this->setParameter('HPPPostResponse', $data); - } - - public function getData() { - - $data['extraData'] = [ - 'PAYER_REF' => $this->getCustomerRef(), - 'PAYER_EXIST' => $this->getCustomerExists(), - 'VALIDATE_CARD_ONLY' => $this->getValidateCardOnly(), - 'OFFER_SAVE_CARD' => $this->getOfferSaveCard(), - 'CARD_STORAGE_ENABLE' => '1', - 'CARD_PAYMENT_BUTTON' => $this->getCardPaymentButton(), - 'HPP_POST_DIMENSIONS' => $this->getHPPPostDimensions(), - 'HPP_POST_RESPONSE' => $this->getHPPPostResponse(), - ]; - - return $data; - } - - public function sendData($data) { - return $this->response = new RedirectStoreCardResponse($this, $data); - } - +class RedirectStoreCardRequest extends RedirectDataVaultRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($data) + { + $this->setParameter('customerRef', $data); + } + + public function getCustomerExists() + { + return $this->getParameter('customerExists'); + } + + public function setCustomerExists($data) + { + $this->setParameter('customerExists', $data); + } + + public function getValidateCardOnly() + { + return $this->getParameter('validateCardOnly'); + } + + public function setValidateCardOnly($data) + { + $this->setParameter('validateCardOnly', $data); + } + + public function getOfferSaveCard() + { + return $this->getParameter('offerSaveCard'); + } + + public function setOfferSaveCard($data) + { + $this->setParameter('offerSaveCard', $data); + } + + public function getCardPaymentButton() + { + return $this->getParameter('cardPaymentButton'); + } + + public function setCardPaymentButton($data) + { + $this->setParameter('cardPaymentButton', $data); + } + + public function getHPPPostDimensions() + { + return $this->getParameter('HPPPostDimensions'); + } + + public function setHPPPostDimensions($data) + { + $this->setParameter('HPPPostDimensions', $data); + } + + public function getHPPPostResponse() + { + return $this->getParameter('HPPPostResponse'); + } + + public function setHPPPostResponse($data) + { + $this->setParameter('HPPPostResponse', $data); + } + + public function getData() + { + $data['extraData'] = [ + 'PAYER_REF' => $this->getCustomerRef(), + 'PAYER_EXIST' => $this->getCustomerExists(), + 'VALIDATE_CARD_ONLY' => $this->getValidateCardOnly(), + 'OFFER_SAVE_CARD' => $this->getOfferSaveCard(), + 'CARD_STORAGE_ENABLE' => '1', + 'CARD_PAYMENT_BUTTON' => $this->getCardPaymentButton(), + 'HPP_POST_DIMENSIONS' => $this->getHPPPostDimensions(), + 'HPP_POST_RESPONSE' => $this->getHPPPostResponse(), + ]; + + return $data; + } + + public function sendData($data) + { + return $this->response = new RedirectStoreCardResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php index 0d5b77a..208feb3 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectStoreCardResponse.php @@ -7,12 +7,12 @@ /** * Realex Redirect Purchase Response */ -class RedirectStoreCardResponse extends RedirectDataVaultResponse { - - public function getRedirectData() { - $data = $this->getRequest()->getRedirectData(); - - return $data; - } +class RedirectStoreCardResponse extends RedirectDataVaultResponse +{ + public function getRedirectData() + { + $data = $this->getRequest()->getRedirectData(); + return $data; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php index 5a710e0..64d1aac 100644 --- a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php @@ -8,52 +8,60 @@ /** * Realex Response */ -class dataVaultResponse extends AbstractResponse { - - public function __construct(RequestInterface $request, $data = array()) { - $this->request = $request; - $this->data = $data; - } - - public function isSuccessful() { - if (!$this->isPayerSetupSuccessful()) { - return false; - } elseif (!$this->isPayerCardAddSuccessful()) { - return false; - } else { - return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; - } - } - - public function getMessage() { - $message; - if (isset($this->data['PMT_SETUP_MSG'])) { - $message .= $this->data['PMT_SETUP_MSG'] . ' '; - } - if (isset($this->data['PAYER_SETUP_MSG'])) { - $message .= $this->data['PAYER_SETUP_MSG'] . ' '; - } - if (isset($this->data['MESSAGE'])) { - $message .= $this->data['MESSAGE'] . ' '; - } - - return $message; - } - - public function getTransactionReference() { - return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; - } - - public function isPayerSetupSuccessful() { - return !isset($this->data['PAYER_SETUP']) || (isset($this->data['PAYER_SETUP']) && '00' === $this->data['PAYER_SETUP']); - } - - public function isPayerCardAddSuccessful() { - return !isset($this->data['PMT_SETUP']) || (isset($this->data['PMT_SETUP']) && '00' === $this->data['PMT_SETUP']); - } - - public function getCardToken() { - return isset($this->data['SAVED_PMT_REF']) ? $this->data['SAVED_PMT_REF'] : null; - } +class DataVaultResponse extends AbstractResponse +{ + public function __construct(RequestInterface $request, $data = array()) + { + $this->request = $request; + $this->data = $data; + } + public function isSuccessful() + { + if (!$this->isPayerSetupSuccessful()) { + return false; + } elseif (!$this->isPayerCardAddSuccessful()) { + return false; + } else { + return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; + } + } + + public function getMessage() + { + $message; + if (isset($this->data['PMT_SETUP_MSG'])) { + $message .= $this->data['PMT_SETUP_MSG'] . ' '; + } + if (isset($this->data['PAYER_SETUP_MSG'])) { + $message .= $this->data['PAYER_SETUP_MSG'] . ' '; + } + if (isset($this->data['MESSAGE'])) { + $message .= $this->data['MESSAGE'] . ' '; + } + + return $message; + } + + public function getTransactionReference() + { + return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; + } + + public function isPayerSetupSuccessful() + { + return !isset($this->data['PAYER_SETUP']) || + (isset($this->data['PAYER_SETUP']) && '00' === $this->data['PAYER_SETUP']); + } + + public function isPayerCardAddSuccessful() + { + return !isset($this->data['PMT_SETUP']) || + (isset($this->data['PMT_SETUP']) && '00' === $this->data['PMT_SETUP']); + } + + public function getCardToken() + { + return isset($this->data['SAVED_PMT_REF']) ? $this->data['SAVED_PMT_REF'] : null; + } } diff --git a/src/Omnipay/Realex/Message/Redirect/response.php b/src/Omnipay/Realex/Message/Redirect/response.php index 3fe32e8..e3d1599 100644 --- a/src/Omnipay/Realex/Message/Redirect/response.php +++ b/src/Omnipay/Realex/Message/Redirect/response.php @@ -8,23 +8,26 @@ /** * Realex Response */ -class Response extends AbstractResponse { - - public function __construct(RequestInterface $request, $data = array()) { - $this->request = $request; - $this->data = $data; - } - - public function isSuccessful() { - return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; - } - - public function getMessage() { - return isset($this->data['MESSAGE']) ? $this->data['MESSAGE'] : null; - } - - public function getTransactionReference() { - return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; - } - +class Response extends AbstractResponse +{ + public function __construct(RequestInterface $request, $data = array()) + { + $this->request = $request; + $this->data = $data; + } + + public function isSuccessful() + { + return isset($this->data['RESULT']) && '00' === $this->data['RESULT']; + } + + public function getMessage() + { + return isset($this->data['MESSAGE']) ? $this->data['MESSAGE'] : null; + } + + public function getTransactionReference() + { + return isset($this->data['PASREF']) ? $this->data['PASREF'] : null; + } } diff --git a/src/Omnipay/Realex/Message/RefundRequest.php b/src/Omnipay/Realex/Message/RefundRequest.php index ef31e19..d149fb1 100644 --- a/src/Omnipay/Realex/Message/RefundRequest.php +++ b/src/Omnipay/Realex/Message/RefundRequest.php @@ -7,128 +7,144 @@ /** * Realex Refund Request */ -class RefundRequest extends RemoteAbstractRequest { - - public function getTransactionReference() { - return $this->getParameter('transactionReference'); - } - - public function setTransactionReference($value) { - return $this->setParameter('transactionReference', $value); - } - - public function getAuthCode() { - return $this->getParameter('authCode'); - } - - public function setAuthCode($value) { - return $this->setParameter('authCode', $value); - } - - public function getOriginalTransactionId() { - return $this->getParameter('originalTransactionId'); - } - - public function setOriginalTransactionId($value) { - return $this->setParameter('originalTransactionId', $value); - } - - public function getRefundPassword() { - return $this->getParameter('refundPassword'); - } - - public function setRefundPassword($value) { - return $this->setParameter('refundPassword', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate( - 'amount', 'currency', 'originalTransactionId', 'transactionReference', 'authCode', 'refundPassword' - ); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $originalTransactionId = $this->getOriginalTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - // No card number for rebate requests but still needs to be in hash - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$originalTransactionId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'rebate'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // the ID of the original transaction (confusingly in a tag called 'orderid') - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); - $root->appendChild($orderIdEl); - - // pasref for the original transaction - $pasRefEl = $domTree->createElement('pasref'); - $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); - $root->appendChild($pasRefEl); - - // authcode returned for original transaction - $authCodeEl = $domTree->createElement('authcode'); - $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); - $root->appendChild($authCodeEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - // refund hash - $refundHash = sha1($this->getRefundPassword()); - $refundHashEl = $domTree->createElement('refundhash'); - $refundHashEl->appendChild($domTree->createTextNode($refundHash)); - $root->appendChild($refundHashEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new RefundResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('AuthEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('AuthEndpoint', $value); - } - +class RefundRequest extends RemoteAbstractRequest +{ + public function getTransactionReference() + { + return $this->getParameter('transactionReference'); + } + + public function setTransactionReference($value) + { + return $this->setParameter('transactionReference', $value); + } + + public function getAuthCode() + { + return $this->getParameter('authCode'); + } + + public function setAuthCode($value) + { + return $this->setParameter('authCode', $value); + } + + public function getOriginalTransactionId() + { + return $this->getParameter('originalTransactionId'); + } + + public function setOriginalTransactionId($value) + { + return $this->setParameter('originalTransactionId', $value); + } + + public function getRefundPassword() + { + return $this->getParameter('refundPassword'); + } + + public function setRefundPassword($value) + { + return $this->setParameter('refundPassword', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate( + 'amount', + 'currency', + 'originalTransactionId', + 'transactionReference', + 'authCode', + 'refundPassword' + ); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $originalTransactionId = $this->getOriginalTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + // No card number for rebate requests but still needs to be in hash + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$originalTransactionId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'rebate'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // the ID of the original transaction (confusingly in a tag called 'orderid') + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($originalTransactionId)); + $root->appendChild($orderIdEl); + + // pasref for the original transaction + $pasRefEl = $domTree->createElement('pasref'); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); + $root->appendChild($pasRefEl); + + // authcode returned for original transaction + $authCodeEl = $domTree->createElement('authcode'); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); + $root->appendChild($authCodeEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + // refund hash + $refundHash = sha1($this->getRefundPassword()); + $refundHashEl = $domTree->createElement('refundhash'); + $refundHashEl->appendChild($domTree->createTextNode($refundHash)); + $root->appendChild($refundHashEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new RefundResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('AuthEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('AuthEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/RefundResponse.php b/src/Omnipay/Realex/Message/RefundResponse.php index 3ab9688..ec4dc60 100644 --- a/src/Omnipay/Realex/Message/RefundResponse.php +++ b/src/Omnipay/Realex/Message/RefundResponse.php @@ -10,45 +10,53 @@ /** * Realex Refund Response */ -class RefundResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } - - public function getTransactionReference() { - return ($this->xml->pasref) ? (string) $this->xml->pasref : null; - } - - public function getAuthCode() { - return ($this->xml->authcode) ? (string) $this->xml->authcode : null; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class RefundResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() + { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() + { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php index 611ae30..d600577 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php @@ -8,75 +8,85 @@ /** * Realex Purchase Request */ -abstract class RemoteAbstractRequest extends AbstractRequest { - - protected $cardBrandMap = array( - 'mastercard' => 'mc', - 'diners_club' => 'diners' - ); - - /** - * Override some of the default Omnipay card brand names - * - * @return mixed - */ - protected function getCardBrand() { - $brand = $this->getCard()->getBrand(); - - if (isset($this->cardBrandMap[$brand])) { - $brand = $this->cardBrandMap[$brand]; - } - - return strtoupper($brand); - } - - public function getMerchantId() { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) { - return $this->setParameter('merchantId', $value); - } - - public function getAccount() { - return $this->getParameter('account'); - } - - public function setAccount($value) { - return $this->setParameter('account', $value); - } - - public function getSecret() { - return $this->getParameter('secret'); - } - - public function setSecret($value) { - return $this->setParameter('secret', $value); - } - - public function getReturnUrl() { - return $this->getParameter('returnUrl'); - } - - public function setReturnUrl($value) { - return $this->setParameter('returnUrl', $value); - } - - public function sendData($data) { - // register the payment - $this->httpClient->setConfig(array( - 'curl.options' => array( - 'CURLOPT_SSLVERSION' => 1, - 'CURLOPT_SSL_VERIFYPEER' => false - ) - )); - - $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); - - return $this->createResponse($httpResponse->getBody(true)); - } - - abstract public function getEndpoint(); - - abstract protected function createResponse($data); +abstract class RemoteAbstractRequest extends AbstractRequest +{ + protected $cardBrandMap = array( + 'mastercard' => 'mc', + 'diners_club' => 'diners' + ); + + /** + * Override some of the default Omnipay card brand names + * + * @return mixed + */ + protected function getCardBrand() + { + $brand = $this->getCard()->getBrand(); + + if (isset($this->cardBrandMap[$brand])) { + $brand = $this->cardBrandMap[$brand]; + } + + return strtoupper($brand); + } + + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getReturnUrl() + { + return $this->getParameter('returnUrl'); + } + + public function setReturnUrl($value) + { + return $this->setParameter('returnUrl', $value); + } + + public function sendData($data) + { + // register the payment + $this->httpClient->setConfig(array( + 'curl.options' => array( + 'CURLOPT_SSLVERSION' => 1, + 'CURLOPT_SSL_VERIFYPEER' => false + ) + )); + + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); + + return $this->createResponse($httpResponse->getBody(true)); + } + + abstract public function getEndpoint(); + + abstract protected function createResponse($data); } diff --git a/src/Omnipay/Realex/Message/RemoteAbstractResponse.php b/src/Omnipay/Realex/Message/RemoteAbstractResponse.php index 7a0a1ba..b6bc005 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractResponse.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractResponse.php @@ -11,28 +11,29 @@ /** * Realex Abstract Response */ -abstract class RemoteAbstractResponse extends AbstractResponse implements RedirectResponseInterface { - - protected $xml; - - public function __construct(RequestInterface $request, $data) { - parent::__construct($request, $data); - - $this->xml = $this->parseXml($data); - } - - /** - * Turn the raw XML response string into a SimpleXMLElement - * - * @param string $data - * @return \SimpleXMLElement - */ - public function parseXml($data) { - $data = str_replace(' ', ' ', $data); - $data = str_replace("\n", '', $data); - $data = str_replace("\r", '', $data); - - return new \SimpleXMLElement($data); - } - +abstract class RemoteAbstractResponse extends AbstractResponse implements RedirectResponseInterface +{ + protected $xml; + + public function __construct(RequestInterface $request, $data) + { + parent::__construct($request, $data); + + $this->xml = $this->parseXml($data); + } + + /** + * Turn the raw XML response string into a SimpleXMLElement + * + * @param string $data + * @return \SimpleXMLElement + */ + public function parseXml($data) + { + $data = str_replace(' ', ' ', $data); + $data = str_replace("\n", '', $data); + $data = str_replace("\r", '', $data); + + return new \SimpleXMLElement($data); + } } diff --git a/src/Omnipay/Realex/Message/SavedAuthRequest.php b/src/Omnipay/Realex/Message/SavedAuthRequest.php index 1865199..1f287d8 100644 --- a/src/Omnipay/Realex/Message/SavedAuthRequest.php +++ b/src/Omnipay/Realex/Message/SavedAuthRequest.php @@ -8,156 +8,167 @@ /** * Realex Auth Request */ -class SavedAuthRequest extends RemoteAbstractRequest { - - public function getCavv() { - return $this->getParameter('cavv'); - } - - public function setCavv($value) { - return $this->setParameter('cavv', $value); - } - - public function getEci() { - return $this->getParameter('eci'); - } - - public function setEci($value) { - return $this->setParameter('eci', $value); - } - - public function getXid() { - return $this->getParameter('xid'); - } - - public function setXid($value) { - return $this->setParameter('xid', $value); - } - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('amount', 'currency', 'transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.{$this->getCustomerRef()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'receipt-in'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->setAttribute('currency', $this->getCurrency()); - $amountEl->appendChild($domTree->createTextNode($amount)); - $root->appendChild($amountEl); - - $paymentDataEl = $domTree->createElement('paymentdata'); - $cvnEl = $domTree->createElement('cvn'); - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getCvv())); - - $cvnEl->appendChild($numberEl); - $paymentDataEl->appendChild($cvnEl); - $root->appendChild($paymentDataEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $root->appendChild($payerRefEl); - - $paymentMethodEl = $domTree->createElement('paymentmethod'); - $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); - $root->appendChild($paymentMethodEl); - - $settleEl = $domTree->createElement('autosettle'); - $settleEl->setAttribute('flag', 1); - $root->appendChild($settleEl); - - // 3D Secure section - $mpiEl = $domTree->createElement('mpi'); - $cavvEl = $domTree->createElement('cavv'); - $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); - $xidEl = $domTree->createElement('xid'); - $xidEl->appendChild($domTree->createTextNode($this->getXid())); - $eciEl = $domTree->createElement('eci'); - $eciEl->appendChild($domTree->createTextNode($this->getEci())); - $mpiEl->appendChild($cavvEl); - $mpiEl->appendChild($xidEl); - $mpiEl->appendChild($eciEl); - $root->appendChild($mpiEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $tssEl = $domTree->createElement('tssinfo'); - $addressEl = $domTree->createElement('address'); - $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - $tssEl->appendChild($addressEl); - $root->appendChild($tssEl); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new AuthResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } - +class SavedAuthRequest extends RemoteAbstractRequest +{ + public function getCavv() + { + return $this->getParameter('cavv'); + } + + public function setCavv($value) + { + return $this->setParameter('cavv', $value); + } + + public function getEci() + { + return $this->getParameter('eci'); + } + + public function setEci($value) + { + return $this->setParameter('eci', $value); + } + + public function getXid() + { + return $this->getParameter('xid'); + } + + public function setXid($value) + { + return $this->setParameter('xid', $value); + } + + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('amount', 'currency', 'transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.{$this->getCustomerRef()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'receipt-in'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->setAttribute('currency', $this->getCurrency()); + $amountEl->appendChild($domTree->createTextNode($amount)); + $root->appendChild($amountEl); + + $paymentDataEl = $domTree->createElement('paymentdata'); + $cvnEl = $domTree->createElement('cvn'); + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getCvv())); + + $cvnEl->appendChild($numberEl); + $paymentDataEl->appendChild($cvnEl); + $root->appendChild($paymentDataEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $root->appendChild($payerRefEl); + + $paymentMethodEl = $domTree->createElement('paymentmethod'); + $paymentMethodEl->appendChild($domTree->createTextNode($this->getCardReference())); + $root->appendChild($paymentMethodEl); + + $settleEl = $domTree->createElement('autosettle'); + $settleEl->setAttribute('flag', 1); + $root->appendChild($settleEl); + + // 3D Secure section + $mpiEl = $domTree->createElement('mpi'); + $cavvEl = $domTree->createElement('cavv'); + $cavvEl->appendChild($domTree->createTextNode($this->getCavv())); + $xidEl = $domTree->createElement('xid'); + $xidEl->appendChild($domTree->createTextNode($this->getXid())); + $eciEl = $domTree->createElement('eci'); + $eciEl->appendChild($domTree->createTextNode($this->getEci())); + $mpiEl->appendChild($cavvEl); + $mpiEl->appendChild($xidEl); + $mpiEl->appendChild($eciEl); + $root->appendChild($mpiEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $tssEl = $domTree->createElement('tssinfo'); + $addressEl = $domTree->createElement('address'); + $addressEl->setAttribute('type', 'billing'); + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + $tssEl->appendChild($addressEl); + $root->appendChild($tssEl); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new AuthResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/UpdateCardRequest.php b/src/Omnipay/Realex/Message/UpdateCardRequest.php index 86db8bf..b4f5fd8 100644 --- a/src/Omnipay/Realex/Message/UpdateCardRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCardRequest.php @@ -7,104 +7,109 @@ namespace Omnipay\Realex\Message; -class UpdateCardRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'card-update-card'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $cardEl = $domTree->createElement('card'); - - $cardRefEl = $domTree->createElement('ref'); - $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); - $cardEl->appendChild($cardRefEl); - - $payerRefEl = $domTree->createElement('payerref'); - $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); - $cardEl->appendChild($payerRefEl); - - $numberEl = $domTree->createElement('number'); - $numberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($numberEl); - - $expDateEl = $domTree->createElement('expdate'); - $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expDateEl); - - $chNameEl = $domTree->createElement('chname'); - $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($chNameEl); - - $typeEl = $domTree->createElement('type'); - $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($typeEl); - - $issueNoEl = $domTree->createElement('issueno'); - $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); - $cardEl->appendChild($issueNoEl); - - $root->appendChild($cardEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new UpdateCardResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } - +class UpdateCardRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef.{$card->getBillingName()}.{$card->getNumber()}"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'card-update-card'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $cardEl = $domTree->createElement('card'); + + $cardRefEl = $domTree->createElement('ref'); + $cardRefEl->appendChild($domTree->createTextNode($this->getCardReference())); + $cardEl->appendChild($cardRefEl); + + $payerRefEl = $domTree->createElement('payerref'); + $payerRefEl->appendChild($domTree->createTextNode($this->getCustomerRef())); + $cardEl->appendChild($payerRefEl); + + $numberEl = $domTree->createElement('number'); + $numberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($numberEl); + + $expDateEl = $domTree->createElement('expdate'); + $expDateEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expDateEl); + + $chNameEl = $domTree->createElement('chname'); + $chNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($chNameEl); + + $typeEl = $domTree->createElement('type'); + $typeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($typeEl); + + $issueNoEl = $domTree->createElement('issueno'); + $issueNoEl->appendChild($domTree->createTextNode($card->getIssueNumber())); + $cardEl->appendChild($issueNoEl); + + $root->appendChild($cardEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new UpdateCardResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/UpdateCardResponse.php b/src/Omnipay/Realex/Message/UpdateCardResponse.php index 6343df9..dd0a562 100644 --- a/src/Omnipay/Realex/Message/UpdateCardResponse.php +++ b/src/Omnipay/Realex/Message/UpdateCardResponse.php @@ -7,33 +7,38 @@ namespace Omnipay\Realex\Message; -class UpdateCardResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class UpdateCardResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php index 740521d..2cd75b3 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerRequest.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerRequest.php @@ -7,132 +7,137 @@ namespace Omnipay\Realex\Message; -class UpdateCustomerRequest extends RemoteAbstractRequest { - - public function getCustomerRef() { - return $this->getParameter('customerRef'); - } - - public function setCustomerRef($customerRef) { - $this->setParameter('customerRef', $customerRef); - } - - public function getData() { - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $secret = $this->getSecret(); - $payerRef = $this->getCustomerRef(); +class UpdateCustomerRequest extends RemoteAbstractRequest +{ + public function getCustomerRef() + { + return $this->getParameter('customerRef'); + } + + public function setCustomerRef($customerRef) + { + $this->setParameter('customerRef', $customerRef); + } + + public function getData() + { + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $secret = $this->getSecret(); + $payerRef = $this->getCustomerRef(); + + //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; + $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'payer-edit'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + $payerEl = $domTree->createElement('payer'); + $payerEl->setAttribute('type', 'Business'); + $payerEl->setAttribute('ref', $payerRef); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + $titleEl = $domTree->createElement('title'); + $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); + $payerEl->appendChild($titleEl); + + $firstnameEl = $domTree->createElement('firstname'); + $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); + $payerEl->appendChild($firstnameEl); + + $lastnameEl = $domTree->createElement('surname'); + $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); + $payerEl->appendChild($lastnameEl); + + $companyEl = $domTree->createElement('company'); + $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); + $payerEl->appendChild($companyEl); + + $addressEl = $domTree->createElement('address'); + + $line1El = $domTree->createElement('line1'); + $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); + $addressEl->appendChild($line1El); + + $line2El = $domTree->createElement('line2'); + $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); + $addressEl->appendChild($line2El); + + $cityEl = $domTree->createElement('city'); + $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); + $addressEl->appendChild($cityEl); + + $countyEl = $domTree->createElement('county'); + $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); + $addressEl->appendChild($countyEl); + + $postcodeEl = $domTree->createElement('postcode'); + $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); + $addressEl->appendChild($postcodeEl); + + $countryEl = $domTree->createElement('country'); + $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); + $addressEl->appendChild($countryEl); + + $payerEl->appendChild($addressEl); + + $phonenumbersEl = $domTree->createElement('phonenumbers'); + $homeEl = $domTree->createElement('home'); + $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); + $phonenumbersEl->appendChild($homeEl); + $payerEl->appendChild($phonenumbersEl); + + $emailEl = $domTree->createElement('email'); + $emailEl->appendChild($domTree->createTextNode($card->getEmail())); + $payerEl->appendChild($emailEl); + + $root->appendChild($payerEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } - //$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$payerRef"; - $tmp = "$timestamp.$merchantId.$orderId...$payerRef"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); + protected function createResponse($data) + { + return $this->response = new UpdateCustomerResponse($this, $data); + } - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'payer-edit'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - $payerEl = $domTree->createElement('payer'); - $payerEl->setAttribute('type', 'Business'); - $payerEl->setAttribute('ref', $payerRef); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - $titleEl = $domTree->createElement('title'); - $titleEl->appendChild($domTree->createTextNode($card->getBillingTitle())); - $payerEl->appendChild($titleEl); - - $firstnameEl = $domTree->createElement('firstname'); - $firstnameEl->appendChild($domTree->createTextNode($card->getBillingFirstName())); - $payerEl->appendChild($firstnameEl); - - $lastnameEl = $domTree->createElement('surname'); - $lastnameEl->appendChild($domTree->createTextNode($card->getBillingLastName())); - $payerEl->appendChild($lastnameEl); - - $companyEl = $domTree->createElement('company'); - $companyEl->appendChild($domTree->createTextNode($card->getBillingCompany())); - $payerEl->appendChild($companyEl); - - $addressEl = $domTree->createElement('address'); - - $line1El = $domTree->createElement('line1'); - $line1El->appendChild($domTree->createTextNode($card->getBillingAddress1())); - $addressEl->appendChild($line1El); - - $line2El = $domTree->createElement('line2'); - $line2El->appendChild($domTree->createTextNode($card->getBillingAddress2())); - $addressEl->appendChild($line2El); - - $cityEl = $domTree->createElement('city'); - $cityEl->appendChild($domTree->createTextNode($card->getBillingCity())); - $addressEl->appendChild($cityEl); - - $countyEl = $domTree->createElement('county'); - $countyEl->appendChild($domTree->createTextNode($card->getBillingState())); - $addressEl->appendChild($countyEl); - - $postcodeEl = $domTree->createElement('postcode'); - $postcodeEl->appendChild($domTree->createTextNode($card->getBillingPostcode())); - $addressEl->appendChild($postcodeEl); - - $countryEl = $domTree->createElement('country'); - $countryEl->appendChild($domTree->createTextNode($card->getBillingCountry())); - $addressEl->appendChild($countryEl); - - $payerEl->appendChild($addressEl); - - $phonenumbersEl = $domTree->createElement('phonenumbers'); - $homeEl = $domTree->createElement('home'); - $homeEl->appendChild($domTree->createTextNode($card->getBillingPhone())); - $phonenumbersEl->appendChild($homeEl); - $payerEl->appendChild($phonenumbersEl); - - $emailEl = $domTree->createElement('email'); - $emailEl->appendChild($domTree->createTextNode($card->getEmail())); - $payerEl->appendChild($emailEl); - - $root->appendChild($payerEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new UpdateCustomerResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } + public function getEndpoint() + { + return $this->getParameter('SecureDataVaultEndpoint'); + } + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/UpdateCustomerResponse.php b/src/Omnipay/Realex/Message/UpdateCustomerResponse.php index 71594b4..34a583e 100644 --- a/src/Omnipay/Realex/Message/UpdateCustomerResponse.php +++ b/src/Omnipay/Realex/Message/UpdateCustomerResponse.php @@ -7,33 +7,38 @@ namespace Omnipay\Realex\Message; -class UpdateCustomerResponse extends RemoteAbstractResponse { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class UpdateCustomerResponse extends RemoteAbstractResponse +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/VerifySigRequest.php b/src/Omnipay/Realex/Message/VerifySigRequest.php index 5ee1d7b..33a0241 100644 --- a/src/Omnipay/Realex/Message/VerifySigRequest.php +++ b/src/Omnipay/Realex/Message/VerifySigRequest.php @@ -9,164 +9,170 @@ /** * Realex Complete Auth Request */ -class VerifySigRequest extends RemoteAbstractRequest { - - /** - * Decode our previously-encoded Merchant Data - * - * @param string $data - * @return array - */ - protected function decodeMerchantData($data) { - $json = base64_decode($data); - $cardData = (array) json_decode($json); - - return $cardData; - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - /** - * Data will be sent from the 3D Secure provider in two fields: MD and ParRes. - * MD contains our original data (encoded by us) and PaRes will be sent to the gateway. - */ - $returnedData = $this->decodeMerchantData($this->httpRequest->request->get('MD', '')); - - $this->setTransactionId($returnedData['transactionId']); - $this->setAmount($returnedData['amount']); - $this->setCurrency($returnedData['currency']); - $this->setCard(new CreditCard($returnedData)); - - $paRes = $this->httpRequest->request->get('PaRes', ''); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); - $cardNumber = $this->getCard()->getNumber(); - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', '3ds-verifysig'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $merchantEl = $domTree->createElement('account'); - $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($merchantEl); - - // order ID - $merchantEl = $domTree->createElement('orderid'); - $merchantEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($merchantEl); - - // amount - $amountEl = $domTree->createElement('amount'); - $amountEl->appendChild($domTree->createTextNode($amount)); - $amountEl->setAttribute('currency', $this->getCurrency()); - $root->appendChild($amountEl); - - /** - * @var \Omnipay\Common\CreditCard $card - */ - $card = $this->getCard(); - - // Card details - $cardEl = $domTree->createElement('card'); - - $cardNumberEl = $domTree->createElement('number'); - $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); - $cardEl->appendChild($cardNumberEl); - - $expiryEl = $domTree->createElement('expdate'); // mmyy - $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); - $cardEl->appendChild($expiryEl); - - $cardTypeEl = $domTree->createElement('type'); - $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); - $cardEl->appendChild($cardTypeEl); - - $cardNameEl = $domTree->createElement('chname'); - $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); - $cardEl->appendChild($cardNameEl); - - $root->appendChild($cardEl); - - $paResEl = $domTree->createElement('pares'); - $paResEl->appendChild($domTree->createTextNode($paRes)); - $root->appendChild($paResEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new VerifySigResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('authEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('authEndpoint', $value); - } - - /** - * @param mixed $parameters - * - * @return AuthResponse|VerifySigResponse - */ - public function sendData($parameters) { - /** - * @var VerifySigResponse $response - */ - $response = parent::sendData($parameters); - - if ($response->isSuccessful()) { - // a few additional parameters that need to be passed for 3D-Secure transactions - $parameters = $this->getParameters(); - $parameters['cavv'] = $response->getParam('cavv'); - $parameters['eci'] = $response->getParam('eci'); - $parameters['xid'] = $response->getParam('xid'); - - /** - * Now finally, do our authorisation - * - * @var AuthRequest $request - * @var AuthResponse $response - */ - $request = new AuthRequest($this->httpClient, $this->httpRequest); - $request->initialize($parameters); - - $response = $request->send(); - } - - return $response; - } - +class VerifySigRequest extends RemoteAbstractRequest +{ + + /** + * Decode our previously-encoded Merchant Data + * + * @param string $data + * @return array + */ + protected function decodeMerchantData($data) + { + $json = base64_decode($data); + $cardData = (array) json_decode($json); + + return $cardData; + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + /** + * Data will be sent from the 3D Secure provider in two fields: MD and ParRes. + * MD contains our original data (encoded by us) and PaRes will be sent to the gateway. + */ + $returnedData = $this->decodeMerchantData($this->httpRequest->request->get('MD', '')); + + $this->setTransactionId($returnedData['transactionId']); + $this->setAmount($returnedData['amount']); + $this->setCurrency($returnedData['currency']); + $this->setCard(new CreditCard($returnedData)); + + $paRes = $this->httpRequest->request->get('PaRes', ''); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + $amount = $this->getAmountInteger(); + $currency = $this->getCurrency(); + $cardNumber = $this->getCard()->getNumber(); + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', '3ds-verifysig'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $merchantEl = $domTree->createElement('account'); + $merchantEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($merchantEl); + + // order ID + $merchantEl = $domTree->createElement('orderid'); + $merchantEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($merchantEl); + + // amount + $amountEl = $domTree->createElement('amount'); + $amountEl->appendChild($domTree->createTextNode($amount)); + $amountEl->setAttribute('currency', $this->getCurrency()); + $root->appendChild($amountEl); + + /** + * @var \Omnipay\Common\CreditCard $card + */ + $card = $this->getCard(); + + // Card details + $cardEl = $domTree->createElement('card'); + + $cardNumberEl = $domTree->createElement('number'); + $cardNumberEl->appendChild($domTree->createTextNode($card->getNumber())); + $cardEl->appendChild($cardNumberEl); + + $expiryEl = $domTree->createElement('expdate'); // mmyy + $expiryEl->appendChild($domTree->createTextNode($card->getExpiryDate("my"))); + $cardEl->appendChild($expiryEl); + + $cardTypeEl = $domTree->createElement('type'); + $cardTypeEl->appendChild($domTree->createTextNode($this->getCardBrand())); + $cardEl->appendChild($cardTypeEl); + + $cardNameEl = $domTree->createElement('chname'); + $cardNameEl->appendChild($domTree->createTextNode($card->getBillingName())); + $cardEl->appendChild($cardNameEl); + + $root->appendChild($cardEl); + + $paResEl = $domTree->createElement('pares'); + $paResEl->appendChild($domTree->createTextNode($paRes)); + $root->appendChild($paResEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new VerifySigResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('authEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('authEndpoint', $value); + } + + /** + * @param mixed $parameters + * + * @return AuthResponse|VerifySigResponse + */ + public function sendData($parameters) + { + /** + * @var VerifySigResponse $response + */ + $response = parent::sendData($parameters); + + if ($response->isSuccessful()) { + // a few additional parameters that need to be passed for 3D-Secure transactions + $parameters = $this->getParameters(); + $parameters['cavv'] = $response->getParam('cavv'); + $parameters['eci'] = $response->getParam('eci'); + $parameters['xid'] = $response->getParam('xid'); + + /** + * Now finally, do our authorisation + * + * @var AuthRequest $request + * @var AuthResponse $response + */ + $request = new AuthRequest($this->httpClient, $this->httpRequest); + $request->initialize($parameters); + + $response = $request->send(); + } + + return $response; + } } diff --git a/src/Omnipay/Realex/Message/VerifySigResponse.php b/src/Omnipay/Realex/Message/VerifySigResponse.php index febbb3a..e9905fc 100644 --- a/src/Omnipay/Realex/Message/VerifySigResponse.php +++ b/src/Omnipay/Realex/Message/VerifySigResponse.php @@ -10,75 +10,83 @@ /** * Realex Verify 3D Secure signature Response */ -class VerifySigResponse extends RemoteAbstractResponse implements RedirectResponseInterface { +class VerifySigResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + /** + * The 3D secure result is only counted as successful if is: + * - legitimate - (result = 00) + * - card holder correctly entered their password, or the 3DS systems are unavailable at the moment + */ + return ($this->xml->result == '00' && $this->xml->threedsecure->status != 'N'); + } - public function isSuccessful() { - /** - * The 3D secure result is only counted as successful if is: - * - legitimate - (result = 00) - * - card holder correctly entered their password, or the 3DS systems are unavailable at the moment - */ - return ($this->xml->result == '00' && $this->xml->threedsecure->status != 'N'); - } + /** + * Find the value of a named XML element in the response + * + * @param string $key + * @return string + */ + public function getParam($key) + { + $matches = $this->xml->xpath('//' . $key); + if (!empty($matches)) { + $value = (string) $matches[0]; + } else { + $value = ''; + } - /** - * Find the value of a named XML element in the response - * - * @param string $key - * @return string - */ - public function getParam($key) { - $matches = $this->xml->xpath('//' . $key); - if (!empty($matches)) { - $value = (string) $matches[0]; - } else { - $value = ''; - } + return $value; + } - return $value; - } + public function getMessage() + { + /** + * For some reason, the default message from the gateway + * says "Authentication Successful", even if the customer + * was shown to have used an incorrect password. For sane + * front-end reporting, let's override this. + */ + if ($this->xml->threedsecure->status == 'N') { + $message = '3D Secure Authentication Unsuccessful'; + } else { + $message = (string) $this->xml->message; + } - public function getMessage() { - /** - * For some reason, the default message from the gateway - * says "Authentication Successful", even if the customer - * was shown to have used an incorrect password. For sane - * front-end reporting, let's override this. - */ - if ($this->xml->threedsecure->status == 'N') { - $message = '3D Secure Authentication Unsuccessful'; - } else { - $message = (string) $this->xml->message; - } + return $message; + } - return $message; - } + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } + public function getTransactionReference() + { + return ($this->xml->pasref) ? $this->xml->pasref : null; + } - public function getTransactionReference() { - return ($this->xml->pasref) ? $this->xml->pasref : null; - } + public function isRedirect() + { + return false; + } - public function isRedirect() { - return false; - } + public function getRedirectMethod() + { + return 'GET'; + } - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } + public function getRedirectData() + { + return null; + } + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/Message/VoidRequest.php b/src/Omnipay/Realex/Message/VoidRequest.php index daec5fc..cb13010 100644 --- a/src/Omnipay/Realex/Message/VoidRequest.php +++ b/src/Omnipay/Realex/Message/VoidRequest.php @@ -7,98 +7,105 @@ /** * Realex Void Request */ -class VoidRequest extends RemoteAbstractRequest { - - public function getTransactionReference() { - return $this->getParameter('pasRef'); - } - - public function setTransactionReference($value) { - return $this->setParameter('pasRef', $value); - } - - public function getAuthCode() { - return $this->getParameter('authCode'); - } - - public function setAuthCode($value) { - return $this->setParameter('authCode', $value); - } - - /** - * Get the XML registration string to be sent to the gateway - * - * @return string - */ - public function getData() { - $this->validate('transactionId'); - - // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); - $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - // No amount, currency or card number for rebate requests but still needs to be in hash - $amount = ''; - $currency = ''; - $cardNumber = ''; - $secret = $this->getSecret(); - $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; - $sha1hash = sha1($tmp); - $tmp2 = "$sha1hash.$secret"; - $sha1hash = sha1($tmp2); - - $domTree = new \DOMDocument('1.0', 'UTF-8'); - - // root element - $root = $domTree->createElement('request'); - $root->setAttribute('type', 'void'); - $root->setAttribute('timestamp', $timestamp); - $root = $domTree->appendChild($root); - - // merchant ID - $merchantEl = $domTree->createElement('merchantid'); - $merchantEl->appendChild($domTree->createTextNode($merchantId)); - $root->appendChild($merchantEl); - - // account - $accountEl = $domTree->createElement('account'); - $accountEl->appendChild($domTree->createTextNode($this->getAccount())); - $root->appendChild($accountEl); - - // original order ID - $orderIdEl = $domTree->createElement('orderid'); - $orderIdEl->appendChild($domTree->createTextNode($orderId)); - $root->appendChild($orderIdEl); - - // pasref returned for original transaction - $pasRefEl = $domTree->createElement('pasref'); - $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); - $root->appendChild($pasRefEl); - - // authcode returned for original transaction - $authCodeEl = $domTree->createElement('authcode'); - $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); - $root->appendChild($authCodeEl); - - $sha1El = $domTree->createElement('sha1hash'); - $sha1El->appendChild($domTree->createTextNode($sha1hash)); - $root->appendChild($sha1El); - - $xmlString = $domTree->saveXML($root); - - return $xmlString; - } - - protected function createResponse($data) { - return $this->response = new VoidResponse($this, $data); - } - - public function getEndpoint() { - return $this->getParameter('SecureDataVaultEndpoint'); - } - - public function setAuthEndpoint($value) { - return $this->setParameter('SecureDataVaultEndpoint', $value); - } - +class VoidRequest extends RemoteAbstractRequest +{ + public function getTransactionReference() + { + return $this->getParameter('pasRef'); + } + + public function setTransactionReference($value) + { + return $this->setParameter('pasRef', $value); + } + + public function getAuthCode() + { + return $this->getParameter('authCode'); + } + + public function setAuthCode($value) + { + return $this->setParameter('authCode', $value); + } + + /** + * Get the XML registration string to be sent to the gateway + * + * @return string + */ + public function getData() + { + $this->validate('transactionId'); + + // Create the hash + $timestamp = strftime("%Y%m%d%H%M%S"); + $merchantId = $this->getMerchantId(); + $orderId = $this->getTransactionId(); + // No amount, currency or card number for rebate requests but still needs to be in hash + $amount = ''; + $currency = ''; + $cardNumber = ''; + $secret = $this->getSecret(); + $tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber"; + $sha1hash = sha1($tmp); + $tmp2 = "$sha1hash.$secret"; + $sha1hash = sha1($tmp2); + + $domTree = new \DOMDocument('1.0', 'UTF-8'); + + // root element + $root = $domTree->createElement('request'); + $root->setAttribute('type', 'void'); + $root->setAttribute('timestamp', $timestamp); + $root = $domTree->appendChild($root); + + // merchant ID + $merchantEl = $domTree->createElement('merchantid'); + $merchantEl->appendChild($domTree->createTextNode($merchantId)); + $root->appendChild($merchantEl); + + // account + $accountEl = $domTree->createElement('account'); + $accountEl->appendChild($domTree->createTextNode($this->getAccount())); + $root->appendChild($accountEl); + + // original order ID + $orderIdEl = $domTree->createElement('orderid'); + $orderIdEl->appendChild($domTree->createTextNode($orderId)); + $root->appendChild($orderIdEl); + + // pasref returned for original transaction + $pasRefEl = $domTree->createElement('pasref'); + $pasRefEl->appendChild($domTree->createTextNode($this->getTransactionReference())); + $root->appendChild($pasRefEl); + + // authcode returned for original transaction + $authCodeEl = $domTree->createElement('authcode'); + $authCodeEl->appendChild($domTree->createTextNode($this->getAuthCode())); + $root->appendChild($authCodeEl); + + $sha1El = $domTree->createElement('sha1hash'); + $sha1El->appendChild($domTree->createTextNode($sha1hash)); + $root->appendChild($sha1El); + + $xmlString = $domTree->saveXML($root); + + return $xmlString; + } + + protected function createResponse($data) + { + return $this->response = new VoidResponse($this, $data); + } + + public function getEndpoint() + { + return $this->getParameter('SecureDataVaultEndpoint'); + } + + public function setAuthEndpoint($value) + { + return $this->setParameter('SecureDataVaultEndpoint', $value); + } } diff --git a/src/Omnipay/Realex/Message/VoidResponse.php b/src/Omnipay/Realex/Message/VoidResponse.php index 1b3bbb2..7c8120d 100644 --- a/src/Omnipay/Realex/Message/VoidResponse.php +++ b/src/Omnipay/Realex/Message/VoidResponse.php @@ -10,45 +10,53 @@ /** * Realex Void Response */ -class VoidResponse extends RemoteAbstractResponse implements RedirectResponseInterface { - - public function isSuccessful() { - return ($this->xml->result == '00'); - } - - public function getMessage() { - return (string) $this->xml->message; - } - - public function getTransactionId() { - return ($this->xml->orderid) ? (string) $this->xml->orderid : null; - } - - public function getTransactionReference() { - return ($this->xml->pasref) ? (string) $this->xml->pasref : null; - } - - public function getAuthCode() { - return ($this->xml->authcode) ? (string) $this->xml->authcode : null; - } - - public function isRedirect() { - return false; - } - - public function getRedirectMethod() { - return 'GET'; - } - - public function getRedirectData() { - return null; - } - - /** - * Gets the redirect target url. - */ - public function getRedirectUrl() { - return ''; - } - +class VoidResponse extends RemoteAbstractResponse implements RedirectResponseInterface +{ + public function isSuccessful() + { + return ($this->xml->result == '00'); + } + + public function getMessage() + { + return (string) $this->xml->message; + } + + public function getTransactionId() + { + return ($this->xml->orderid) ? (string) $this->xml->orderid : null; + } + + public function getTransactionReference() + { + return ($this->xml->pasref) ? (string) $this->xml->pasref : null; + } + + public function getAuthCode() + { + return ($this->xml->authcode) ? (string) $this->xml->authcode : null; + } + + public function isRedirect() + { + return false; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return ''; + } } diff --git a/src/Omnipay/Realex/RedirectGateway.php b/src/Omnipay/Realex/RedirectGateway.php index 4fd2afc..bddba27 100644 --- a/src/Omnipay/Realex/RedirectGateway.php +++ b/src/Omnipay/Realex/RedirectGateway.php @@ -7,76 +7,91 @@ /** * Realex Redirect Class */ -class RedirectGateway extends AbstractGateway { - - public function getName() { - return 'Realex Redirect'; - } - - public function getDefaultParameters() { - return array( - 'merchantId' => '', - 'secret' => '', - 'account' => 'internet', - 'testMode' => false, - 'checkoutEndpoint' => 'https://hpp.realexpayments.com/pay', - ); - } - - public function getMerchantId() { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) { - return $this->setParameter('merchantId', $value); - } - - public function getSecret() { - return $this->getParameter('secret'); - } - - public function setSecret($value) { - return $this->setParameter('secret', $value); - } - - public function getAccount() { - return $this->getParameter('account'); - } - - public function setAccount($value) { - return $this->setParameter('account', $value); - } - - public function getCheckoutEndpoint() { - return $this->getParameter('checkoutEndpoint'); - } - - public function setCheckoutEndpoint($value) { - return $this->setParameter('checkoutEndpoint', $value); - } - - public function authorize(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectAuthorizeRequest', $parameters); - } - - public function completeAuthorize(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteAuthorizeRequest', $parameters); - } - - public function purchase(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectPurchaseRequest', $parameters); - } - - public function completePurchase(array $parameters = array()) { - return $this->completeAuthorize($parameters); - } - - public function storeCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectStoreCardRequest', $parameters); - } - - public function completeStoreCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteStoreCardRequest', $parameters); - } - +class RedirectGateway extends AbstractGateway +{ + public function getName() + { + return 'Realex Redirect'; + } + + public function getDefaultParameters() + { + return array( + 'merchantId' => '', + 'secret' => '', + 'account' => 'internet', + 'testMode' => false, + 'checkoutEndpoint' => 'https://hpp.realexpayments.com/pay', + ); + } + + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getCheckoutEndpoint() + { + return $this->getParameter('checkoutEndpoint'); + } + + public function setCheckoutEndpoint($value) + { + return $this->setParameter('checkoutEndpoint', $value); + } + + public function authorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectAuthorizeRequest', $parameters); + } + + public function completeAuthorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteAuthorizeRequest', $parameters); + } + + public function purchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectPurchaseRequest', $parameters); + } + + public function completePurchase(array $parameters = array()) + { + return $this->completeAuthorize($parameters); + } + + public function storeCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectStoreCardRequest', $parameters); + } + + public function completeStoreCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\Redirect\RedirectCompleteStoreCardRequest', $parameters); + } } diff --git a/src/Omnipay/Realex/RemoteGateway.php b/src/Omnipay/Realex/RemoteGateway.php index 138520c..f5453bb 100644 --- a/src/Omnipay/Realex/RemoteGateway.php +++ b/src/Omnipay/Realex/RemoteGateway.php @@ -12,152 +12,178 @@ /** * Realex Remote Gateway */ -class RemoteGateway extends AbstractGateway { - - public function getName() { - return 'Realex Remote'; - } - - public function getDefaultParameters() { - return array( - 'merchantId' => '', - 'account' => '', - 'secret' => '', - '3dSecure' => 0, - 'authEndpoint' => 'https://epage.payandshop.com/epage-remote.cgi', - 'secureDataVaultEndpoint' => 'https://epage.payandshop.com/epage-remote-plugins.cgi', - '3dSecureEndpoint' => 'https://epage.payandshop.com/epage-3dsecure.cgi' - ); - } - - public function getMerchantId() { - return $this->getParameter('merchantId'); - } - - public function setMerchantId($value) { - return $this->setParameter('merchantId', $value); - } - - public function getAccount() { - return $this->getParameter('account'); - } - - public function setAccount($value) { - return $this->setParameter('account', $value); - } - - public function getSecret() { - return $this->getParameter('secret'); - } - - public function setSecret($value) { - return $this->setParameter('secret', $value); - } - - public function getRefundPassword() { - return $this->getParameter('refundPassword'); - } - - /** - * Although Omnipay terminology deals with 'refunds', you need - * to actually supply the 'rebate' password that Realex gives you - * in order for this to work. - * - * @param string $value The 'rebate' password supplied by Realex - * - * @return $this - */ - public function setRefundPassword($value) { - return $this->setParameter('refundPassword', $value); - } - - public function get3dSecure() { - return $this->getParameter('3dSecure'); - } - - public function set3dSecure($value) { - return $this->setParameter('3dSecure', $value); - } - - public function purchase(array $parameters = array()) { - - if (array_key_exists('cardReference', $parameters)) { - return $this->createRequest('\Omnipay\Realex\Message\SavedAuthRequest', $parameters); - } elseif ($this->get3dSecure()) { - return $this->createRequest('\Omnipay\Realex\Message\EnrolmentRequest', $parameters); - } else { - return $this->createRequest('\Omnipay\Realex\Message\AuthRequest', $parameters); - } - } - - /** - * This will always be called as the result of returning from 3D Secure. - * Verify that the 3D Secure message we've received is legit - */ - public function completePurchase(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\VerifySigRequest', $parameters); - } - - public function refund(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\RefundRequest', $parameters); - } - - public function void(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\VoidRequest', $parameters); - } - - public function fetchTransaction(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\FetchTransactionRequest', $parameters); - } - - /** - * Create/update/delete card/customer details - */ - public function createCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\CreateCardRequest', $parameters); - } - - public function updateCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\UpdateCardRequest', $parameters); - } - - public function deleteCard(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\DeleteCardRequest', $parameters); - } - - public function createCustomer(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\CreateCustomerRequest', $parameters); - } - - public function updateCustomer(array $parameters = array()) { - return $this->createRequest('\Omnipay\Realex\Message\UpdateCustomerRequest', $parameters); - } - - /** - * Setup service endpoint links for different realex service providers - */ - public function setAuthEndpoint($value) { - return $this->setParameter('authEndpoint', $value); - } - - public function getAuthEndpoint() { - return $this->getParameter('authEndpoint'); - } - - public function setSecureDataVaultEndpoint($value) { - return $this->setParameter('secureDataVaultEndpoint', $value); - } - - public function getSecureDataVaultEndpoint() { - return $this->getParameter('secureDataVaultEndpoint'); - } - - public function set3DSecureEndpoint($value) { - return $this->setParameter('3dSecureEndpoint', $value); - } - - public function get3DSecureEndpoint() { - return $this->getParameter('3dSecureEndpoint'); - } - +class RemoteGateway extends AbstractGateway +{ + public function getName() + { + return 'Realex Remote'; + } + + public function getDefaultParameters() + { + return array( + 'merchantId' => '', + 'account' => '', + 'secret' => '', + '3dSecure' => 0, + 'authEndpoint' => 'https://epage.payandshop.com/epage-remote.cgi', + 'secureDataVaultEndpoint' => 'https://epage.payandshop.com/epage-remote-plugins.cgi', + '3dSecureEndpoint' => 'https://epage.payandshop.com/epage-3dsecure.cgi' + ); + } + + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + public function getAccount() + { + return $this->getParameter('account'); + } + + public function setAccount($value) + { + return $this->setParameter('account', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getRefundPassword() + { + return $this->getParameter('refundPassword'); + } + + /** + * Although Omnipay terminology deals with 'refunds', you need + * to actually supply the 'rebate' password that Realex gives you + * in order for this to work. + * + * @param string $value The 'rebate' password supplied by Realex + * + * @return $this + */ + public function setRefundPassword($value) + { + return $this->setParameter('refundPassword', $value); + } + + public function get3dSecure() + { + return $this->getParameter('3dSecure'); + } + + public function set3dSecure($value) + { + return $this->setParameter('3dSecure', $value); + } + + public function purchase(array $parameters = array()) + { + if (array_key_exists('cardReference', $parameters)) { + return $this->createRequest('\Omnipay\Realex\Message\SavedAuthRequest', $parameters); + } elseif ($this->get3dSecure()) { + return $this->createRequest('\Omnipay\Realex\Message\EnrolmentRequest', $parameters); + } else { + return $this->createRequest('\Omnipay\Realex\Message\AuthRequest', $parameters); + } + } + + /** + * This will always be called as the result of returning from 3D Secure. + * Verify that the 3D Secure message we've received is legit + */ + public function completePurchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\VerifySigRequest', $parameters); + } + + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\RefundRequest', $parameters); + } + + public function void(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\VoidRequest', $parameters); + } + + public function fetchTransaction(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\FetchTransactionRequest', $parameters); + } + + /** + * Create/update/delete card/customer details + */ + public function createCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\CreateCardRequest', $parameters); + } + + public function updateCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\UpdateCardRequest', $parameters); + } + + public function deleteCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\DeleteCardRequest', $parameters); + } + + public function createCustomer(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\CreateCustomerRequest', $parameters); + } + + public function updateCustomer(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Realex\Message\UpdateCustomerRequest', $parameters); + } + + /** + * Setup service endpoint links for different realex service providers + */ + public function setAuthEndpoint($value) + { + return $this->setParameter('authEndpoint', $value); + } + + public function getAuthEndpoint() + { + return $this->getParameter('authEndpoint'); + } + + public function setSecureDataVaultEndpoint($value) + { + return $this->setParameter('secureDataVaultEndpoint', $value); + } + + public function getSecureDataVaultEndpoint() + { + return $this->getParameter('secureDataVaultEndpoint'); + } + + public function set3DSecureEndpoint($value) + { + return $this->setParameter('3dSecureEndpoint', $value); + } + + public function get3DSecureEndpoint() + { + return $this->getParameter('3dSecureEndpoint'); + } } From 6a9b41e7a55a95d9d695427e05f7696a938cc385 Mon Sep 17 00:00:00 2001 From: 3dgroup Date: Mon, 18 May 2020 15:26:25 +0100 Subject: [PATCH 25/29] Rename response.php to Response.php --- .../Realex/Message/Redirect/{response.php => Response.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Omnipay/Realex/Message/Redirect/{response.php => Response.php} (100%) diff --git a/src/Omnipay/Realex/Message/Redirect/response.php b/src/Omnipay/Realex/Message/Redirect/Response.php similarity index 100% rename from src/Omnipay/Realex/Message/Redirect/response.php rename to src/Omnipay/Realex/Message/Redirect/Response.php From 6e6e5424bb0f359a68e3b63f70f43a92e5d27ac5 Mon Sep 17 00:00:00 2001 From: 3dgroup Date: Thu, 15 Oct 2020 17:31:14 +0100 Subject: [PATCH 26/29] Add script timeout Elavon servers went down causing paying scripts to hang. Adding this frees the resources. --- src/Omnipay/Realex/Message/RemoteAbstractRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php index aaf66a5..d3e75a2 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php @@ -83,7 +83,7 @@ public function sendData($data) ) ); - $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data,['timeout' => 7,'connect_timeout' => 7])->send(); return $this->createResponse($httpResponse->getBody(true)); } From d534dac8bbe35ca8dccf06638ad6e8083d43ceb3 Mon Sep 17 00:00:00 2001 From: 3dgroup Date: Thu, 5 May 2022 19:00:16 +0100 Subject: [PATCH 27/29] Update dataVaultResponse.php --- src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php index 64d1aac..6b0dcda 100644 --- a/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php +++ b/src/Omnipay/Realex/Message/Redirect/dataVaultResponse.php @@ -29,7 +29,7 @@ public function isSuccessful() public function getMessage() { - $message; + $message = ''; if (isset($this->data['PMT_SETUP_MSG'])) { $message .= $this->data['PMT_SETUP_MSG'] . ' '; } From 1e71f2894a81f9029cb3ab774ef9df036c9e8481 Mon Sep 17 00:00:00 2001 From: 3dgroup Date: Thu, 5 May 2022 19:01:39 +0100 Subject: [PATCH 28/29] Update RedirectCompleteStoreCardRequest.php --- .../Message/Redirect/RedirectCompleteStoreCardRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php index f3d3702..de711ba 100644 --- a/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php +++ b/src/Omnipay/Realex/Message/Redirect/RedirectCompleteStoreCardRequest.php @@ -11,8 +11,8 @@ class RedirectCompleteStoreCardRequest extends AbstractRequest { public function getData() { - $data; - foreach (json_decode($this->httpRequest->request->get('hppResponse')) as $key => $value) { + $data = []; + foreach (json_decode($_POST['hppResponse']) as $key => $value) { $data[$key] = base64_decode($value); } From 23333f86c9b7c6e22e0771261700949b5a9b4bd9 Mon Sep 17 00:00:00 2001 From: 3dgroup Date: Tue, 27 Aug 2024 11:35:54 +0100 Subject: [PATCH 29/29] Update RemoteAbstractRequest.php --- src/Omnipay/Realex/Message/RemoteAbstractRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php index d3e75a2..fae6e5b 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php @@ -83,7 +83,7 @@ public function sendData($data) ) ); - $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data,['timeout' => 7,'connect_timeout' => 7])->send(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data,['timeout' => 30,'connect_timeout' => 30])->send(); return $this->createResponse($httpResponse->getBody(true)); }