Skip to content

Commit 507a394

Browse files
committed
Merge pull request #14 from incarnate/create-success
Fix Rapid Direct create and update card
2 parents 1c95363 + 3c2854f commit 507a394

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

src/Message/RapidDirectCreateCardRequest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
* Once submitted, a TokenCustomerID is provided which can be
1313
* used in future transactions instead of the card details.
1414
*
15-
* Note that since no transaction is processed, the transaction
16-
* status is returned as false when a token is created. This means that
17-
* isSuccessful() cannot be used to check for success.
18-
*
1915
* Example:
2016
*
2117
* <code>
@@ -49,7 +45,9 @@
4945
* ));
5046
*
5147
* $response = $request->send();
52-
* $cardReference = $response->getCardReference();
48+
* if ($response->isSuccessful()) {
49+
* $cardReference = $response->getCardReference();
50+
* }
5351
* </code>
5452
*
5553
* @link https://eway.io/api-v3/#direct-connection
@@ -73,4 +71,13 @@ protected function getEndpoint()
7371
{
7472
return $this->getEndpointBase().'/DirectPayment.json';
7573
}
74+
75+
public function sendData($data)
76+
{
77+
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, json_encode($data))
78+
->setAuth($this->getApiKey(), $this->getPassword())
79+
->send();
80+
81+
return $this->response = new RapidDirectCreateCardResponse($this, $httpResponse->json());
82+
}
7683
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* eWAY Rapid Direct Create Card Response
4+
*/
5+
6+
namespace Omnipay\Eway\Message;
7+
8+
/**
9+
* eWAY Rapid Direct Create Card Response
10+
*
11+
* This is the response class for Rapid Direct when creating
12+
* or updating a card
13+
*
14+
*/
15+
class RapidDirectCreateCardResponse extends RapidResponse
16+
{
17+
public function isSuccessful()
18+
{
19+
return $this->data['ResponseMessage'] == 'A2000';
20+
}
21+
}

src/Message/RapidDirectUpdateCardRequest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
* This requires the TokenCustomerID of the token being updated, handled
1515
* in OmniPay as the cardReference.
1616
*
17-
* Note that since no transaction is processed, the transaction
18-
* status is returned as false when a token is created. This means that
19-
* isSuccessful() cannot be used to check for success.
20-
*
2117
* Example:
2218
*
2319
* <code>
@@ -52,7 +48,9 @@
5248
* ));
5349
*
5450
* $response = $request->send();
55-
* $cardReference = $response->getCardReference();
51+
* if ($response->isSuccessful()) {
52+
* $cardReference = $response->getCardReference();
53+
* }
5654
* </code>
5755
*
5856
* @link https://eway.io/api-v3/#direct-connection
@@ -80,4 +78,13 @@ protected function getEndpoint()
8078
{
8179
return $this->getEndpointBase().'/DirectPayment.json';
8280
}
81+
82+
public function sendData($data)
83+
{
84+
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, json_encode($data))
85+
->setAuth($this->getApiKey(), $this->getPassword())
86+
->send();
87+
88+
return $this->response = new RapidDirectCreateCardResponse($this, $httpResponse->json());
89+
}
8390
}

tests/Message/RapidDirectCreateCardRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testSendSuccess()
7575
$this->setMockHttpResponse('RapidDirectCreateCardRequestSuccess.txt');
7676
$response = $this->request->send();
7777

78-
$this->assertFalse($response->isSuccessful());
78+
$this->assertTrue($response->isSuccessful());
7979
$this->assertSame(916260137222, $response->getCardReference());
8080
$this->assertSame('Transaction Approved', $response->getMessage());
8181
}

tests/Message/RapidDirectUpdateCardRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testSendSuccess()
6565
$this->setMockHttpResponse('RapidDirectUpdateCardRequestSuccess.txt');
6666
$response = $this->request->send();
6767

68-
$this->assertFalse($response->isSuccessful());
68+
$this->assertTrue($response->isSuccessful());
6969
$this->assertSame(917758625852, $response->getCardReference());
7070
$this->assertSame('Transaction Approved', $response->getMessage());
7171
}

0 commit comments

Comments
 (0)