diff --git a/Action/Api/BaseApiAwareAction.php b/Action/Api/BaseApiAwareAction.php new file mode 100644 index 0000000..e762571 --- /dev/null +++ b/Action/Api/BaseApiAwareAction.php @@ -0,0 +1,27 @@ +api = $api; + } +} diff --git a/Action/AuthorizeAction.php b/Action/AuthorizeAction.php new file mode 100644 index 0000000..abfadc0 --- /dev/null +++ b/Action/AuthorizeAction.php @@ -0,0 +1,35 @@ +getModel()); + + throw new \LogicException('Not implemented'); + } + + /** + * {@inheritDoc} + */ + public function supports($request) + { + return + $request instanceof Authorize && + $request->getModel() instanceof \ArrayAccess + ; + } +} diff --git a/Action/CancelAction.php b/Action/CancelAction.php new file mode 100644 index 0000000..40c010f --- /dev/null +++ b/Action/CancelAction.php @@ -0,0 +1,35 @@ +getModel()); + + throw new \LogicException('Not implemented'); + } + + /** + * {@inheritDoc} + */ + public function supports($request) + { + return + $request instanceof Cancel && + $request->getModel() instanceof \ArrayAccess + ; + } +} diff --git a/Action/CaptureAction.php b/Action/CaptureAction.php new file mode 100644 index 0000000..837995e --- /dev/null +++ b/Action/CaptureAction.php @@ -0,0 +1,35 @@ +getModel()); + + throw new \LogicException('Not implemented'); + } + + /** + * {@inheritDoc} + */ + public function supports($request) + { + return + $request instanceof Capture && + $request->getModel() instanceof \ArrayAccess + ; + } +} diff --git a/Action/ConvertPaymentAction.php b/Action/ConvertPaymentAction.php new file mode 100644 index 0000000..f48d895 --- /dev/null +++ b/Action/ConvertPaymentAction.php @@ -0,0 +1,40 @@ +getSource(); + + throw new \LogicException('Not implemented'); + } + + /** + * {@inheritDoc} + */ + public function supports($request) + { + return + $request instanceof Convert && + $request->getSource() instanceof PaymentInterface && + $request->getTo() == 'array' + ; + } +} diff --git a/Action/NotifyAction.php b/Action/NotifyAction.php new file mode 100644 index 0000000..6cfbac0 --- /dev/null +++ b/Action/NotifyAction.php @@ -0,0 +1,34 @@ +getModel()); + + throw new \LogicException('Not implemented'); + } + + /** + * {@inheritDoc} + */ + public function supports($request) + { + return + $request instanceof Notify && + $request->getModel() instanceof \ArrayAccess + ; + } +} diff --git a/Action/RefundAction.php b/Action/RefundAction.php new file mode 100644 index 0000000..d84b19a --- /dev/null +++ b/Action/RefundAction.php @@ -0,0 +1,35 @@ +getModel()); + + throw new \LogicException('Not implemented'); + } + + /** + * {@inheritDoc} + */ + public function supports($request) + { + return + $request instanceof Refund && + $request->getModel() instanceof \ArrayAccess + ; + } +} diff --git a/Action/StatusAction.php b/Action/StatusAction.php new file mode 100644 index 0000000..ca5ed05 --- /dev/null +++ b/Action/StatusAction.php @@ -0,0 +1,35 @@ +getModel()); + + throw new \LogicException('Not implemented'); + } + + /** + * {@inheritDoc} + */ + public function supports($request) + { + return + $request instanceof GetStatusInterface && + $request->getModel() instanceof \ArrayAccess + ; + } +} diff --git a/Api.php b/Api.php new file mode 100644 index 0000000..83c53a9 --- /dev/null +++ b/Api.php @@ -0,0 +1,60 @@ +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'; + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1d4d0bf --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea34638 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# Skeleton + +The Payum extension to rapidly build new extensions. + +1. Create new project + +```bash +$ composer create-project payum/skeleton +``` + +2. Replace all occurrences of `payum` with your vendor name. It may be your github name, for now let's say you choose: `acme`. +3. Replace all occurrences of `skeleton` with a payment gateway name. For example Stripe, Paypal etc. For now let's say you choose: `paypal`. +4. Register a gateway factory to the payum's builder and create a gateway: + +```php +addGatewayFactory('paypal', new \Acme\Paypal\PaypalGatewayFactory($defaultConfig)) + + ->addGateway('paypal', [ + 'factory' => 'paypal', + 'sandbox' => true, + ]) + + ->getPayum() +; +``` + +5. While using the gateway implement all method where you get `Not implemented` exception: + +```php +getGateway('paypal'); + +$model = new \ArrayObject([ + // ... +]); + +$paypal->execute(new Capture($model)); +``` + +## Resources + +* [Documentation](http://payum.org/doc) +* [Questions](http://stackoverflow.com/questions/tagged/payum) +* [Issue Tracker](https://github.com/Payum/Payum/issues) +* [Twitter](https://twitter.com/payumphp) + +## License + +Skeleton is released under the [MIT License](LICENSE). diff --git a/SkeletonGatewayFactory.php b/SkeletonGatewayFactory.php new file mode 100644 index 0000000..b9a3811 --- /dev/null +++ b/SkeletonGatewayFactory.php @@ -0,0 +1,47 @@ +defaults([ + 'payum.factory_name' => 'skeleton', + 'payum.factory_title' => 'skeleton', + 'payum.action.capture' => new CaptureAction(), + 'payum.action.authorize' => new AuthorizeAction(), + 'payum.action.refund' => new RefundAction(), + 'payum.action.cancel' => new CancelAction(), + 'payum.action.notify' => new NotifyAction(), + 'payum.action.status' => new StatusAction(), + 'payum.action.convert_payment' => new ConvertPaymentAction(), + ]); + + if (false == $config['payum.api']) { + $config['payum.default_options'] = array( + 'sandbox' => true, + ); + $config->defaults($config['payum.default_options']); + $config['payum.required_options'] = []; + + $config['payum.api'] = function (ArrayObject $config) { + $config->validateNotEmpty($config['payum.required_options']); + + return new Api((array) $config, $config['payum.http_client']); + }; + } + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e018773 --- /dev/null +++ b/composer.json @@ -0,0 +1,37 @@ +{ + "name": "payum/skeleton", + "type": "library", + "description": "The Payum extension. Rapid extensino development", + "keywords": ["payment"], + "homepage": "http://payum.org", + "license": "MIT", + "authors": [ + { + "name": "Kotlyar Maksim", + "email": "kotlyar.maksim@gmail.com" + }, + { + "name": "Payum project", + "homepage": "http://payum.org/" + }, + { + "name": "Community contributions", + "homepage": "https://github.com/Payum/AuthorizeNetAim/contributors" + } + ], + "require": { + "payum/core": "~1.0" + }, + "config": { + "bin-dir": "bin" + }, + "autoload": { + "psr-0": { "Payum\\Skeleton": "" } + }, + "target-dir": "Payum/Skeleton", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + } +}