-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skeleton] to easy new extension development.
- Loading branch information
0 parents
commit 36d7903
Showing
13 changed files
with
498 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.