Skip to content

Commit

Permalink
[skeleton] to easy new extension development.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Dec 14, 2015
0 parents commit 36d7903
Show file tree
Hide file tree
Showing 13 changed files with 498 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Action/Api/BaseApiAwareAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace Payum\Skeleton\Action\Api;

use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Skeleton\Api;

abstract class BaseApiAwareAction implements ActionInterface, ApiAwareInterface
{
/**
* @var Config
*/
protected $api;

/**
* {@inheritDoc}
*/
public function setApi($api)
{
if (false == $api instanceof Api) {
throw new UnsupportedApiException(sprintf('Not supported. Expected %s instance to be set as api.', Api::class));
}

$this->api = $api;
}
}
35 changes: 35 additions & 0 deletions Action/AuthorizeAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Payum\Skeleton\Action;

use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Request\Authorize;
use Payum\Core\Exception\RequestNotSupportedException;

class AuthorizeAction extends GatewayAwareAction
{
/**
* {@inheritDoc}
*
* @param Authorize $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);

$model = ArrayObject::ensureArrayObject($request->getModel());

throw new \LogicException('Not implemented');
}

/**
* {@inheritDoc}
*/
public function supports($request)
{
return
$request instanceof Authorize &&
$request->getModel() instanceof \ArrayAccess
;
}
}
35 changes: 35 additions & 0 deletions Action/CancelAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Payum\Skeleton\Action;

use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Request\Cancel;

class CancelAction extends GatewayAwareAction
{
/**
* {@inheritDoc}
*
* @param Cancel $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);

$model = ArrayObject::ensureArrayObject($request->getModel());

throw new \LogicException('Not implemented');
}

/**
* {@inheritDoc}
*/
public function supports($request)
{
return
$request instanceof Cancel &&
$request->getModel() instanceof \ArrayAccess
;
}
}
35 changes: 35 additions & 0 deletions Action/CaptureAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Payum\Skeleton\Action;

use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Request\Capture;
use Payum\Core\Exception\RequestNotSupportedException;

class CaptureAction extends GatewayAwareAction
{
/**
* {@inheritDoc}
*
* @param Capture $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);

$model = ArrayObject::ensureArrayObject($request->getModel());

throw new \LogicException('Not implemented');
}

/**
* {@inheritDoc}
*/
public function supports($request)
{
return
$request instanceof Capture &&
$request->getModel() instanceof \ArrayAccess
;
}
}
40 changes: 40 additions & 0 deletions Action/ConvertPaymentAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace Payum\Skeleton\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Model\PaymentInterface;
use Payum\Core\Request\Convert;
use Payum\Core\Request\GetCurrency;

class ConvertPaymentAction extends GatewayAwareAction
{
/**
* {@inheritDoc}
*
* @param Convert $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);

/** @var PaymentInterface $payment */
$payment = $request->getSource();

throw new \LogicException('Not implemented');
}

/**
* {@inheritDoc}
*/
public function supports($request)
{
return
$request instanceof Convert &&
$request->getSource() instanceof PaymentInterface &&
$request->getTo() == 'array'
;
}
}
34 changes: 34 additions & 0 deletions Action/NotifyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace Payum\Skeleton\Action;

use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;

class NotifyAction extends GatewayAwareAction
{
/**
* {@inheritDoc}
*
* @param Notify $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);

$model = ArrayObject::ensureArrayObject($request->getModel());

throw new \LogicException('Not implemented');
}

/**
* {@inheritDoc}
*/
public function supports($request)
{
return
$request instanceof Notify &&
$request->getModel() instanceof \ArrayAccess
;
}
}
35 changes: 35 additions & 0 deletions Action/RefundAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Payum\Skeleton\Action;

use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Request\Refund;

class RefundAction extends GatewayAwareAction
{
/**
* {@inheritDoc}
*
* @param Refund $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);

$model = ArrayObject::ensureArrayObject($request->getModel());

throw new \LogicException('Not implemented');
}

/**
* {@inheritDoc}
*/
public function supports($request)
{
return
$request instanceof Refund &&
$request->getModel() instanceof \ArrayAccess
;
}
}
35 changes: 35 additions & 0 deletions Action/StatusAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Payum\Skeleton\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Request\GetStatusInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;

class StatusAction implements ActionInterface
{
/**
* {@inheritDoc}
*
* @param GetStatusInterface $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);

$model = ArrayObject::ensureArrayObject($request->getModel());

throw new \LogicException('Not implemented');
}

/**
* {@inheritDoc}
*/
public function supports($request)
{
return
$request instanceof GetStatusInterface &&
$request->getModel() instanceof \ArrayAccess
;
}
}
60 changes: 60 additions & 0 deletions Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
namespace Payum\Skeleton;

use GuzzleHttp\Psr7\Request;
use Payum\Core\Bridge\Guzzle\HttpClientFactory;
use Payum\Core\Exception\Http\HttpException;
use Payum\Core\HttpClientInterface;

class Api
{
/**
* @var HttpClientInterface
*/
protected $client;

/**
* @var array
*/
protected $options = [];

/**
* @param array $options
* @param HttpClientInterface $client
*
* @throws \Payum\Core\Exception\InvalidArgumentException if an option is invalid
*/
public function __construct(array $options, HttpClientInterface $client = null)
{
$this->options = $options;
$this->client = $client ?: HttpClientFactory::create();
}

/**
* @param array $fields
*
* @return array
*/
protected function doRequest($method, array $fields)
{
$headers = [];

$request = new Request($method, $this->getApiEndpoint(), $headers, http_build_query($fields));

$response = $this->client->send($request);

if (false == ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)) {
throw HttpException::factory($request, $response);
}

return $response;
}

/**
* @return string
*/
protected function getApiEndpoint()
{
return $this->options['sandbox'] ? 'http://sandbox.example.com' : 'http://example.com';
}
}
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2015 Maksim Kotlyar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading

0 comments on commit 36d7903

Please sign in to comment.