diff --git a/README.md b/README.md index d3a9c84..a563e0d 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,66 @@ -Omnipay for Laravel 5 & Lumen +Omnipay for Laravel & Lumen ============== [![Total Downloads](https://img.shields.io/packagist/dt/ignited/laravel-omnipay.svg)](https://packagist.org/packages/ignited/laravel-omnipay) [![Latest Version](http://img.shields.io/packagist/v/ignited/laravel-omnipay.svg)](https://github.com/ignited/laravel-omnipay/releases) -[![Dependency Status](https://www.versioneye.com/php/ignited:laravel-omnipay/badge.svg)](https://www.versioneye.com/php/ignited:laravel-omnipay) -Integrates the [Omnipay](https://github.com/adrianmacneil/omnipay) PHP library with Laravel 5 via a ServiceProvider to make Configuring multiple payment tunnels a breeze! +Integrates the [Omnipay](https://github.com/adrianmacneil/omnipay) PHP library with Laravel to make Configuring multiple payment tunnels a breeze! -### Laravel 4 Support - -For Laravel 4 see the [version 1.x](https://github.com/ignited/laravel-omnipay/tree/1.1.0) tree - -### Now using Omnipay 2.3 - -Version `2.0` and onwards has been updated to use Omnipay 2.3. - -### Composer Configuration +## Installation Include the laravel-omnipay package as a dependency in your `composer.json`: - "ignited/laravel-omnipay": "2.*" + composer require ignited/laravel-omnipay "3.*" -**Note:** You don't need to include the `omnipay/common` in your composer.json - it is a requirement of the `laravel-omnipay` package. +**Note:** You don't need to include the `omnipay/common` in your composer.json - it has already been included `laravel-omnipay`. -Omnipay recently went refactoring that made it so that each package is now a seperate repository. The `omnipay/common` package includes the core framework. You will then need to include each gateway as you require. For example: +### Install Required Providers - "omnipay/eway": "*" +Now just include each gateway as you require, to included PayPal for example: + + composer require omnipay/paypal "3.*" -Alternatively you can include every gateway by requring: +Alternatively you can include every gateway by the following: - "omnipay/omnipay": "*" + composer require omnipay/omnipay "3.*" **Note:** this requires a large amount of composer work as it needs to fetch each seperate repository. This is not recommended. -### Installation - -Run `composer install` to download the dependencies. - -#### Laravel 5 +## Configuration -Add a ServiceProvider to your providers array in `config/app.php`: +You can publish the configuration files using the `vendor:publish` command. -```php -'providers' => [ - - 'Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider', - -] ``` - -Add the `Omnipay` facade to your facades array: - -```php - 'Omnipay' => 'Ignited\LaravelOmnipay\Facades\OmnipayFacade', +php artisan vendor:publish --provider="Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider" --tag=config ``` -Finally, publish the configuration files via `php artisan vendor:publish`. - -#### Lumen - -For `Lumen` add the following in your bootstrap/app.php -```php -$app->register(Ignited\LaravelOmnipay\LumenOmnipayServiceProvider::class); -``` +Once you have published the configuration files, you can add your gateway options to the config file in `config/laravel-omnipay.php`. -Copy the laravel-omnipay.php file from the config directory to config/laravel-omnipay.php +#### PayPal Express Example +Here is an example of how to configure password, username and, signature with paypal express checkout driver -And also add the following to bootstrap/app.php ```php -$app->configure('laravel-omnipay'); +... +'gateways' => [ + 'paypal' => [ + 'driver' => 'PayPal_Express', + 'options' => [ + 'username' => 'coolusername', + 'password' => 'strongpassword', + 'signature' => '', + 'solutionType' => '', + 'landingPage' => '', + 'headerImageUrl' => '', + 'brandName' => 'Your app name', + 'testMode' => true + ] + ], +] +... ``` -### Configuration - -Once you have published the configuration files, you can add your gateway options to the config file in `config/laravel-omnipay.php`. -### Usage +## Usage ```php $cardInput = [ @@ -87,6 +72,7 @@ $cardInput = [ ]; $card = Omnipay::creditCard($cardInput); + $response = Omnipay::purchase([ 'amount' => '100.00', 'returnUrl' => 'http://bobjones.com/payment/return', @@ -102,7 +88,7 @@ This will use the gateway specified in the config as `default`. However, you can also specify a gateway to use. ```php -Omnipay::setGateway('eway'); +Omnipay::setGateway('paypal'); $response = Omnipay::purchase([ 'amount' => '100.00', @@ -112,8 +98,34 @@ $response = Omnipay::purchase([ dd($response->getMessage()); ``` -In addition you can take an instance of the gateway. +In addition you can make an instance of the gateway. + +```php +$gateway = Omnipay::gateway('paypal'); +``` + +## Installation on Other Frameworks +### Lumen + +For `Lumen` add the following in your bootstrap/app.php +```php +$app->register(Ignited\LaravelOmnipay\LumenOmnipayServiceProvider::class); +``` + +Copy the laravel-omnipay.php file from the config directory to config/laravel-omnipay.php +And also add the following to bootstrap/app.php ```php -$gateway = Omnipay::gateway('eway'); +$app->configure('laravel-omnipay'); ``` + +## Guzzle + +If you are using Guzzle 6 you need to require the following package. + + composer require php-http/guzzle6-adapter + +Guzzle 7 now implements a PSR http client compliant adapter. So there is no need to include this. + +## License +This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). diff --git a/composer.json b/composer.json index 89d45a7..1abfcbc 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "name": "ignited/laravel-omnipay", - "description": "Integerates Omnipay with Laravel and provides an easy configuration.", - "keywords": ["omnipay", "payments", "laravel", "laravel5"], + "description": "Integrates Omnipay with Laravel and provides an easy configuration.", + "keywords": ["omnipay", "payments", "laravel"], + "license": "MIT", "authors": [ { "name": "Alex Whiteside", @@ -9,9 +10,9 @@ } ], "require": { - "php": ">=5.4.0", - "illuminate/support": "~5", - "omnipay/common": "2.3.*" + "php": "^7.2.5|^8.0", + "illuminate/support": "~6|~7|~8|~9|~10|~11|~12", + "omnipay/common": "~3.0" }, "autoload": { "psr-0": { @@ -20,8 +21,16 @@ }, "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" + }, + "laravel": { + "providers": [ + "Ignited\\LaravelOmnipay\\LaravelOmnipayServiceProvider" + ], + "aliases": { + "Omnipay": "Ignited\\LaravelOmnipay\\Facades\\OmnipayFacade" + } } }, "minimum-stability": "dev" -} \ No newline at end of file +} diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..a1cf8f6 --- /dev/null +++ b/license.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Ignited Labs + +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. diff --git a/src/Ignited/LaravelOmnipay/BaseServiceProvider.php b/src/Ignited/LaravelOmnipay/BaseServiceProvider.php index cb1b1c8..407e054 100644 --- a/src/Ignited/LaravelOmnipay/BaseServiceProvider.php +++ b/src/Ignited/LaravelOmnipay/BaseServiceProvider.php @@ -27,8 +27,7 @@ public function register() */ public function registerManager() { - $this->app['omnipay'] = $this->app->share(function($app) - { + $this->app->singleton('omnipay', function ($app) { $factory = new GatewayFactory; $manager = new LaravelOmnipayManager($app, $factory); diff --git a/src/Ignited/LaravelOmnipay/LaravelOmnipayManager.php b/src/Ignited/LaravelOmnipay/LaravelOmnipayManager.php index 105ac91..1470b93 100644 --- a/src/Ignited/LaravelOmnipay/LaravelOmnipayManager.php +++ b/src/Ignited/LaravelOmnipay/LaravelOmnipayManager.php @@ -25,6 +25,12 @@ class LaravelOmnipayManager { */ protected $gateway; + /** + * The Guzzle client to use (null means use default) + * @var \Guzzle\Http\Client|null + */ + protected $httpClient; + /** * The array of resolved queue connections. * @@ -70,7 +76,7 @@ protected function resolve($name) throw new \UnexpectedValueException("Gateway [$name] is not defined."); } - $gateway = $this->factory->create($config['driver']); + $gateway = $this->factory->create($config['driver'], $this->getHttpClient()); $class = trim(Helper::getGatewayClassName($config['driver']), "\\"); @@ -117,6 +123,16 @@ public function setGateway($name) $this->gateway = $name; } + public function setHttpClient($httpClient) + { + $this->httpClient = $httpClient; + } + + public function getHttpClient() + { + return $this->httpClient; + } + public function __call($method, $parameters) { $callable = [$this->gateway(), $method]; @@ -128,4 +144,4 @@ public function __call($method, $parameters) throw new \BadMethodCallException("Method [$method] is not supported by the gateway [$this->gateway]."); } -} \ No newline at end of file +}