diff --git a/src/Gateway.php b/src/Gateway.php index 72387c2..e8ebf81 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -287,6 +287,11 @@ public function getCard(array $parameters = []) return $this->createRequest(Message\GetCardRequest::class, $parameters); } + public function createCard(array $parameters = []) + { + return $this->createRequest(Message\CreateCardRequest::class, $parameters); + } + /** * @param array $parameters * @return Message\GetBankStatusRequest diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index eda2fc7..3f7da32 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -8,6 +8,8 @@ use Omnipay\Common\Message\RedirectResponseInterface; use Omnipay\Common\Message\AbstractResponse as OmnipayAbstractResponse; +use Omnipay\GiroCheckout\Gateway; +use Omnipay\Omnipay; abstract class AbstractResponse extends OmnipayAbstractResponse { @@ -23,4 +25,39 @@ protected function getDataItem($name, $default = null) $data = $this->getData(); return isset($this->data[$name]) ? $this->data[$name] : $default; } + + /** + * Get the card reference, if one was requested. + * We don't know what was originally requeste, so we just go to + * the gateway to ask for a reference. + */ + public function getCardReference() + { + if (! $this->isSuccessful()) { + // The transaction was not successful, so there won't be a + // card reference to fetch. + + return null; + } + + // Build a new request. + + $gateway = Omnipay::create('\\' . Gateway::class); + + $gateway->setMerchantId($this->request->getMerchantId(true)); + $gateway->setProjectId($this->request->getProjectId(true)); + $gateway->setProjectId($this->request->getProjectId(true)); + $gateway->setProjectPassphrase($this->request->getProjectPassphrase()); + $gateway->setPaymentType($this->request->getPaymentType()); + + $request = $gateway->getCard(); + + $request->setTransactionReference($this->getTransactionReference()); + + $response = $request->send(); + + if ($response->isSuccessful()) { + return $response->getCardReference(); + } + } } diff --git a/src/Message/CreateCardRequest.php b/src/Message/CreateCardRequest.php new file mode 100644 index 0000000..25d1bdf --- /dev/null +++ b/src/Message/CreateCardRequest.php @@ -0,0 +1,13 @@ +setCreateCard(true); + + return parent::getData(); + } +}