Skip to content

Commit

Permalink
Issue #104 Test coverage for capture (in both modes - authorise and d…
Browse files Browse the repository at this point in the history
…eferred)
  • Loading branch information
judgej committed Sep 23, 2018
1 parent ef1abad commit a24bfb3
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Message/SharedCaptureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public function getData()

// The documentation (2015) says this is required. But it can't be, because
// we won't have it for authenticate, as the bank has not been visited.
//$data['RelatedTxAuthNo'] = $this->getTxAuthNo();
// We will follow the spec though, but treat it as optional here.

if ($this->getTxAuthNo() !== null) {
$data['RelatedTxAuthNo'] = $this->getTxAuthNo();
}
} else {
$this->validate('txAuthNo');

Expand Down
2 changes: 1 addition & 1 deletion src/Message/SharedRepeatAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getData()

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

// SagePay's unique reference for the PREVIOUS transaction
// Sage Pay's unique reference for the ORIGINAL transaction

$data['RelatedVendorTxCode'] = $this->getRelatedTransactionId();
$data['RelatedVPSTxId'] = $this->getVpsTxId();
Expand Down
104 changes: 104 additions & 0 deletions tests/Message/SharedCaptureRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Omnipay\SagePay\Message;

use Omnipay\Tests\TestCase;

class SharedCaptureRequestTest extends TestCase
{
public function setUp()
{
parent::setUp();

$this->request = new SharedCaptureRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'transactionReference' => '{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}',
'testMode' => true,
)
);
}

public function testTxType()
{
// Default TxType is RELEASE.

$this->assertSame('RELEASE', $this->request->getTxType());

// User authenticate explicity true.

$this->request->setUseAuthenticate(true);

$this->assertSame('AUTHORISE', $this->request->getTxType());

// User authenticate explicity false (back to the default).

$this->request->setUseAuthenticate(false);

$this->assertSame('RELEASE', $this->request->getTxType());
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
*/
public function testMissingAmount()
{
$this->request->getData();
}

public function testValid()
{
$this->request->setAmount(123.45);

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

$this->assertSame('123.45', $data['ReleaseAmount']);
$this->assertSame('438791', $data['VendorTxCode']);

$this->assertSame('{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}', $data['VPSTxId']);
$this->assertSame('JEUPDN1N7E', $data['SecurityKey']);
$this->assertSame('4255', $data['TxAuthNo']);
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
*/
public function testAuthMissingDescription()
{
$this->request->setAmount(123.45);
$this->request->setUseAuthenticate(true);

$this->request->getData();
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
*/
public function testAuthMissingTransactionId()
{
$this->request->setAmount(123.45);
$this->request->setDescription('desc');
$this->request->setUseAuthenticate(true);

$this->request->getData();
}

public function testAuthValid()
{
$this->request->setAmount(123.45);
$this->request->setDescription('desc');
$this->request->setTransactionId('438791-NEW');
$this->request->setUseAuthenticate(true);

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

$this->assertSame('123.45', $data['Amount']);
$this->assertSame('438791-NEW', $data['VendorTxCode']);
$this->assertSame('desc', $data['Description']);

$this->assertSame('438791', $data['RelatedVendorTxCode']);
$this->assertSame('{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}', $data['RelatedVPSTxId']);
$this->assertSame('JEUPDN1N7E', $data['RelatedSecurityKey']);
$this->assertSame('4255', $data['RelatedTxAuthNo']);
}
}

0 comments on commit a24bfb3

Please sign in to comment.