Skip to content

Commit

Permalink
Honour purchase action for createCardRequest.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eileenmcnaughton committed Oct 15, 2017
1 parent e516e65 commit a225346
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 23 deletions.
17 changes: 17 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
protected $liveEndpoint = 'https://api.ewaypayments.com';
protected $testEndpoint = 'https://api.sandbox.ewaypayments.com';
protected $action;

public function getApiKey()
{
Expand Down Expand Up @@ -84,6 +85,22 @@ public function setInvoiceReference($value)
return $this->setParameter('invoiceReference', $value);
}

/**
* @return string|NULL
*/
public function getAction()
{
return $this->action;
}

/**
* @param string $action
*/
public function setAction($action)
{
$this->action = $action;
}

protected function getBaseData()
{
$data = array();
Expand Down
18 changes: 0 additions & 18 deletions src/Message/RapidCreateCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@
*/
class RapidCreateCardRequest extends RapidPurchaseRequest
{
protected $action;

/**
* @return string|NULL
*/
public function getAction()
{
return $this->action;
}

/**
* @param string $action
*/
public function setAction($action)
{
$this->action = $action;
}

public function getData()
{
$this->validate('returnUrl');
Expand Down
25 changes: 24 additions & 1 deletion src/Message/RapidDirectCreateCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Omnipay\Eway\Message;

use Omnipay\Eway\RapidDirectGateway;
use Omnipay\Omnipay;

/**
* eWAY Rapid Direct Create Card Request
*
Expand Down Expand Up @@ -78,6 +81,26 @@ public function sendData($data)
->setAuth($this->getApiKey(), $this->getPassword())
->send();

return $this->response = new RapidDirectCreateCardResponse($this, $httpResponse->json());
$this->response = new RapidDirectCreateCardResponse($this, $httpResponse->json());

if ($this->getAction() === 'Purchase' && $this->response->isSuccessful())
{
/** @var RapidDirectGateway $purchaseGateway */
$purchaseGateway = Omnipay::create('Eway_RapidDirect');
$purchaseGateway->setApiKey($this->getApiKey());
$purchaseGateway->setPassword($this->getPassword());
$purchaseGateway->setTestMode($this->getTestMode());
$purchaseResponse = $purchaseGateway->purchase(array(
'amount' => $this->getAmount(),
'currency' => $this->getCurrency(),
'description' => $this->getDescription(),
'transactionId' => $this->getTransactionId(),
'card' => $this->getCard(),
'cardReference' => $this->response->getCardReference(),
))->send();
}
$this->response->setPurchaseResponse($purchaseResponse);

return $this->response;
}
}
35 changes: 31 additions & 4 deletions src/Message/RapidDirectCreateCardResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,47 @@
/**
* eWAY Rapid Direct Create Card Response
*/

namespace Omnipay\Eway\Message;

use Omnipay\SecurePay\Message\DirectPostCompletePurchaseResponse;

/**
* eWAY Rapid Direct Create Card Response
*
* This is the response class for Rapid Direct when creating
*
* This is the response class for Rapid Direct when creating
* or updating a card
*
*/
class RapidDirectCreateCardResponse extends RapidResponse
{
/**
* @var DirectPostCompletePurchaseResponse
*/
protected $purchaseResponse;

/**
* @return DirectPostCompletePurchaseResponse
*/
public function getPurchaseResponse()
{
return $this->purchaseResponse;
}

/**
* @param DirectPostCompletePurchaseResponse $purchaseResponse
*/
public function setPurchaseResponse($purchaseResponse)
{
$this->purchaseResponse = $purchaseResponse;
}

public function isSuccessful()
{
return $this->data['ResponseMessage'] == 'A2000';
if (!$this->getPurchaseResponse()) {
return $this->data['ResponseMessage'] == 'A2000';
} else {
return ($this->data['ResponseMessage'] == 'A2000' && $this->purchaseResponse->isSuccessful());
}
}
}

0 comments on commit a225346

Please sign in to comment.