Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

Add optional params "uppReturnMaskedCC", "useAlias", "uppCustomerDetails" #7

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Message/AbstractRedirectRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getData()
foreach ($this->optionalParams as $param) {
$value = $this->getParameter($param);

if ($value !== '') {
if (!empty($value)) {
$data[$param] = $value;
}
}
Expand Down
93 changes: 93 additions & 0 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
14 changes: 12 additions & 2 deletions src/Message/XmlAuthorizationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class XmlAuthorizationRequest extends XmlRequest
*/
protected $optionalParameters = array(
'reqtype',
'uppCustomerIpAddress'
'uppCustomerIpAddress',
'useAlias'
);

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
7 changes: 5 additions & 2 deletions tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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());
Expand Down
40 changes: 40 additions & 0 deletions tests/Mock/XmlAuthorizationAliasSuccess.txt
Original file line number Diff line number Diff line change
@@ -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: -

<?xml version='1.0' encoding='UTF-8'?>
<authorizationService version='3'>
<body merchantId='TEST-TOKEN-123' status='accepted'>
<transaction refno='1' trxStatus='response'>
<request>
<amount>10000</amount>
<currency>CHF</currency>
<aliasCC>13820602628130529</aliasCC>
<uppReturnMaskedCC>yes</uppReturnMaskedCC>
<expm>12</expm>
<expy>18</expy>
<useAlias>no</useAlias>
<sign>TEST-SIGN-123</sign>
<reqtype>NOA</reqtype>
</request>
<response>
<responseCode>01</responseCode>
<responseMessage>Authorized</responseMessage>
<uppTransactionId>44E89981F8714392Y</uppTransactionId>
<authorizationCode>123</authorizationCode>
<acqAuthorizationCode>123</acqAuthorizationCode>
<maskedCC>490000xxxxxx0086</maskedCC>
<returnCustomerCountry>CH</returnCustomerCountry>
<aliasCC>13820602628130529</aliasCC>
</response>
</transaction>
</body>
</authorizationService>
20 changes: 20 additions & 0 deletions tests/XmlGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down