diff --git a/src/Message/SharedCaptureRequest.php b/src/Message/SharedCaptureRequest.php index a655e94..d1cd18e 100644 --- a/src/Message/SharedCaptureRequest.php +++ b/src/Message/SharedCaptureRequest.php @@ -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'); diff --git a/src/Message/SharedRepeatAuthorizeRequest.php b/src/Message/SharedRepeatAuthorizeRequest.php index e358d31..68e9797 100644 --- a/src/Message/SharedRepeatAuthorizeRequest.php +++ b/src/Message/SharedRepeatAuthorizeRequest.php @@ -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(); diff --git a/tests/Message/SharedCaptureRequestTest.php b/tests/Message/SharedCaptureRequestTest.php new file mode 100644 index 0000000..0035709 --- /dev/null +++ b/tests/Message/SharedCaptureRequestTest.php @@ -0,0 +1,104 @@ +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']); + } +}