Skip to content

Commit ef1abad

Browse files
committed
Fix incorrect TxType in direct purchase; added missing test that would 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.
1 parent 652b6b7 commit ef1abad

File tree

8 files changed

+119
-28
lines changed

8 files changed

+119
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ In both cases, send the message and check the result.
686686
$captureResponse = $captureRequest->send();
687687

688688
if ($captureResponse->isSuccessful()) {
689-
// The capture will successful.
689+
// The capture was successful.
690690
// There will never be a redirect here.
691691
}
692692
```

src/DirectGateway.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function getDefaultParameters()
4646
'exitOnResponse' => false,
4747
'apply3DSecure' => null,
4848
'useAuthenticate' => null,
49+
'accountType' => null,
4950
];
5051
}
5152

src/Message/AbstractRequest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -199,31 +199,6 @@ public function setProfile($value)
199199
return $this->setParameter('profile', $value);
200200
}
201201

202-
/**
203-
* @return string One of static::ACCOUNT_TYPE_*
204-
*/
205-
public function getAccountType()
206-
{
207-
return $this->getParameter('accountType');
208-
}
209-
210-
/**
211-
* Set account type.
212-
* Neither 'M' nor 'C' offer the 3D-Secure checks that the "E" customer
213-
* experience offers. See constants ACCOUNT_TYPE_*
214-
*
215-
* This is ignored for all PAYPAL transactions.
216-
*
217-
* @param string $value E: Use the e-commerce merchant account. (default)
218-
* M: Use the mail/telephone order account. (if present)
219-
* C: Use the continuous authority merchant account. (if present)
220-
* @return $this
221-
*/
222-
public function setAccountType($value)
223-
{
224-
return $this->setParameter('accountType', $value);
225-
}
226-
227202
/**
228203
* @return string The custom vendor data.
229204
*/

src/Message/DirectPurchaseRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
class DirectPurchaseRequest extends DirectAuthorizeRequest
99
{
10-
public function getService()
10+
public function getTxType()
1111
{
12-
return static::SERVICE_DIRECT_REGISTER;
12+
return static::TXTYPE_PAYMENT;
1313
}
1414
}

src/Message/SharedRepeatAuthorizeRequest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public function getData()
3838

3939
$data = $this->getBaseData();
4040

41+
// If no explicit account type has been supplied (set and defaulted
42+
// in getBaseData), then override the default.
43+
44+
if ($this->getAccountType() === null) {
45+
// C – for repeat transactions
46+
$data['AccountType'] = static::ACCOUNT_TYPE_C;
47+
}
48+
4149
// Merchant's unique reference to THIS new authorization or payment
4250

4351
$data['VendorTxCode'] = $this->getTransactionId();

src/Traits/GatewayParamsTrait.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,29 @@ public function getUseAuthenticate()
176176
{
177177
return $this->getParameter('useAuthenticate');
178178
}
179+
180+
/**
181+
* @return string One of static::ACCOUNT_TYPE_*
182+
*/
183+
public function getAccountType()
184+
{
185+
return $this->getParameter('accountType');
186+
}
187+
188+
/**
189+
* Set account type.
190+
* Neither 'M' nor 'C' offer the 3D-Secure checks that the "E" customer
191+
* experience offers. See constants ACCOUNT_TYPE_*
192+
*
193+
* This is ignored for all PAYPAL transactions.
194+
*
195+
* @param string $value E: Use the e-commerce merchant account. (default)
196+
* M: Use the mail/telephone order account. (if present)
197+
* C: Use the continuous authority merchant account. (if present)
198+
* @return $this
199+
*/
200+
public function setAccountType($value)
201+
{
202+
return $this->setParameter('accountType', $value);
203+
}
179204
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Omnipay\SagePay\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class DirectPurchaseRequestTest extends DirectAuthorizeRequestTest
8+
{
9+
// VISA incurrs a surcharge of 2.5% when used.
10+
const SURCHARGE_XML = '<surcharges><surcharge>'
11+
. '<paymentType>VISA</paymentType><percentage>2.50</percentage>'
12+
. '</surcharge></surcharges>';
13+
14+
/**
15+
* @var DirectAuthorizeRequest
16+
*/
17+
protected $request;
18+
19+
public function setUp()
20+
{
21+
parent::setUp();
22+
23+
$this->request = new DirectPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
24+
25+
$this->request->initialize(
26+
array(
27+
// Money as Omnipay 3.x Money object, combining currency and amount
28+
// Omnipay 3.0-RC2 no longer accepts a money object.
29+
'amount' => '12.00', //Money::GBP(1200),
30+
'currency' => 'GBP',
31+
'transactionId' => '123',
32+
'surchargeXml' => self::SURCHARGE_XML,
33+
'card' => $this->getValidCard(),
34+
'language' => 'EN',
35+
)
36+
);
37+
}
38+
39+
public function testGetDataDefaults()
40+
{
41+
$data = $this->request->getData();
42+
43+
$this->assertSame('E', $data['AccountType']);
44+
$this->assertSame(0, $data['ApplyAVSCV2']);
45+
$this->assertSame(0, $data['Apply3DSecure']);
46+
47+
$this->assertSame('PAYMENT', $data['TxType']);
48+
$this->assertSame('vspdirect-register', $this->request->getService());
49+
50+
// If we have not explicitly set the CreateToken flag, then it remains
51+
// undefined. This allows it to default when creating a transaction
52+
// according to whether we are using a single-use token or a more
53+
// permanent cardReference.
54+
55+
$this->assertArrayNotHasKey('CreateToken', $data);
56+
57+
$this->assertSame('EN', $data['Language']);
58+
}
59+
}

tests/Message/SharedRepeatAuthorizeRequestTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testSettingOfRelatedTransaction()
3131
'{"SecurityKey":"F6AF4AIB1G","TxAuthNo":"1518884596","VPSTxId":"{9EC5D0BC-A816-E8C3-859A-55C1E476E7C2}","VendorTxCode":"D6429BY7x2217743"}';
3232
$this->request->setTransactionReference($relatedTransactionRef);
3333
$this->request->setDescription('testSettingOfRelatedTransaction');
34+
3435
$data = $this->request->getData();
3536

3637
$this->assertEquals('12.00', $data['Amount'], 'Transaction amount does not match');
@@ -45,4 +46,26 @@ public function testSettingOfRelatedTransaction()
4546
$this->assertEquals('REPEATDEFERRED', $data['TxType']);
4647
$this->assertEquals('repeat', $this->request->getService());
4748
}
49+
50+
public function testAccountType()
51+
{
52+
$relatedTransactionRef =
53+
'{"SecurityKey":"F6AF4AIB1G","TxAuthNo":"1518884596","VPSTxId":"{9EC5D0BC-A816-E8C3-859A-55C1E476E7C2}","VendorTxCode":"D6429BY7x2217743"}';
54+
$this->request->setTransactionReference($relatedTransactionRef);
55+
$this->request->setDescription('testSettingOfRelatedTransaction');
56+
57+
// The account type will default to 'C' for repeat payments.
58+
59+
$data = $this->request->getData();
60+
61+
$this->assertSame('C', $data['AccountType']);
62+
63+
// It can be overridden.
64+
65+
$this->request->setAccountType('E');
66+
67+
$data = $this->request->getData();
68+
69+
$this->assertSame('E', $data['AccountType']);
70+
}
4871
}

0 commit comments

Comments
 (0)