diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index ffcb047..75fd802 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -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() { @@ -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(); diff --git a/src/Message/RapidCreateCardRequest.php b/src/Message/RapidCreateCardRequest.php index 489521b..bbd7095 100644 --- a/src/Message/RapidCreateCardRequest.php +++ b/src/Message/RapidCreateCardRequest.php @@ -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'); diff --git a/src/Message/RapidDirectCreateCardRequest.php b/src/Message/RapidDirectCreateCardRequest.php index 7894242..26b66f1 100644 --- a/src/Message/RapidDirectCreateCardRequest.php +++ b/src/Message/RapidDirectCreateCardRequest.php @@ -5,6 +5,9 @@ namespace Omnipay\Eway\Message; +use Omnipay\Eway\RapidDirectGateway; +use Omnipay\Omnipay; + /** * eWAY Rapid Direct Create Card Request * @@ -78,6 +81,25 @@ 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; } } diff --git a/src/Message/RapidDirectCreateCardResponse.php b/src/Message/RapidDirectCreateCardResponse.php index 2648620..5441049 100644 --- a/src/Message/RapidDirectCreateCardResponse.php +++ b/src/Message/RapidDirectCreateCardResponse.php @@ -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()); + } } }