1
0
Fork 0

Added base plugin, in preperation for the API

master
Christiaan Goossens 7 years ago
parent 64d7fa13d7
commit 3e0d67caca

@ -48,7 +48,7 @@ repository.
));
// Start the purchase
if (!isset($_GET['status'])) {
if (!isset($_GET['trxid'])) {
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$response = $gateway->purchase(array(
'amount' => "1.50",

@ -4,15 +4,13 @@ namespace Omnipay\Inforbank;
use Omnipay\Common\AbstractGateway;
class Gateway extends AbstractGateway {
public function getName() {
class Gateway extends AbstractGateway
{
public function getName()
{
return 'Inforbank';
}
public function getDefaultParameters() {
return array();
}
/**
* Start a purchase request.
* @param array $parameters An array of options

@ -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');
}
}

@ -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;
}
}
}

@ -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());
}
}

@ -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;
}
}

@ -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());
}
}

@ -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;
}
}