1
0

Added base plugin, in preperation for the API

This commit is contained in:
Christiaan Goossens 2017-02-19 11:19:42 +01:00
parent 64d7fa13d7
commit 4f4b7a9d40
6 changed files with 176 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?php
namespace Omnipay\Inforbank\Message;
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
abstract class AbstractRequest extends BaseAbstractRequest
{
abstract protected function generateSignature();
public function getClientId()
{
return $this->getParameter('clientId');
}
public function getClientSecret()
{
return $this->getParameter('clientSecret');
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Omnipay\Inforbank\Message;
use Omnipay\Common\Message\AbstractResponse as BaseAbstractResponse;
use Omnipay\Common\Message\RequestInterface;
abstract class AbstractResponse extends BaseAbstractResponse
{
protected $error;
public function __construct(RequestInterface $request, $data)
{
parent::__construct($request, $data);
if (!$this->data->success) {
$this->error = (string) $this->data->error;
}
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace Omnipay\Inforbank\Message;
class CompletePurchaseRequest extends AbstractRequest
{
protected $endpoint = "https://inforbank.nl/api/statusRequest";
protected function generateSignature()
{
return sha1(
$this->getTransactionReference() . $this->getClientId() . $this->getClientSecret()
);
}
public function getTransactionReference()
{
return $this->httpRequest->query->get('trxid');
}
public function getData()
{
$this->validate('merchantId', 'merchantKey');
$data = array(
"clientId" => $this->getClientId(),
"clientSecret" => $this->getClientSecret(),
"transactionId" => $this->getTransactionReference(),
"sha1" => $this->generateSignature()
);
}
public function sendData($data)
{
$httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send();
return $this->response = new CompletePurchaseResponse($this, $httpResponse->json());
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Omnipay\Inforbank\Message;
class CompletePurchaseResponse extends PurchaseResponse
{
public function isSuccessful()
{
return ($this->data->transaction->status === "Success");
}
public function isRedirect()
{
return false;
}
public function getStatus()
{
return $this->data->transaction->status;
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Omnipay\Inforbank\Message;
class PurchaseRequest extends AbstractRequest
{
protected $endpoint = "https://inforbank.nl/api/transactionRequest";
protected function generateSignature()
{
return sha1(
$this->getTransactionId() . $this->getAmountInteger() . $this->getClientId() . $this->getClientSecret()
);
}
public function getData()
{
$this->validate(
'amount',
'transactionId',
'returnUrl'
);
$data = array(
"clientId" => $this->getClientId(),
"clientSecret" => $this->getClientSecret(),
"transactionId" => $this->getTransactionId(),
"amount" => $this->getAmountInteger(),
"description" => $this->getDescription(),
"returnUrl" => $this->getReturnUrl(),
"sha1" => $this->generateSignature()
);
}
public function sendData($data)
{
$httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send();
return $this->response = new PurchaseResponse($this, $httpResponse->json());
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace Omnipay\Inforbank\Message;
use Omnipay\Common\Message\RedirectResponseInterface;
class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface
{
public function isSuccessful()
{
return false;
}
public function isRedirect()
{
return is_null($this->error);
}
public function isPending()
{
return true;
}
public function getRedirectUrl()
{
return $this->data->redirect;
}
public function getRedirectMethod()
{
return 'GET';
}
public function getRedirectData()
{
return null;
}
}