Skip to content

Commit a15ab75

Browse files
committed
Merge pull request #4 from antonioperic/master
Adding capture option
2 parents a661c21 + 3a16cb5 commit a15ab75

15 files changed

+524
-0
lines changed

src/Gateway.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,19 @@ public function completePurchase(array $parameters = array())
5656
{
5757
return $this->createRequest('\Omnipay\Netaxept\Message\CompletePurchaseRequest', $parameters);
5858
}
59+
60+
public function capture(array $parameters = array())
61+
{
62+
return $this->createRequest('\Omnipay\Netaxept\Message\CaptureRequest', $parameters);
63+
}
64+
65+
public function void(array $parameters = array())
66+
{
67+
return $this->createRequest('\Omnipay\Netaxept\Message\AnnulRequest', $parameters);
68+
}
69+
70+
public function credit(array $parameters = array())
71+
{
72+
return $this->createRequest('\Omnipay\Netaxept\Message\CreditRequest', $parameters);
73+
}
5974
}

src/Message/AnnulRequest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Common\Exception\InvalidResponseException;
6+
use Omnipay\Common\Message\AbstractRequest;
7+
8+
/**
9+
* Netaxept Annul Request
10+
*
11+
* @author Antonio Peric-Mazar <[email protected]>
12+
*/
13+
class AnnulRequest extends PurchaseRequest
14+
{
15+
public function getData()
16+
{
17+
$data = array();
18+
$data['transactionAmount'] = $this->getAmountInteger();
19+
$data['transactionId'] = $this->getTransactionId();
20+
$data['merchantId'] = $this->getMerchantId();
21+
$data['token'] = $this->getPassword();
22+
$data['operation'] = 'ANNUL';
23+
24+
if (empty($data['transactionAmount']) || empty($data['transactionId'])) {
25+
throw new InvalidResponseException;
26+
}
27+
28+
return $data;
29+
}
30+
31+
public function sendData($data)
32+
{
33+
$url = $this->getEndpoint().'/Netaxept/Process.aspx?';
34+
$httpResponse = $this->httpClient->get($url.http_build_query($data))->send();
35+
36+
return $this->response = new Response($this, $httpResponse->xml());
37+
}
38+
}

src/Message/CaptureRequest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Common\Exception\InvalidResponseException;
6+
7+
/**
8+
* Netaxept Capture Request
9+
*
10+
* @author Antonio Peric-Mazar <[email protected]>
11+
*/
12+
class CaptureRequest extends PurchaseRequest
13+
{
14+
public function getData()
15+
{
16+
$data = array();
17+
$data['transactionAmount'] = $this->getAmountInteger();
18+
$data['transactionId'] = $this->getTransactionId();
19+
$data['merchantId'] = $this->getMerchantId();
20+
$data['token'] = $this->getPassword();
21+
$data['operation'] = 'CAPTURE';
22+
23+
if (empty($data['transactionAmount']) || empty($data['transactionId'])) {
24+
throw new InvalidResponseException;
25+
}
26+
27+
return $data;
28+
}
29+
30+
public function sendData($data)
31+
{
32+
$url = $this->getEndpoint().'/Netaxept/Process.aspx?';
33+
$httpResponse = $this->httpClient->get($url.http_build_query($data))->send();
34+
35+
return $this->response = new Response($this, $httpResponse->xml());
36+
}
37+
}

src/Message/CreditRequest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Common\Exception\InvalidResponseException;
6+
use Omnipay\Common\Message\AbstractRequest;
7+
8+
/**
9+
* Netaxept Credit Request
10+
*
11+
* @author Antonio Peric-Mazar <[email protected]>
12+
*/
13+
class CreditRequest extends PurchaseRequest
14+
{
15+
public function getData()
16+
{
17+
$data = array();
18+
$data['transactionAmount'] = $this->getAmountInteger();
19+
$data['transactionId'] = $this->getTransactionId();
20+
$data['merchantId'] = $this->getMerchantId();
21+
$data['token'] = $this->getPassword();
22+
$data['operation'] = 'CREDIT';
23+
24+
if (empty($data['transactionAmount']) || empty($data['transactionId'])) {
25+
throw new InvalidResponseException;
26+
}
27+
28+
return $data;
29+
}
30+
31+
public function sendData($data)
32+
{
33+
$url = $this->getEndpoint().'/Netaxept/Process.aspx?';
34+
$httpResponse = $this->httpClient->get($url.http_build_query($data))->send();
35+
36+
return $this->response = new Response($this, $httpResponse->xml());
37+
}
38+
}

tests/GatewayTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,81 @@ public function testCompletePurchaseFailure()
9696

9797
$response = $this->gateway->completePurchase($this->options)->send();
9898

