Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris de Jong committed Mar 2, 2017
0 parents commit ad033d4
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor
composer.lock
composer.phar
phpunit.xml
/nbproject/
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm

before_script:
- composer install -n --dev --prefer-source

script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "eventix/omnipay-backoffice",
"type": "library",
"description": "Backoffice driver for the Omnipay payment processing library",
"keywords": [
"gateway",
"merchant",
"paynl",
"omnipay",
"pay",
"payment"
],
"homepage": "https://www.eventix.nl",
"license": "MIT",
"authors": [
{
"name": "Chris de Jong",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": { "Omnipay\\Backoffice\\" : "src/" }
},
"require": {
"omnipay/common": "~2.2"
},
"require-dev": {
"omnipay/tests": "~2.0"
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}
33 changes: 33 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Omnipay\Backoffice;

use Omnipay\Common\AbstractGateway;

/**
* Backoffice Payment methods
*
* Used for 'offline' payment methods as
* PIN / Cash which will be paid directly
* withouth any 'online' paymentProvider.
*
*/
class Gateway extends AbstractGateway
{
/**
* @return string
*/
public function getName()
{
return 'Backoffice';
}

/**
* @param array $parameters
* @return \Omnipay\Backoffice\Message\PurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Backoffice\Message\PurchaseRequest', $parameters);
}
}
63 changes: 63 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Omnipay\Backoffice\Message;

use Guzzle\Common\Event;

abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest {

protected $endpoint = 'https://rest-api.pay.nl/v5/';

/**
* @return string
*/
public function getApitoken() {
return $this->getParameter('apitoken');
}

/**
* @param string $value
* @return $this
*/
public function setApitoken($value) {
return $this->setParameter('apitoken', $value);
}

/**
* @return string
*/
public function getServiceId() {
return $this->getParameter('serviceId');
}

/**
* @param string $value
* @return $this
*/
public function setServiceId($value) {
return $this->setParameter('serviceId', $value);
}

protected function sendRequest($method, $endpoint, array $data = array()) {
$this->httpClient->getEventDispatcher()->addListener('request.error', function (Event $event) {
/**
* @var \Guzzle\Http\Message\Response $response
*/
$response = $event['response'];

if ($response->isError()) {
$event->stopPropagation();
}
});

$data['token'] = $this->getApitoken();
$data['serviceId'] = $this->getServiceId();

$httpRequest = $this->httpClient->createRequest(
$method, $this->endpoint . $endpoint.'/json', array(), $data
);

return $httpRequest->send();
}

}
16 changes: 16 additions & 0 deletions src/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Omnipay\Backoffice\Message;

class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse
{
public function isSuccessful()
{
return true;
}

public function getMessage()
{
return '';
}
}
116 changes: 116 additions & 0 deletions src/Message/FetchTransactionResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace Omnipay\Backoffice\Message;

use Omnipay\Common\Message\RedirectResponseInterface;

class FetchTransactionResponse extends AbstractResponse implements RedirectResponseInterface
{
/**
* {@inheritdoc}
*/
public function isRedirect()
{
return false;
}

/**
* {@inheritdoc}
*/
public function getRedirectUrl()
{
return false;
}

/**
* {@inheritdoc}
*/
public function getRedirectMethod()
{
return 'GET';
}

/**
* {@inheritdoc}
*/
public function getRedirectData()
{
return null;
}

/**
* {@inheritdoc}
*/
public function isSuccessful()
{
return parent::isSuccessful();
}

/**
* @return boolean
*/
public function isOpen()
{
return false;
}

/**
* @return boolean
*/
public function isCancelled()
{
return false;
}

/**
* @return boolean
*/
public function isPaid()
{
return true;
}

/**
* @return boolean
*/
public function isExpired()
{
return false;
}

/**
* @return mixed
*/
public function getTransactionReference()
{
if(isset($this->data['paymentMethod'])) {
return $this->data['paymentMethod'];
}
}

/**
* @return mixed
*/
public function getStatus()
{
return 'paid';
}

/**
* @return mixed
*/
public function getAmount()
{
if(isset($this->data['amount'])) {
return $this->data['amount'];
}
}

/**
* @return bool
*/
public function isPending()
{
return false;
}
}
36 changes: 36 additions & 0 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Omnipay\Backoffice\Message;

/**
* Backoffice Purchase Request
*
* @method \Omnipay\Backoffice\Message\PurchaseResponse send()
*/
class PurchaseRequest extends AbstractRequest {

/**
* Return the data formatted for PAY.nl
* @return array
*/
public function getData() {
$this->validate('paymentMethod');
$data['amount'] = round($this->getAmount() * 100);
$data['transaction']['description'] = $this->getDescription();
$data['finishUrl'] = $this->getReturnUrl();
$data['ipAddress'] = $this->getClientIp();
$data['paymentMethod'] = $this->getPaymentMethod();

$data['testMode'] = $this->getTestMode() ? 1 : 0;
return $data;
}

/**
* Send the data
* @param array $data
* @return AbstractResponse
*/
public function sendData($data) {
return $this->response = new PurchaseResponse($this, $this->getData());
}
}
16 changes: 16 additions & 0 deletions src/Message/PurchaseResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Omnipay\Backoffice\Message;

class PurchaseResponse extends FetchTransactionResponse
{
/**
* A Payment made through this gateway is always instant successful
*
*/
public function isSuccessful()
{
return true;
}

}

0 comments on commit ad033d4

Please sign in to comment.