Skip to content

Commit 1e7efb8

Browse files
Honour purchase action for createCardRequest.
Eway does not natively allow you to make a concurrent purchase with a card creation for the Direct gateway (only). I think we should be honouring this pattern (which is used on other gateways) and we can do it by internally doing the purchase when the card is created.
1 parent e516e65 commit 1e7efb8

4 files changed

+71
-23
lines changed

src/Message/AbstractRequest.php

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
1616
{
1717
protected $liveEndpoint = 'https://api.ewaypayments.com';
1818
protected $testEndpoint = 'https://api.sandbox.ewaypayments.com';
19+
protected $action;
1920

2021
public function getApiKey()
2122
{
@@ -84,6 +85,22 @@ public function setInvoiceReference($value)
8485
return $this->setParameter('invoiceReference', $value);
8586
}
8687

88+
/**
89+
* @return string|NULL
90+
*/
91+
public function getAction()
92+
{
93+
return $this->action;
94+
}
95+
96+
/**
97+
* @param string $action
98+
*/
99+
public function setAction($action)
100+
{
101+
$this->action = $action;
102+
}
103+
87104
protected function getBaseData()
88105
{
89106
$data = array();

src/Message/RapidCreateCardRequest.php

-18
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,6 @@
1414
*/
1515
class RapidCreateCardRequest extends RapidPurchaseRequest
1616
{
17-
protected $action;
18-
19-
/**
20-
* @return string|NULL
21-
*/
22-
public function getAction()
23-
{
24-
return $this->action;
25-
}
26-
27-
/**
28-
* @param string $action
29-
*/
30-
public function setAction($action)
31-
{
32-
$this->action = $action;
33-
}
34-
3517
public function getData()
3618
{
3719
$this->validate('returnUrl');

src/Message/RapidDirectCreateCardRequest.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Omnipay\Eway\Message;
77

8+
use Omnipay\Eway\RapidDirectGateway;
9+
use Omnipay\Omnipay;
10+
811
/**
912
* eWAY Rapid Direct Create Card Request
1013
*
@@ -78,6 +81,25 @@ public function sendData($data)
7881
->setAuth($this->getApiKey(), $this->getPassword())
7982
->send();
8083

81-
return $this->response = new RapidDirectCreateCardResponse($this, $httpResponse->json());
84+
$this->response = new RapidDirectCreateCardResponse($this, $httpResponse->json());
85+
86+
if ($this->getAction() === 'Purchase' && $this->response->isSuccessful()) {
87+
/** @var RapidDirectGateway $purchaseGateway */
88+
$purchaseGateway = Omnipay::create('Eway_RapidDirect');
89+
$purchaseGateway->setApiKey($this->getApiKey());
90+
$purchaseGateway->setPassword($this->getPassword());
91+
$purchaseGateway->setTestMode($this->getTestMode());
92+
$purchaseResponse = $purchaseGateway->purchase(array(
93+
'amount' => $this->getAmount(),
94+
'currency' => $this->getCurrency(),
95+
'description' => $this->getDescription(),
96+
'transactionId' => $this->getTransactionId(),
97+
'card' => $this->getCard(),
98+
'cardReference' => $this->response->getCardReference(),
99+
))->send();
100+
}
101+
$this->response->setPurchaseResponse($purchaseResponse);
102+
103+
return $this->response;
82104
}
83105
}

src/Message/RapidDirectCreateCardResponse.php

+31-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,47 @@
22
/**
33
* eWAY Rapid Direct Create Card Response
44
*/
5-
5+
66
namespace Omnipay\Eway\Message;
77

8+
use Omnipay\SecurePay\Message\DirectPostCompletePurchaseResponse;
9+
810
/**
911
* eWAY Rapid Direct Create Card Response
10-
*
11-
* This is the response class for Rapid Direct when creating
12+
*
13+
* This is the response class for Rapid Direct when creating
1214
* or updating a card
1315
*
1416
*/
1517
class RapidDirectCreateCardResponse extends RapidResponse
1618
{
19+
/**
20+
* @var DirectPostCompletePurchaseResponse
21+
*/
22+
protected $purchaseResponse;
23+
24+
/**
25+
* @return DirectPostCompletePurchaseResponse
26+
*/
27+
public function getPurchaseResponse()
28+
{
29+
return $this->purchaseResponse;
30+
}
31+
32+
/**
33+
* @param DirectPostCompletePurchaseResponse $purchaseResponse
34+
*/
35+
public function setPurchaseResponse($purchaseResponse)
36+
{
37+
$this->purchaseResponse = $purchaseResponse;
38+
}
39+
1740
public function isSuccessful()
1841
{
19-
return $this->data['ResponseMessage'] == 'A2000';
42+
if (!$this->getPurchaseResponse()) {
43+
return $this->data['ResponseMessage'] == 'A2000';
44+
} else {
45+
return ($this->data['ResponseMessage'] == 'A2000' && $this->purchaseResponse->isSuccessful());
46+
}
2047
}
2148
}

0 commit comments

Comments
 (0)