diff --git a/composer.json b/composer.json index f5d1146..653ad69 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,12 @@ } ], "autoload": { - "psr-0": { "Omnipay\\Realex\\" : "src/" } + "psr-4": { "Omnipay\\Realex\\" : "src/" } }, "require": { - "omnipay/common": "~2.0" + "omnipay/common": "^3" }, "require-dev": { - "squizlabs/php_codesniffer": "~1.4.4" + "squizlabs/php_codesniffer": "^3" } } diff --git a/src/Omnipay/Realex/Message/AuthRequest.php b/src/Omnipay/Realex/Message/AuthRequest.php index 5e224f8..f2ced4d 100644 --- a/src/Omnipay/Realex/Message/AuthRequest.php +++ b/src/Omnipay/Realex/Message/AuthRequest.php @@ -12,31 +12,16 @@ class AuthRequest extends RemoteAbstractRequest { protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi'; - 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); @@ -52,17 +37,18 @@ public function getData() $this->validate('amount', 'currency', 'transactionId'); // Create the hash - $timestamp = strftime("%Y%m%d%H%M%S"); + $timestamp = strftime("%Y%m%d%H%M%S"); $merchantId = $this->getMerchantId(); - $orderId = $this->getTransactionId(); - $amount = $this->getAmountInteger(); - $currency = $this->getCurrency(); + $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); + $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'); @@ -93,6 +79,7 @@ public function getData() * @var \Omnipay\Common\CreditCard $card */ $card = $this->getCard(); + $this->setCode($card->getBillingPostcode(), $card->getBillingAddress1()); // Card details $cardEl = $domTree->createElement('card'); @@ -129,10 +116,10 @@ public function getData() $root->appendChild($settleEl); // 3D Secure section - $mpiEl = $domTree->createElement('mpi'); + $mpiEl = $domTree->createElement('mpi'); $cavvEl = $domTree->createElement('cavv', $this->getCavv()); - $xidEl = $domTree->createElement('xid', $this->getXid()); - $eciEl = $domTree->createElement('eci', $this->getEci()); + $xidEl = $domTree->createElement('xid', $this->getXid()); + $eciEl = $domTree->createElement('eci', $this->getEci()); $mpiEl->appendChild($cavvEl); $mpiEl->appendChild($xidEl); $mpiEl->appendChild($eciEl); @@ -141,11 +128,13 @@ public function getData() $sha1El = $domTree->createElement('sha1hash', $sha1hash); $root->appendChild($sha1El); - $tssEl = $domTree->createElement('tssinfo'); + $tssEl = $domTree->createElement('tssinfo'); $addressEl = $domTree->createElement('address'); $addressEl->setAttribute('type', 'billing'); - $countryEl = $domTree->createElement('country', $card->getBillingCountry()); + $countryEl = $domTree->createElement('country', $card->getBillingCountry()); + $postcodeEl = $domTree->createElement('code', $this->getCode()); $addressEl->appendChild($countryEl); + $addressEl->appendChild($postcodeEl); $tssEl->appendChild($addressEl); $root->appendChild($tssEl); @@ -154,13 +143,28 @@ public function getData() return $xmlString; } - protected function createResponse($data) + public function getCavv() { - return $this->response = new AuthResponse($this, $data); + return $this->getParameter('cavv'); + } + + public function getXid() + { + return $this->getParameter('xid'); + } + + public function getEci() + { + return $this->getParameter('eci'); } public function getEndpoint() { return $this->endpoint; } + + protected function createResponse($data) + { + return $this->response = new AuthResponse($this, $data); + } } diff --git a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php index 22f302a..30070ef 100644 --- a/src/Omnipay/Realex/Message/RemoteAbstractRequest.php +++ b/src/Omnipay/Realex/Message/RemoteAbstractRequest.php @@ -11,24 +11,26 @@ abstract class RemoteAbstractRequest extends AbstractRequest { protected $cardBrandMap = array( - 'mastercard' => 'mc', - 'diners_club' => 'diners' + 'mastercard' => 'mc', + 'diners_club' => 'diners', ); - /** - * Override some of the default Omnipay card brand names - * - * @return mixed - */ - protected function getCardBrand() + public function getCode() { - $brand = $this->getCard()->getBrand(); + return $this->getParameter('code'); + } - if (isset($this->cardBrandMap[$brand])) { - $brand = $this->cardBrandMap[$brand]; - } + public function setCode($postcode, $billingAddressLine1) + { + $postcode = $this->stripNonNumeric($postcode); + $billingAddressLine1 = $this->stripNonNumeric($billingAddressLine1); - return strtoupper($brand); + return $this->setParameter('code', $postcode . '|' . $billingAddressLine1); + } + + public function stripNonNumeric($value) + { + return preg_replace("/[^0-9]/", "", $value); } public function getMerchantId() @@ -74,20 +76,39 @@ public function setReturnUrl($value) public function sendData($data) { // register the payment - $this->httpClient->setConfig( - array( - 'curl.options' => array( - 'CURLOPT_SSLVERSION' => 1, - 'CURLOPT_SSL_VERIFYPEER' => false - ) - ) + $headers = array( + 'curl' => array( + CURLOPT_SSLVERSION => 1, + CURLOPT_SSL_VERIFYPEER => false, + ), ); - $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); - return $this->createResponse($httpResponse->getBody(true)); + if (is_array($data)) { + $data = http_build_query($data); + } + + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); + + return $this->createResponse($httpResponse->getBody()->getContents()); } abstract public function getEndpoint(); abstract protected function createResponse($data); + + /** + * 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); + } }