diff --git a/src/Message/AbstractRedirectRequest.php b/src/Message/AbstractRedirectRequest.php index 9fa8203..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; } } diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 64c583c..ae2e911 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -16,5 +16,98 @@ class PurchaseRequest extends AbstractRedirectRequest { + /** + * @var array + */ + protected $optionalParams = array( + 'useAlias', + 'uppReturnMaskedCC', + 'uppRememberMe', + 'paymentMethod' + ); + /** + * @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; + } + } + + // card data for prefilling redirect form + $this->addCardData($data); + + 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); + } + + /** + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + 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; + } + } + } } 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); + } } 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()); 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');