Skip to content

Commit

Permalink
Issue #6 support createCard() as a request.
Browse files Browse the repository at this point in the history
No documentation yet, and we may need to restrict this to just
credit and debit card payment types, but it's working to try out.
  • Loading branch information
judgej committed Aug 23, 2018
1 parent 2669df4 commit 12b080a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions src/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}
}
}
13 changes: 13 additions & 0 deletions src/Message/CreateCardRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Omnipay\GiroCheckout\Message;

class CreateCardRequest extends AuthorizeRequest
{
public function getData()
{
$this->setCreateCard(true);

return parent::getData();
}
}

0 comments on commit 12b080a

Please sign in to comment.