Skip to content

Commit

Permalink
Fix incorrect TxType in direct purchase; added missing test that woul…
Browse files Browse the repository at this point in the history
…d have caught this.

Also default the account type to C for repeat payments, allowing
that to be overridden at the request and gateway level.
Tests added for this.
  • Loading branch information
judgej committed Sep 22, 2018
1 parent 652b6b7 commit ef1abad
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ In both cases, send the message and check the result.
$captureResponse = $captureRequest->send();

if ($captureResponse->isSuccessful()) {
// The capture will successful.
// The capture was successful.
// There will never be a redirect here.
}
```
Expand Down
1 change: 1 addition & 0 deletions src/DirectGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getDefaultParameters()
'exitOnResponse' => false,
'apply3DSecure' => null,
'useAuthenticate' => null,
'accountType' => null,
];
}

Expand Down
25 changes: 0 additions & 25 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,31 +199,6 @@ public function setProfile($value)
return $this->setParameter('profile', $value);
}

/**
* @return string One of static::ACCOUNT_TYPE_*
*/
public function getAccountType()
{
return $this->getParameter('accountType');
}

/**
* Set account type.
* Neither 'M' nor 'C' offer the 3D-Secure checks that the "E" customer
* experience offers. See constants ACCOUNT_TYPE_*
*
* This is ignored for all PAYPAL transactions.
*
* @param string $value E: Use the e-commerce merchant account. (default)
* M: Use the mail/telephone order account. (if present)
* C: Use the continuous authority merchant account. (if present)
* @return $this
*/
public function setAccountType($value)
{
return $this->setParameter('accountType', $value);
}

/**
* @return string The custom vendor data.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Message/DirectPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
class DirectPurchaseRequest extends DirectAuthorizeRequest
{
public function getService()
public function getTxType()
{
return static::SERVICE_DIRECT_REGISTER;
return static::TXTYPE_PAYMENT;
}
}
8 changes: 8 additions & 0 deletions src/Message/SharedRepeatAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public function getData()

$data = $this->getBaseData();

// If no explicit account type has been supplied (set and defaulted
// in getBaseData), then override the default.

if ($this->getAccountType() === null) {
// C – for repeat transactions
$data['AccountType'] = static::ACCOUNT_TYPE_C;
}

// Merchant's unique reference to THIS new authorization or payment

$data['VendorTxCode'] = $this->getTransactionId();
Expand Down
25 changes: 25 additions & 0 deletions src/Traits/GatewayParamsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,29 @@ public function getUseAuthenticate()
{
return $this->getParameter('useAuthenticate');
}

/**
* @return string One of static::ACCOUNT_TYPE_*
*/
public function getAccountType()
{
return $this->getParameter('accountType');
}

/**
* Set account type.
* Neither 'M' nor 'C' offer the 3D-Secure checks that the "E" customer
* experience offers. See constants ACCOUNT_TYPE_*
*
* This is ignored for all PAYPAL transactions.
*
* @param string $value E: Use the e-commerce merchant account. (default)
* M: Use the mail/telephone order account. (if present)
* C: Use the continuous authority merchant account. (if present)
* @return $this
*/
public function setAccountType($value)
{
return $this->setParameter('accountType', $value);
}
}
59 changes: 59 additions & 0 deletions tests/Message/DirectPurchaseRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Omnipay\SagePay\Message;

use Omnipay\Tests\TestCase;

class DirectPurchaseRequestTest extends DirectAuthorizeRequestTest
{
// VISA incurrs a surcharge of 2.5% when used.
const SURCHARGE_XML = '<surcharges><surcharge>'
. '<paymentType>VISA</paymentType><percentage>2.50</percentage>'
. '</surcharge></surcharges>';

/**
* @var DirectAuthorizeRequest
*/
protected $request;

public function setUp()
{
parent::setUp();

$this->request = new DirectPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());

$this->request->initialize(
array(
// Money as Omnipay 3.x Money object, combining currency and amount
// Omnipay 3.0-RC2 no longer accepts a money object.
'amount' => '12.00', //Money::GBP(1200),
'currency' => 'GBP',
'transactionId' => '123',
'surchargeXml' => self::SURCHARGE_XML,
'card' => $this->getValidCard(),
'language' => 'EN',
)
);
}

public function testGetDataDefaults()
{
$data = $this->request->getData();

$this->assertSame('E', $data['AccountType']);
$this->assertSame(0, $data['ApplyAVSCV2']);
$this->assertSame(0, $data['Apply3DSecure']);

$this->assertSame('PAYMENT', $data['TxType']);
$this->assertSame('vspdirect-register', $this->request->getService());

// If we have not explicitly set the CreateToken flag, then it remains
// undefined. This allows it to default when creating a transaction
// according to whether we are using a single-use token or a more
// permanent cardReference.

$this->assertArrayNotHasKey('CreateToken', $data);

$this->assertSame('EN', $data['Language']);
}
}
23 changes: 23 additions & 0 deletions tests/Message/SharedRepeatAuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testSettingOfRelatedTransaction()
'{"SecurityKey":"F6AF4AIB1G","TxAuthNo":"1518884596","VPSTxId":"{9EC5D0BC-A816-E8C3-859A-55C1E476E7C2}","VendorTxCode":"D6429BY7x2217743"}';
$this->request->setTransactionReference($relatedTransactionRef);
$this->request->setDescription('testSettingOfRelatedTransaction');

$data = $this->request->getData();

$this->assertEquals('12.00', $data['Amount'], 'Transaction amount does not match');
Expand All @@ -45,4 +46,26 @@ public function testSettingOfRelatedTransaction()
$this->assertEquals('REPEATDEFERRED', $data['TxType']);
$this->assertEquals('repeat', $this->request->getService());
}

public function testAccountType()
{
$relatedTransactionRef =
'{"SecurityKey":"F6AF4AIB1G","TxAuthNo":"1518884596","VPSTxId":"{9EC5D0BC-A816-E8C3-859A-55C1E476E7C2}","VendorTxCode":"D6429BY7x2217743"}';
$this->request->setTransactionReference($relatedTransactionRef);
$this->request->setDescription('testSettingOfRelatedTransaction');

// The account type will default to 'C' for repeat payments.

$data = $this->request->getData();

$this->assertSame('C', $data['AccountType']);

// It can be overridden.

$this->request->setAccountType('E');

$data = $this->request->getData();

$this->assertSame('E', $data['AccountType']);
}
}

0 comments on commit ef1abad

Please sign in to comment.