Skip to content

Commit c22731d

Browse files
committed
Merge pull request #15 from alexw23/void-rapiddirect
Add void direct
2 parents 507a394 + 94c7a1f commit c22731d

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* eWAY Rapid Void Request
4+
*/
5+
6+
namespace Omnipay\Eway\Message;
7+
8+
class RapidDirectVoidRequest extends AbstractRequest
9+
{
10+
public function getData()
11+
{
12+
$this->validate('transactionReference');
13+
14+
$data = array();
15+
$data['TransactionId'] = $this->getTransactionReference();
16+
17+
return $data;
18+
}
19+
20+
protected function getEndpoint()
21+
{
22+
return $this->getEndpointBase().'/CancelAuthorisation';
23+
}
24+
25+
public function sendData($data)
26+
{
27+
// This request uses the REST endpoint and requires the JSON content type header
28+
$httpResponse = $this->httpClient->post(
29+
$this->getEndpoint(),
30+
array('content-type' => 'application/json'),
31+
json_encode($data)
32+
)
33+
->setAuth($this->getApiKey(), $this->getPassword())
34+
->send();
35+
return $this->response = new RapidResponse($this, $httpResponse->json());
36+
}
37+
}

src/RapidDirectGateway.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ public function refund(array $parameters = array())
185185
return $this->createRequest('\Omnipay\Eway\Message\RefundRequest', $parameters);
186186
}
187187

188+
/**
189+
* Void a Transaction
190+
*
191+
* @link https://eway.io/api-v3/#pre-auth
192+
* @param array $parameters
193+
* @return \Omnipay\Eway\Message\RapidDirectVoidRequest
194+
*/
195+
public function void(array $parameters = array())
196+
{
197+
return $this->createRequest('\Omnipay\Eway\Message\RapidDirectVoidRequest', $parameters);
198+
}
199+
188200
/**
189201
* Store a credit card as a Token
190202
*
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class RapidDirectVoidRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new RapidDirectVoidRequest($this->getHttpClient(), $this->getHttpRequest());
12+
$this->request->initialize(array(
13+
'apiKey' => 'my api key',
14+
'password' => 'secret',
15+
'transactionReference' => '4324324'
16+
));
17+
}
18+
19+
public function testGetData()
20+
{
21+
$this->request->initialize(array(
22+
'apiKey' => 'my api key',
23+
'password' => 'secret',
24+
'transactionReference' => '4324324'
25+
));
26+
27+
$data = $this->request->getData();
28+
29+
$this->assertSame('4324324', $data['TransactionId']);
30+
}
31+
32+
public function testSendSuccess()
33+
{
34+
$this->setMockHttpResponse('RapidDirectVoidRequestSuccess.txt');
35+
$response = $this->request->send();
36+
37+
$this->assertTrue($response->isSuccessful());
38+
$this->assertFalse($response->isRedirect());
39+
$this->assertSame('12921019', $response->getTransactionReference());
40+
$this->assertSame('Transaction Approved', $response->getMessage());
41+
}
42+
43+
public function testSendFailure()
44+
{
45+
$this->setMockHttpResponse('RapidDirectVoidRequestFailure.txt');
46+
$response = $this->request->send();
47+
48+
$this->assertFalse($response->isSuccessful());
49+
$this->assertFalse($response->isRedirect());
50+
$this->assertSame('0', $response->getTransactionReference());
51+
$this->assertSame('Invalid Auth Transaction ID for Capture/Void', $response->getMessage());
52+
$this->assertSame('V6134', $response->getCode());
53+
}
54+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
HTTP/1.1 200 OK
2+
Cache-control: no-cache="set-cookie"
3+
Content-Type: application/json; charset=utf-8
4+
Date: Wed, 01 Jun 2016 06:00:19 GMT
5+
p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
6+
Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D02FB0E46BA8D67B7A800B44A7D2ED0D94C6B4D750DDAD028ED5C0787DEB1569FF96BD73CDCF09B6E3F354EB31B6537F6;PATH=/;MAX-AGE=86400
7+
X-EWAY-VIA: api-au.sandbox.ewaypayments.com/
8+
X-EWAY-VIA-FROM: http://api.sandbox.ewaypayments.com/CancelAuthorisation
9+
X-EWAY-VIA-HTTP-METHOD: POST
10+
X-EWAY-VIA-HTTP-STATUS: 200
11+
X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CancelAuthorisation
12+
X-ID: AM-143
13+
X-Powered-By: eWAY
14+
Content-Length: 105
15+
Connection: keep-alive
16+
17+
{"ResponseCode":null,"ResponseMessage":null,"TransactionID":0,"TransactionStatus":false,"Errors":"V6134"}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
HTTP/1.1 200 OK
2+
Cache-control: no-cache="set-cookie"
3+
Content-Type: application/json; charset=utf-8
4+
Date: Wed, 01 Jun 2016 06:03:27 GMT
5+
p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
6+
Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D02FB0E46BA8D67B7A800B44A7D2ED0D94C6B4D750DDAD028ED5C0787DEB1569FF96BD73CDCF09B6E3F354EB31B6537F6;PATH=/;MAX-AGE=86400
7+
X-EWAY-VIA: api-au.sandbox.ewaypayments.com/
8+
X-EWAY-VIA-FROM: http://api.sandbox.ewaypayments.com/CancelAuthorisation
9+
X-EWAY-VIA-HTTP-METHOD: POST
10+
X-EWAY-VIA-HTTP-STATUS: 200
11+
X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CancelAuthorisation
12+
X-ID: AM-143
13+
X-Powered-By: eWAY
14+
Content-Length: 116
15+
Connection: keep-alive
16+
17+
{"ResponseCode":"932181","ResponseMessage":"Transaction Approved","TransactionID":12921019,"TransactionStatus":true,"Errors":null}

0 commit comments

Comments
 (0)