From f0e23eb24556e48f7d57852fb290a0b05bcb7aa9 Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Fri, 12 Jan 2018 16:20:46 +0100 Subject: [PATCH 01/11] feature: Add optional params uppReturnMaskedCC and useAlias to obtain additional data from purchase request --- src/Message/AbstractRedirectRequest.php | 22 ++++++++++++++++++++-- tests/Message/PurchaseRequestTest.php | 8 ++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Message/AbstractRedirectRequest.php b/src/Message/AbstractRedirectRequest.php index 9fa8203..717f544 100644 --- a/src/Message/AbstractRedirectRequest.php +++ b/src/Message/AbstractRedirectRequest.php @@ -22,7 +22,8 @@ abstract class AbstractRedirectRequest extends AbstractRequest * @var array */ protected $optionalParams = array( - + 'uppReturnMaskedCC', + 'useAlias' ); /** @@ -43,7 +44,7 @@ public function getData() foreach ($this->optionalParams as $param) { $value = $this->getParameter($param); - if ($value !== '') { + if (!empty($value)) { $data[$param] = $value; } } @@ -91,4 +92,21 @@ public function sendData($data) { return $this->response = new PurchaseResponse($this, $data); } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUppReturnMaskedCC($value) + { + return $this->setParameter('uppReturnMaskedCC', $value); + } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUseAlias($value){ + return $this->setParameter('useAlias', $value); + } } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index e62f5e6..9babf58 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -30,7 +30,9 @@ public function testGetDataWithoutCard() 'transactionId' => '123', 'returnUrl' => 'https://www.example.com/success', 'errorUrl' => 'https://www.example.com/error', - 'cancelUrl' => 'https://www.example.com/cancel' + 'cancelUrl' => 'https://www.example.com/cancel', + 'uppReturnMaskedCC' => 'yes', + 'useAlias' => 'yes' )); $expected = array( @@ -41,7 +43,9 @@ public function testGetDataWithoutCard() 'sign' => '123', 'successUrl' => 'https://www.example.com/success', 'errorUrl' => 'https://www.example.com/error', - 'cancelUrl' => 'https://www.example.com/cancel' + 'cancelUrl' => 'https://www.example.com/cancel', + 'uppReturnMaskedCC' => 'yes', + 'useAlias' => 'yes' ); $this->assertEquals($expected, $this->request->getData()); From b3548fc69d73647a72d67025ffa2b71880b522a6 Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Fri, 12 Jan 2018 16:20:46 +0100 Subject: [PATCH 02/11] feature: Add optional params uppReturnMaskedCC and useAlias to obtain additional data from purchase request --- src/Message/AbstractRedirectRequest.php | 22 ++++++++++++++++++++-- tests/Message/PurchaseRequestTest.php | 7 +++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Message/AbstractRedirectRequest.php b/src/Message/AbstractRedirectRequest.php index 9fa8203..717f544 100644 --- a/src/Message/AbstractRedirectRequest.php +++ b/src/Message/AbstractRedirectRequest.php @@ -22,7 +22,8 @@ abstract class AbstractRedirectRequest extends AbstractRequest * @var array */ protected $optionalParams = array( - + 'uppReturnMaskedCC', + 'useAlias' ); /** @@ -43,7 +44,7 @@ public function getData() foreach ($this->optionalParams as $param) { $value = $this->getParameter($param); - if ($value !== '') { + if (!empty($value)) { $data[$param] = $value; } } @@ -91,4 +92,21 @@ public function sendData($data) { return $this->response = new PurchaseResponse($this, $data); } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUppReturnMaskedCC($value) + { + return $this->setParameter('uppReturnMaskedCC', $value); + } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUseAlias($value){ + return $this->setParameter('useAlias', $value); + } } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index e62f5e6..e3cd939 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -30,7 +30,9 @@ public function testGetDataWithoutCard() 'transactionId' => '123', 'returnUrl' => 'https://www.example.com/success', 'errorUrl' => 'https://www.example.com/error', - 'cancelUrl' => 'https://www.example.com/cancel' + 'cancelUrl' => 'https://www.example.com/cancel', + 'uppReturnMaskedCC' => 'yes', + 'useAlias' => '' )); $expected = array( @@ -41,7 +43,8 @@ public function testGetDataWithoutCard() 'sign' => '123', 'successUrl' => 'https://www.example.com/success', 'errorUrl' => 'https://www.example.com/error', - 'cancelUrl' => 'https://www.example.com/cancel' + 'cancelUrl' => 'https://www.example.com/cancel', + 'uppReturnMaskedCC' => 'yes' ); $this->assertEquals($expected, $this->request->getData()); From 64fa189abff3375b8f50b4039c156ca10705f048 Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Mon, 15 Jan 2018 08:58:40 +0100 Subject: [PATCH 03/11] fix: Codesniffer travis error --- src/Message/AbstractRedirectRequest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Message/AbstractRedirectRequest.php b/src/Message/AbstractRedirectRequest.php index 717f544..4781c86 100644 --- a/src/Message/AbstractRedirectRequest.php +++ b/src/Message/AbstractRedirectRequest.php @@ -23,7 +23,7 @@ abstract class AbstractRedirectRequest extends AbstractRequest */ protected $optionalParams = array( 'uppReturnMaskedCC', - 'useAlias' + 'useAlias', ); /** @@ -38,7 +38,7 @@ public function getData() 'refno' => $this->getTransactionId(), 'amount' => $this->getAmountInteger(), 'currency' => $this->getCurrency(), - 'sign' => $this->getSign() + 'sign' => $this->getSign(), ); foreach ($this->optionalParams as $param) { @@ -106,7 +106,8 @@ public function setUppReturnMaskedCC($value) * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ - public function setUseAlias($value){ + public function setUseAlias($value) + { return $this->setParameter('useAlias', $value); } } From d798d021fcaa936c954357a6d6862711d2346737 Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Thu, 25 Jan 2018 11:13:28 +0100 Subject: [PATCH 04/11] fix: Fix wrong service urls --- src/Message/AbstractResponse.php | 4 ++-- src/Message/XmlRequest.php | 4 ++-- tests/GatewayTest.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index e4a9925..7bf9cc6 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -25,12 +25,12 @@ abstract class AbstractResponse extends OmnipayAbstractResponse implements Redir /** * @var string */ - protected $productionEndpoint = 'https://payment.datatrans.biz/upp/jsp/upStart.jsp'; + protected $productionEndpoint = 'https://pay.datatrans.com/upp/jsp/upStart.jsp'; /** * @var string */ - protected $testEndpoint = 'https://pay.datatrans.com/upp/jsp/upStart.jsp'; + protected $testEndpoint = 'https://pay.sandbox.datatrans.com/upp/jsp/upStart.jsp'; /*** STATUS CODES ****/ /** diff --git a/src/Message/XmlRequest.php b/src/Message/XmlRequest.php index fd66377..c3960da 100644 --- a/src/Message/XmlRequest.php +++ b/src/Message/XmlRequest.php @@ -27,13 +27,13 @@ abstract class XmlRequest extends AbstractRequest * * @var string */ - protected $apiBaseProdUrl = 'https://api.sandbox.datatrans.com/upp/jsp'; + protected $apiBaseProdUrl = 'https://api.datatrans.com/upp/jsp'; /** * The XML API Endpoint Base URL * * @var string */ - protected $apiBaseTestUrl = 'https://pay.sandbox.datatrans.com/upp/jsp'; + protected $apiBaseTestUrl = 'https://api.sandbox.datatrans.com/upp/jsp'; /** * defines the endpoint for a specific api diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index f17a968..90d409c 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -51,7 +51,7 @@ public function testPurchase() $this->assertTrue($response->isRedirect()); $this->assertEquals('POST', $response->getRedirectMethod()); $this->assertEquals($data, $response->getRedirectData()); - $this->assertStringStartsWith('https://pay.datatrans.com/upp/jsp/upStart.jsp', $response->getRedirectUrl()); + $this->assertStringStartsWith('https://pay.sandbox.datatrans.com/upp/jsp/upStart.jsp', $response->getRedirectUrl()); } public function testCompletePurchaseSuccess() From 9b75d90d7abb4dbf00c9091e9b16d7d8d2869b28 Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Mon, 5 Feb 2018 08:59:54 +0100 Subject: [PATCH 05/11] feature: Allow using alias in authorizaion request --- src/Message/XmlAuthorizationRequest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Message/XmlAuthorizationRequest.php b/src/Message/XmlAuthorizationRequest.php index 6fd8f14..c116aff 100644 --- a/src/Message/XmlAuthorizationRequest.php +++ b/src/Message/XmlAuthorizationRequest.php @@ -26,7 +26,8 @@ class XmlAuthorizationRequest extends XmlRequest */ protected $optionalParameters = array( 'reqtype', - 'uppCustomerIpAddress' + 'uppCustomerIpAddress', + 'useAlias' ); /** @@ -57,7 +58,7 @@ public function getData() 'aliasCC' => $this->getCard()->getNumber(), 'expm' => $this->getCard()->getExpiryMonth(), 'expy' => $this->getCard()->getExpiryDate('y'), - 'useAlias' => 'no' + 'useAlias' => 'no' ); foreach ($this->optionalParameters as $param) { @@ -79,4 +80,13 @@ protected function createResponse($data) { return $this->response = new XmlAuthorizationResponse($this, $data); } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUseAlias($value) + { + return $this->setParameter('useAlias', $value); + } } From 1cf5decdc35a3f52dbeeafe65a6bea9f461930e7 Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Thu, 8 Feb 2018 16:18:34 +0100 Subject: [PATCH 06/11] feat: Allow setting Customerdetails to be stored in web admin tool of datatrans --- src/Message/AbstractRedirectRequest.php | 27 ++----------- src/Message/PurchaseRequest.php | 51 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/Message/AbstractRedirectRequest.php b/src/Message/AbstractRedirectRequest.php index 4781c86..e831aa6 100644 --- a/src/Message/AbstractRedirectRequest.php +++ b/src/Message/AbstractRedirectRequest.php @@ -22,8 +22,7 @@ abstract class AbstractRedirectRequest extends AbstractRequest * @var array */ protected $optionalParams = array( - 'uppReturnMaskedCC', - 'useAlias', + ); /** @@ -38,13 +37,13 @@ public function getData() 'refno' => $this->getTransactionId(), 'amount' => $this->getAmountInteger(), 'currency' => $this->getCurrency(), - 'sign' => $this->getSign(), + 'sign' => $this->getSign() ); foreach ($this->optionalParams as $param) { $value = $this->getParameter($param); - if (!empty($value)) { + if ($value !== '') { $data[$param] = $value; } } @@ -92,22 +91,4 @@ public function sendData($data) { return $this->response = new PurchaseResponse($this, $data); } - - /** - * @param $value - * @return \Omnipay\Common\Message\AbstractRequest - */ - public function setUppReturnMaskedCC($value) - { - return $this->setParameter('uppReturnMaskedCC', $value); - } - - /** - * @param $value - * @return \Omnipay\Common\Message\AbstractRequest - */ - public function setUseAlias($value) - { - return $this->setParameter('useAlias', $value); - } -} +} \ No newline at end of file diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 64c583c..962a82b 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -16,5 +16,56 @@ class PurchaseRequest extends AbstractRedirectRequest { + /** + * @var array + */ + protected $optionalParams = array( + 'useAlias', + 'uppReturnMaskedCC' + ); + /** + * @return array + */ + public function getData() + { + $data = parent::getData(); + + //set customer details if set + if (($customerDetails = $this->getParameter('uppCustomerDetails')) && is_array($customerDetails)){ + $data['uppCustomerDetails'] = 'yes'; + foreach ($customerDetails as $key => $value){ + $data[$key] = $value; + } + } + + return $data; + } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUppReturnMaskedCC($value) + { + return $this->setParameter('uppReturnMaskedCC', $value); + } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUseAlias($value) + { + return $this->setParameter('useAlias', $value); + } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUppCustomerDetails($value) + { + return $this->setParameter('uppCustomerDetails', $value); + } } From 3c0bf9c03fcb04e4742f3afdcc3e2a2e0b255a3b Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Tue, 13 Feb 2018 13:43:58 +0100 Subject: [PATCH 07/11] fix: Check if optional parameters are not empty instead of empty string to avoid null values in data --- src/Message/AbstractRedirectRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/AbstractRedirectRequest.php b/src/Message/AbstractRedirectRequest.php index e831aa6..84d5763 100644 --- a/src/Message/AbstractRedirectRequest.php +++ b/src/Message/AbstractRedirectRequest.php @@ -43,7 +43,7 @@ public function getData() foreach ($this->optionalParams as $param) { $value = $this->getParameter($param); - if ($value !== '') { + if (!empty($value)) { $data[$param] = $value; } } @@ -91,4 +91,4 @@ public function sendData($data) { return $this->response = new PurchaseResponse($this, $data); } -} \ No newline at end of file +} From 550b6e9cbd3aac744f09cf9bf26302404e404b44 Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Tue, 13 Feb 2018 13:44:30 +0100 Subject: [PATCH 08/11] fix: PSR-2 compliance --- src/Message/PurchaseRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 962a82b..266ac73 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -32,9 +32,9 @@ public function getData() $data = parent::getData(); //set customer details if set - if (($customerDetails = $this->getParameter('uppCustomerDetails')) && is_array($customerDetails)){ + if (($customerDetails = $this->getParameter('uppCustomerDetails')) && is_array($customerDetails)) { $data['uppCustomerDetails'] = 'yes'; - foreach ($customerDetails as $key => $value){ + foreach ($customerDetails as $key => $value) { $data[$key] = $value; } } From d6e025c857df0985893fa47c08b64e8bb7e1ec6b Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Tue, 29 May 2018 16:59:05 +0200 Subject: [PATCH 09/11] test: add test for aliasCC and maskedCC --- tests/Mock/XmlAuthorizationAliasSuccess.txt | 40 +++++++++++++++++++++ tests/XmlGatewayTest.php | 20 +++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/Mock/XmlAuthorizationAliasSuccess.txt diff --git a/tests/Mock/XmlAuthorizationAliasSuccess.txt b/tests/Mock/XmlAuthorizationAliasSuccess.txt new file mode 100644 index 0000000..2628a18 --- /dev/null +++ b/tests/Mock/XmlAuthorizationAliasSuccess.txt @@ -0,0 +1,40 @@ +HTTP/1.1 200 OK +Expires: Sat, 6 May 1995 12:00:00 GMT +Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 +Pragma: no-cache +P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +Strict-Transport-Security: max-age=15768000; includeSubdomains +X-XSS-Protection: 1; mode=block +Content-Type: text/xml;charset=UTF-8 +Content-Length: 1091 +Date: Tue, 10 Jan 2017 14:45:02 GMT +Server: - + + + + + + + 10000 + CHF + 13820602628130529 + yes + 12 + 18 + no + TEST-SIGN-123 + NOA + + + 01 + Authorized + 44E89981F8714392Y + 123 + 123 + 490000xxxxxx0086 + CH + 13820602628130529 + + + + \ No newline at end of file diff --git a/tests/XmlGatewayTest.php b/tests/XmlGatewayTest.php index d21fc69..fe16640 100644 --- a/tests/XmlGatewayTest.php +++ b/tests/XmlGatewayTest.php @@ -50,6 +50,26 @@ public function testAuthorize() $this->assertEquals('Authorized', $response->getMessage()); } + public function testAuthorizeAlias() + { + $this->setMockHttpResponse('XmlAuthorizationAliasSuccess.txt'); + + $this->options = array_merge($this->options, array( + 'useAlias' => 'yes', + 'uppReturnMaskedCC' => 'yes' + )); + + $response = $this->gateway->authorize($this->options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('Authorized', $response->getMessage()); + + //check for alias and masked cc + $data = $response->getData(); + $this->assertEquals('13820602628130529', $data['response']['aliasCC']); + $this->assertEquals('490000xxxxxx0086', $data['response']['maskedCC']); + } + public function testPurchase() { $this->setMockHttpResponse('XmlAuthorizationSuccess.txt'); From 2c86f7fc1db4f2aad01e132f37becc1ea162774c Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Wed, 30 May 2018 18:24:52 +0200 Subject: [PATCH 10/11] feat: add uppremember me --- src/Message/PurchaseRequest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 266ac73..246b194 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -21,7 +21,8 @@ class PurchaseRequest extends AbstractRedirectRequest */ protected $optionalParams = array( 'useAlias', - 'uppReturnMaskedCC' + 'uppReturnMaskedCC', + 'uppRememberMe' ); /** @@ -68,4 +69,13 @@ public function setUppCustomerDetails($value) { return $this->setParameter('uppCustomerDetails', $value); } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setUppRememberMe($value) + { + return $this->setParameter('uppRememberMe', $value); + } } From 7e7c2c9ff7bca42f467904dd38c67ca1d5e0f913 Mon Sep 17 00:00:00 2001 From: Frederik Trostorf Date: Mon, 4 Jun 2018 13:38:51 +0200 Subject: [PATCH 11/11] feat: allow setting credit card data to prefill form when user redirected --- src/Message/PurchaseRequest.php | 40 +++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 246b194..ae2e911 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -22,7 +22,8 @@ class PurchaseRequest extends AbstractRedirectRequest protected $optionalParams = array( 'useAlias', 'uppReturnMaskedCC', - 'uppRememberMe' + 'uppRememberMe', + 'paymentMethod' ); /** @@ -40,13 +41,16 @@ public function getData() } } + // card data for prefilling redirect form + $this->addCardData($data); + return $data; } /** - * @param $value - * @return \Omnipay\Common\Message\AbstractRequest - */ + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ public function setUppReturnMaskedCC($value) { return $this->setParameter('uppReturnMaskedCC', $value); @@ -78,4 +82,32 @@ public function setUppRememberMe($value) { return $this->setParameter('uppRememberMe', $value); } + + /** + * enable functionality to prefill datatrans form in redirect mode + * + * @param $data + */ + private function addCardData(&$data) + { + // rename paymentmethod if set + if (isset($data['paymentMethod'])) { + $data['paymentmethod'] = $data['paymentMethod']; + unset($data['paymentMethod']); + } + + if ($card = $this->getCard()) { + if ($expMonth = $card->getExpiryMonth()) { + $data['expm'] = $expMonth; + } + + if ($expYear = $card->getExpiryDate('y')) { + $data['expy'] = $expYear; + } + + if ($number = $card->getNumber()) { + $data['aliasCC'] = $number; + } + } + } }