Skip to content

Commit a24bfb3

Browse files
committed
Issue #104 Test coverage for capture (in both modes - authorise and deferred)
1 parent ef1abad commit a24bfb3

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

src/Message/SharedCaptureRequest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public function getData()
4444

4545
// The documentation (2015) says this is required. But it can't be, because
4646
// we won't have it for authenticate, as the bank has not been visited.
47-
//$data['RelatedTxAuthNo'] = $this->getTxAuthNo();
47+
// We will follow the spec though, but treat it as optional here.
48+
49+
if ($this->getTxAuthNo() !== null) {
50+
$data['RelatedTxAuthNo'] = $this->getTxAuthNo();
51+
}
4852
} else {
4953
$this->validate('txAuthNo');
5054

src/Message/SharedRepeatAuthorizeRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getData()
5757

5858
$data['Description'] = $this->getDescription();
5959

60-
// SagePay's unique reference for the PREVIOUS transaction
60+
// Sage Pay's unique reference for the ORIGINAL transaction
6161

6262
$data['RelatedVendorTxCode'] = $this->getRelatedTransactionId();
6363
$data['RelatedVPSTxId'] = $this->getVpsTxId();
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace Omnipay\SagePay\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class SharedCaptureRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
parent::setUp();
12+
13+
$this->request = new SharedCaptureRequest($this->getHttpClient(), $this->getHttpRequest());
14+
$this->request->initialize(
15+
array(
16+
'transactionReference' => '{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}',
17+
'testMode' => true,
18+
)
19+
);
20+
}
21+
22+
public function testTxType()
23+
{
24+
// Default TxType is RELEASE.
25+
26+
$this->assertSame('RELEASE', $this->request->getTxType());
27+
28+
// User authenticate explicity true.
29+
30+
$this->request->setUseAuthenticate(true);
31+
32+
$this->assertSame('AUTHORISE', $this->request->getTxType());
33+
34+
// User authenticate explicity false (back to the default).
35+
36+
$this->request->setUseAuthenticate(false);
37+
38+
$this->assertSame('RELEASE', $this->request->getTxType());
39+
}
40+
41+
/**
42+
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
43+
*/
44+
public function testMissingAmount()
45+
{
46+
$this->request->getData();
47+
}
48+
49+
public function testValid()
50+
{
51+
$this->request->setAmount(123.45);
52+
53+
$data = $this->request->getData();
54+
55+
$this->assertSame('123.45', $data['ReleaseAmount']);
56+
$this->assertSame('438791', $data['VendorTxCode']);
57+
58+
$this->assertSame('{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}', $data['VPSTxId']);
59+
$this->assertSame('JEUPDN1N7E', $data['SecurityKey']);
60+
$this->assertSame('4255', $data['TxAuthNo']);
61+
}
62+
63+
/**
64+
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
65+
*/
66+
public function testAuthMissingDescription()
67+
{
68+
$this->request->setAmount(123.45);
69+
$this->request->setUseAuthenticate(true);
70+
71+
$this->request->getData();
72+
}
73+
74+
/**
75+
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
76+
*/
77+
public function testAuthMissingTransactionId()
78+
{
79+
$this->request->setAmount(123.45);
80+
$this->request->setDescription('desc');
81+
$this->request->setUseAuthenticate(true);
82+
83+
$this->request->getData();
84+
}
85+
86+
public function testAuthValid()
87+
{
88+
$this->request->setAmount(123.45);
89+
$this->request->setDescription('desc');
90+
$this->request->setTransactionId('438791-NEW');
91+
$this->request->setUseAuthenticate(true);
92+
93+
$data = $this->request->getData();
94+
95+
$this->assertSame('123.45', $data['Amount']);
96+
$this->assertSame('438791-NEW', $data['VendorTxCode']);
97+
$this->assertSame('desc', $data['Description']);
98+
99+
$this->assertSame('438791', $data['RelatedVendorTxCode']);
100+
$this->assertSame('{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}', $data['RelatedVPSTxId']);
101+
$this->assertSame('JEUPDN1N7E', $data['RelatedSecurityKey']);
102+
$this->assertSame('4255', $data['RelatedTxAuthNo']);
103+
}
104+
}

0 commit comments

Comments
 (0)