99+
$this->assertFalse($response->isSuccessful());
100+
$this->assertFalse($response->isRedirect());
101+
$this->assertNull($response->getTransactionReference());
102+
103+
var_dump($response->getMessage());
104+
105+
$this->assertSame('Unable to find transaction', $response->getMessage());
106+
}
107+
108+
public function testCaptureSuccess()
109+
{
110+
$this->setMockHttpResponse('CaptureSuccess.txt');
111+
112+
$response = $this->gateway->capture($this->options)->send();
113+
114+
$this->assertTrue($response->isSuccessful());
115+
$this->assertFalse($response->isRedirect());
116+
$this->assertEquals('cc497f37603678c61a09fd5645959812', $response->getTransactionReference());
117+
$this->assertSame('OK', $response->getMessage());
118+
}
119+
120+
public function testCaptureFailure()
121+
{
122+
$this->setMockHttpResponse('CaptureFailure.txt');
123+
124+
$response = $this->gateway->capture($this->options)->send();
125+
126+
$this->assertFalse($response->isSuccessful());
127+
$this->assertFalse($response->isRedirect());
128+
$this->assertNull($response->getTransactionReference());
129+
$this->assertSame('Unable to find transaction', $response->getMessage());
130+
}
131+
132+
public function testAnnulSuccess()
133+
{
134+
$this->setMockHttpResponse('AnnulSuccess.txt');
135+
136+
$response = $this->gateway->capture($this->options)->send();
137+
138+
$this->assertTrue($response->isSuccessful());
139+
$this->assertFalse($response->isRedirect());
140+
$this->assertEquals('3fece3574598c6ae3932fae5f38bc8af', $response->getTransactionReference());
141+
$this->assertSame('OK', $response->getMessage());
142+
}
143+
144+
public function testAnnulFailure()
145+
{
146+
$this->setMockHttpResponse('AnnulFailure.txt');
147+
148+
$response = $this->gateway->capture($this->options)->send();
149+
150+
$this->assertFalse($response->isSuccessful());
151+
$this->assertFalse($response->isRedirect());
152+
$this->assertNull($response->getTransactionReference());
153+
$this->assertSame('Unable to find transaction', $response->getMessage());
154+
}
155+
156+
public function testCreditSuccess()
157+
{
158+
$this->setMockHttpResponse('CreditSuccess.txt');
159+
160+
$response = $this->gateway->capture($this->options)->send();
161+
162+
$this->assertTrue($response->isSuccessful());
163+
$this->assertFalse($response->isRedirect());
164+
$this->assertEquals('3fece3574598c6ae3932fae5f38bc8af', $response->getTransactionReference());
165+
$this->assertSame('OK', $response->getMessage());
166+
}
167+
168+
public function testCreditFailure()
169+
{
170+
$this->setMockHttpResponse('CreditFailure.txt');
171+
172+
$response = $this->gateway->capture($this->options)->send();
173+
99174
$this->assertFalse($response->isSuccessful());
100175
$this->assertFalse($response->isRedirect());
101176
$this->assertNull($response->getTransactionReference());

tests/Message/AnnulRequestTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
/**
8+
* @author Antonio Peric-Mazar <[email protected]>
9+
*/
10+
class AnnulRequestTest extends TestCase
11+
{
12+
/**
13+
* @var \Symfony\Component\HttpFoundation\Request
14+
*/
15+
private $httpRequest;
16+
17+
/**
18+
* @var \Omnipay\Netaxept\Message\AnnulRequest
19+
*/
20+
private $request;
21+
22+
public function setUp()
23+
{
24+
$client = $this->getHttpClient();
25+
$this->httpRequest = $this->getHttpRequest();
26+
27+
$this->request = new AnnulRequest($client, $this->httpRequest);
28+
}
29+
30+
/**
31+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
32+
*/
33+
public function testGetDataThrowsExceptionWithoutTransactionAmount()
34+
{
35+
$this->httpRequest->query->set('transactionId', 'TRANS-123');
36+
37+
$this->request->getData();
38+
}
39+
40+
/**
41+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
42+
*/
43+
public function testGetDataThrowsExceptionWithoutTransactionId()
44+
{
45+
$this->httpRequest->query->set('transactionAmount', 'ABC-123');
46+
47+
$this->request->getData();
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
/**
8+
* @author Antonio Peric-Mazar <[email protected]>
9+
*/
10+
class CaptureRequestTest extends TestCase
11+
{
12+
/**
13+
* @var \Symfony\Component\HttpFoundation\Request
14+
*/
15+
private $httpRequest;
16+
17+
/**
18+
* @var \Omnipay\Netaxept\Message\CaptureRequest
19+
*/
20+
private $request;
21+
22+
public function setUp()
23+
{
24+
$client = $this->getHttpClient();
25+
$this->httpRequest = $this->getHttpRequest();
26+
27+
$this->request = new CaptureRequest($client, $this->httpRequest);
28+
}
29+
30+
/**
31+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
32+
*/
33+
public function testGetDataThrowsExceptionWithoutTransactionAmount()
34+
{
35+
$this->httpRequest->query->set('transactionId', 'TRANS-123');
36+
37+
$this->request->getData();
38+
}
39+
40+
/**
41+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
42+
*/
43+
public function testGetDataThrowsExceptionWithoutTransactionId()
44+
{
45+
$this->httpRequest->query->set('transactionAmount', 'ABC-123');
46+
47+
$this->request->getData();
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
/**
8+
* @author Antonio Peric-Mazar <[email protected]>
9+
*/
10+
class CreditRequestTest extends TestCase
11+
{
12+
/**
13+
* @var \Symfony\Component\HttpFoundation\Request
14+
*/
15+
private $httpRequest;
16+
17+
/**
18+
* @var \Omnipay\Netaxept\Message\CreditRequest
19+
*/
20+
private $request;
21+
22+
public function setUp()
23+
{
24+
$client = $this->getHttpClient();
25+
$this->httpRequest = $this->getHttpRequest();
26+
27+
$this->request = new CreditRequest($client, $this->httpRequest);
28+
}
29+
30+
/**
31+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
32+
*/
33+
public function testGetDataThrowsExceptionWithoutTransactionAmount()
34+
{
35+
$this->httpRequest->query->set('transactionId', 'TRANS-123');
36+
37+
$this->request->getData();
38+
}
39+
40+
/**
41+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
42+
*/
43+
public function testGetDataThrowsExceptionWithoutTransactionId()
44+
{
45+
$this->httpRequest->query->set('transactionAmount', 'ABC-123');
46+
47+
$this->request->getData();
48+
}
49+
}

0 commit comments

Comments
 (0)