Skip to content

Commit 9855622

Browse files
committed
Remove Validate() and complete test suite for DirectPostGateway
1 parent a04dfe0 commit 9855622

16 files changed

+156
-43
lines changed

src/DirectPostGateway.php

-11
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,4 @@ public function credit(array $parameters = array())
160160
{
161161
return $this->createRequest('\Omnipay\NMI\Message\DirectPostCreditRequest', $parameters);
162162
}
163-
164-
/**
165-
* This action is used for doing an "Account Verification" on the
166-
* cardholder's credit card without actually doing an authorization.
167-
* @param array $parameters
168-
* @return \Omnipay\NMI\Message\DirectPostValidateRequest
169-
*/
170-
public function validate(array $parameters = array())
171-
{
172-
return $this->createRequest('\Omnipay\NMI\Message\DirectPostValidateRequest', $parameters);
173-
}
174163
}

src/Message/AbstractRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ protected function getShippingData()
149149
public function sendData($data)
150150
{
151151
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send();
152-
152+
echo $httpResponse;
153153
return $this->response = new DirectPostResponse($this, $httpResponse->getBody());
154154
}
155155

src/Message/DirectPostCaptureRequest.php

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class DirectPostCaptureRequest extends AbstractRequest
1111
public function getData()
1212
{
1313
$this->validate('transactionReference');
14-
$this->getCard()->validate();
1514

1615
$data = $this->getBaseData();
1716
$data['transactionid'] = $this->getTransactionReference();

src/Message/DirectPostValidateRequest.php

-10
This file was deleted.

src/Message/DirectPostVoidRequest.php

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class DirectPostVoidRequest extends AbstractRequest
1111
public function getData()
1212
{
1313
$this->validate('transactionReference');
14-
$this->getCard()->validate();
1514

1615
$data = $this->getBaseData();
1716
$data['transactionid'] = $this->getTransactionReference();

tests/DirectPostGatewayTest.php

+75-19
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,41 @@
55

66
class DirectPostGatewayTest extends GatewayTestCase
77
{
8-
protected $successOptions;
9-
protected $failureOptions;
8+
protected $purchaseOptions;
9+
protected $captureOptions;
10+
protected $voidOptions;
11+
protected $refundOptions;
1012

1113
public function setUp()
1214
{
1315
parent::setUp();
1416

1517
$this->gateway = new DirectPostGateway($this->getHttpClient(), $this->getHttpRequest());
1618

17-
$this->successOptions = array(
19+
$this->purchaseOptions = array(
1820
'amount' => '10.00',
1921
'card' => $this->getValidCard()
2022
);
2123

22-
$this->failureOptions = array(
23-
'amount' => '0.00',
24-
'card' => $this->getValidCard()
24+
$this->captureOptions = array(
25+
'amount' => '10.00',
26+
'transactionReference' => '2577708057'
27+
);
28+
29+
$this->voidOptions = array(
30+
'transactionReference' => '2577708057'
31+
);
32+
33+
$this->refundOptions = array(
34+
'transactionReference' => '2577725848'
2535
);
2636
}
2737

2838
public function testAuthorizeSuccess()
2939
{
3040
$this->setMockHttpResponse('DirectPostAuthSuccess.txt');
3141

32-
$response = $this->gateway->authorize($this->successOptions)->send();
42+
$response = $this->gateway->authorize($this->purchaseOptions)->send();
3343
$this->assertTrue($response->isSuccessful());
3444
$this->assertSame('2577708057', $response->getTransactionReference());
3545
$this->assertSame('SUCCESS', $response->getMessage());
@@ -39,70 +49,116 @@ public function testAuthorizeFailure()
3949
{
4050
$this->setMockHttpResponse('DirectPostAuthFailure.txt');
4151

42-
$response = $this->gateway->authorize($this->failureOptions)->send();
52+
$this->purchaseOptions['amount'] = '0.00';
53+
54+
$response = $this->gateway->authorize($this->purchaseOptions)->send();
4355
$this->assertFalse($response->isSuccessful());
4456
$this->assertSame('2577711599', $response->getTransactionReference());
4557
$this->assertSame('DECLINE', $response->getMessage());
4658
}
4759

48-
public function testSaleSuccess()
60+
public function testPurchaseSuccess()
4961
{
62+
$this->setMockHttpResponse('DirectPostSaleSuccess.txt');
5063

64+
$response = $this->gateway->authorize($this->purchaseOptions)->send();
65+
$this->assertTrue($response->isSuccessful());
66+
$this->assertSame('2577715564', $response->getTransactionReference());
67+
$this->assertSame('SUCCESS', $response->getMessage());
5168
}
5269

53-
public function testSaleFailure()
70+
public function testPurchaseFailure()
5471
{
72+
$this->setMockHttpResponse('DirectPostSaleFailure.txt');
5573

74+
$this->purchaseOptions['amount'] = '0.00';
75+
76+
$response = $this->gateway->authorize($this->purchaseOptions)->send();
77+
$this->assertFalse($response->isSuccessful());
78+
$this->assertSame('2577715978', $response->getTransactionReference());
79+
$this->assertSame('DECLINE', $response->getMessage());
5680
}
5781

5882
public function testCaptureSuccess()
5983
{
84+
$this->setMockHttpResponse('DirectPostCaptureSuccess.txt');
6085

86+
$response = $this->gateway->capture($this->captureOptions)->send();
87+
$this->assertTrue($response->isSuccessful());
88+
$this->assertSame('2577708057', $response->getTransactionReference());
89+
$this->assertSame('SUCCESS', $response->getMessage());
6190
}
6291

6392
public function testCaptureFailure()
6493
{
94+
$this->setMockHttpResponse('DirectPostCaptureFailure.txt');
6595

96+
$response = $this->gateway->capture($this->captureOptions)->send();
97+
$this->assertFalse($response->isSuccessful());
98+
$this->assertSame('2577708057', $response->getTransactionReference());
99+
$this->assertSame('A capture requires that the existing transaction be an AUTH REFID:143498124', $response->getMessage());
66100
}
67101

68102
public function testVoidSuccess()
69103
{
104+
$this->setMockHttpResponse('DirectPostVoidSuccess.txt');
70105

106+
$response = $this->gateway->void($this->voidOptions)->send();
107+
$this->assertTrue($response->isSuccessful());
108+
$this->assertSame('2577708057', $response->getTransactionReference());
109+
$this->assertSame('Transaction Void Successful', $response->getMessage());
71110
}
72111

73112
public function testVoidFailure()
74113
{
114+
$this->setMockHttpResponse('DirectPostVoidFailure.txt');
75115

116+
$response = $this->gateway->void($this->voidOptions)->send();
117+
$this->assertFalse($response->isSuccessful());
118+
$this->assertSame('2577708057', $response->getTransactionReference());
119+
$this->assertSame('Only transactions pending settlement can be voided REFID:143498494', $response->getMessage());
76120
}
77121

78122
public function testRefundSuccess()
79123
{
124+
$this->setMockHttpResponse('DirectPostRefundSuccess.txt');
80125

126+
$response = $this->gateway->void($this->refundOptions)->send();
127+
$this->assertTrue($response->isSuccessful());
128+
$this->assertSame('2577725848', $response->getTransactionReference());
129+
$this->assertSame('SUCCESS', $response->getMessage());
81130
}
82131

83132
public function testRefundFailure()
84133
{
134+
$this->setMockHttpResponse('DirectPostRefundFailure.txt');
85135

136+
$response = $this->gateway->void($this->refundOptions)->send();
137+
$this->assertFalse($response->isSuccessful());
138+
$this->assertSame('2577725848', $response->getTransactionReference());
139+
$this->assertSame('Refund amount may not exceed the transaction balance REFID:143498703', $response->getMessage());
86140
}
87141

88142
public function testCreditSuccess()
89143
{
144+
$this->setMockHttpResponse('DirectPostCreditSuccess.txt');
90145

146+
$response = $this->gateway->authorize($this->purchaseOptions)->send();
147+
$this->assertTrue($response->isSuccessful());
148+
$this->assertSame('2577728141', $response->getTransactionReference());
149+
$this->assertSame('SUCCESS', $response->getMessage());
91150
}
92151

93152
public function testCreditFailure()
94153
{
154+
$this->setMockHttpResponse('DirectPostCreditFailure.txt');
95155

96-
}
97-
98-
public function testValidateSuccess()
99-
{
100-
101-
}
102-
103-
public function testValidateFailure()
104-
{
156+
$this->purchaseOptions['amount'] = '0.00';
105157

158+
$response = $this->gateway->authorize($this->purchaseOptions)->send();
159+
$this->assertFalse($response->isSuccessful());
160+
$this->assertSame('', $response->getTransactionReference());
161+
$this->assertSame('Invalid amount REFID:143498834', $response->getMessage());
106162
}
107163

108164
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:25:28 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 200
5+
Connection: close
6+
Server:
7+
8+
response=3&responsetext=A capture requires that the existing transaction be an AUTH REFID:143498124&authcode=&transactionid=2577708057&avsresponse=&cvvresponse=&orderid=&type=capture&response_code=300
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:24:52 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 138
5+
Connection: close
6+
Server:
7+
8+
response=1&responsetext=SUCCESS&authcode=123456&transactionid=2577708057&avsresponse=&cvvresponse=&orderid=&type=capture&response_code=100
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:42:13 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 144
5+
Connection: close
6+
Server:
7+
8+
response=3&responsetext=Invalid amount REFID:143498834&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=credit&response_code=300
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:41:35 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 131
5+
Connection: close
6+
Server:
7+
8+
response=1&responsetext=SUCCESS&authcode=&transactionid=2577728141&avsresponse=&cvvresponse=&orderid=&type=credit&response_code=100
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:39:14 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 182
5+
Connection: close
6+
Server:
7+
8+
response=3&responsetext=Refund amount may not exceed the transaction balance REFID:143498703&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=refund&response_code=300
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:37:22 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 131
5+
Connection: close
6+
Server:
7+
8+
response=1&responsetext=SUCCESS&authcode=&transactionid=2577725848&avsresponse=&cvvresponse=&orderid=&type=refund&response_code=100

tests/Mock/DirectPostSaleFailure.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:20:20 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 130
5+
Connection: close
6+
Server:
7+
8+
response=2&responsetext=DECLINE&authcode=&transactionid=2577715978&avsresponse=&cvvresponse=M&orderid=&type=sale&response_code=200

tests/Mock/DirectPostSaleSuccess.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:19:43 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 136
5+
Connection: close
6+
Server:
7+
8+
response=1&responsetext=SUCCESS&authcode=123456&transactionid=2577715564&avsresponse=&cvvresponse=M&orderid=&type=sale&response_code=100

tests/Mock/DirectPostVoidFailure.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:34:58 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 188
5+
Connection: close
6+
Server:
7+
8+
response=3&responsetext=Only transactions pending settlement can be voided REFID:143498494&authcode=&transactionid=2577708057&avsresponse=&cvvresponse=&orderid=&type=void&response_code=300

tests/Mock/DirectPostVoidSuccess.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 00:33:05 GMT
3+
Content-Type: text/html; charset=UTF-8
4+
Content-Length: 155
5+
Connection: close
6+
Server:
7+
8+
response=1&responsetext=Transaction Void Successful&authcode=123456&transactionid=2577708057&avsresponse=&cvvresponse=&orderid=&type=void&response_code=100

0 commit comments

Comments
 (0)