|
| 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