├── tests └── .gitkeep ├── .gitignore ├── .travis.yml ├── src ├── Ignited │ └── LaravelOmnipay │ │ ├── Facades │ │ └── OmnipayFacade.php │ │ ├── LumenOmnipayServiceProvider.php │ │ ├── LaravelOmnipayServiceProvider.php │ │ ├── BaseServiceProvider.php │ │ └── LaravelOmnipayManager.php └── config │ └── config.php ├── phpunit.xml ├── composer.json ├── license.txt └── README.md /tests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | 8 | before_script: 9 | - curl -s http://getcomposer.org/installer | php 10 | - php composer.phar install --dev 11 | 12 | script: phpunit -------------------------------------------------------------------------------- /src/Ignited/LaravelOmnipay/Facades/OmnipayFacade.php: -------------------------------------------------------------------------------- 1 | mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'laravel-omnipay'); 8 | } 9 | 10 | } -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | 'paypal', 7 | 8 | // Add in each gateway here 9 | 'gateways' => [ 10 | 'paypal' => [ 11 | 'driver' => 'PayPal_Express', 12 | 'options' => [ 13 | 'solutionType' => '', 14 | 'landingPage' => '', 15 | 'headerImageUrl' => '' 16 | ] 17 | ] 18 | ] 19 | 20 | ]; -------------------------------------------------------------------------------- /src/Ignited/LaravelOmnipay/LaravelOmnipayServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([$configPath => config_path('laravel-omnipay.php')], 'config'); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ignited/laravel-omnipay", 3 | "description": "Integrates Omnipay with Laravel and provides an easy configuration.", 4 | "keywords": ["omnipay", "payments", "laravel"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Alex Whiteside", 9 | "email": "alexwhiteside@ignitedlabs.com.au" 10 | } 11 | ], 12 | "require": { 13 | "php": "^7.2.5|^8.0", 14 | "illuminate/support": "~6|~7|~8|~9|~10|~11|~12", 15 | "omnipay/common": "~3.0" 16 | }, 17 | "autoload": { 18 | "psr-0": { 19 | "Ignited\\LaravelOmnipay": "src/" 20 | } 21 | }, 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.0-dev" 25 | }, 26 | "laravel": { 27 | "providers": [ 28 | "Ignited\\LaravelOmnipay\\LaravelOmnipayServiceProvider" 29 | ], 30 | "aliases": { 31 | "Omnipay": "Ignited\\LaravelOmnipay\\Facades\\OmnipayFacade" 32 | } 33 | } 34 | }, 35 | "minimum-stability": "dev" 36 | } 37 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Ignited Labs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Ignited/LaravelOmnipay/BaseServiceProvider.php: -------------------------------------------------------------------------------- 1 | registerManager(); 23 | } 24 | 25 | /** 26 | * Register the Omnipay manager 27 | */ 28 | public function registerManager() 29 | { 30 | $this->app->singleton('omnipay', function ($app) { 31 | $factory = new GatewayFactory; 32 | $manager = new LaravelOmnipayManager($app, $factory); 33 | 34 | return $manager; 35 | }); 36 | } 37 | 38 | /** 39 | * Get the services provided by the provider. 40 | * 41 | * @return array 42 | */ 43 | public function provides() 44 | { 45 | return ['omnipay']; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/Ignited/LaravelOmnipay/LaravelOmnipayManager.php: -------------------------------------------------------------------------------- 1 | app = $app; 50 | $this->factory = $factory; 51 | } 52 | 53 | /** 54 | * Get an instance of the specified gateway 55 | * @param index of config array to use 56 | * @return Omnipay\Common\AbstractGateway 57 | */ 58 | public function gateway($name = null) 59 | { 60 | $name = $name ?: $this->getGateway(); 61 | 62 | if ( ! isset($this->gateways[$name])) 63 | { 64 | $this->gateways[$name] = $this->resolve($name); 65 | } 66 | 67 | return $this->gateways[$name]; 68 | } 69 | 70 | protected function resolve($name) 71 | { 72 | $config = $this->getConfig($name); 73 | 74 | if(is_null($config)) 75 | { 76 | throw new \UnexpectedValueException("Gateway [$name] is not defined."); 77 | } 78 | 79 | $gateway = $this->factory->create($config['driver'], $this->getHttpClient()); 80 | 81 | $class = trim(Helper::getGatewayClassName($config['driver']), "\\"); 82 | 83 | $reflection = new \ReflectionClass($class); 84 | 85 | foreach($config['options'] as $optionName=>$value) 86 | { 87 | $method = 'set' . ucfirst($optionName); 88 | 89 | if ($reflection->hasMethod($method)) { 90 | $gateway->{$method}($value); 91 | } 92 | } 93 | 94 | return $gateway; 95 | } 96 | 97 | public function creditCard($cardInput) 98 | { 99 | return new CreditCard($cardInput); 100 | } 101 | 102 | protected function getDefault() 103 | { 104 | return $this->app['config']['laravel-omnipay.default']; 105 | } 106 | 107 | protected function getConfig($name) 108 | { 109 | return $this->app['config']["laravel-omnipay.gateways.{$name}"]; 110 | } 111 | 112 | public function getGateway() 113 | { 114 | if(!isset($this->gateway)) 115 | { 116 | $this->gateway = $this->getDefault(); 117 | } 118 | return $this->gateway; 119 | } 120 | 121 | public function setGateway($name) 122 | { 123 | $this->gateway = $name; 124 | } 125 | 126 | public function setHttpClient($httpClient) 127 | { 128 | $this->httpClient = $httpClient; 129 | } 130 | 131 | public function getHttpClient() 132 | { 133 | return $this->httpClient; 134 | } 135 | 136 | public function __call($method, $parameters) 137 | { 138 | $callable = [$this->gateway(), $method]; 139 | 140 | if(method_exists($this->gateway(), $method)) 141 | { 142 | return call_user_func_array($callable, $parameters); 143 | } 144 | 145 | throw new \BadMethodCallException("Method [$method] is not supported by the gateway [$this->gateway]."); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Omnipay for Laravel & Lumen 2 | ============== 3 | 4 | [![Total Downloads](https://img.shields.io/packagist/dt/ignited/laravel-omnipay.svg)](https://packagist.org/packages/ignited/laravel-omnipay) 5 | [![Latest Version](http://img.shields.io/packagist/v/ignited/laravel-omnipay.svg)](https://github.com/ignited/laravel-omnipay/releases) 6 | 7 | Integrates the [Omnipay](https://github.com/adrianmacneil/omnipay) PHP library with Laravel to make Configuring multiple payment tunnels a breeze! 8 | 9 | ## Installation 10 | 11 | Include the laravel-omnipay package as a dependency in your `composer.json`: 12 | 13 | composer require ignited/laravel-omnipay "3.*" 14 | 15 | **Note:** You don't need to include the `omnipay/common` in your composer.json - it has already been included `laravel-omnipay`. 16 | 17 | ### Install Required Providers 18 | 19 | Now just include each gateway as you require, to included PayPal for example: 20 | 21 | composer require omnipay/paypal "3.*" 22 | 23 | Alternatively you can include every gateway by the following: 24 | 25 | composer require omnipay/omnipay "3.*" 26 | 27 | **Note:** this requires a large amount of composer work as it needs to fetch each seperate repository. This is not recommended. 28 | 29 | ## Configuration 30 | 31 | You can publish the configuration files using the `vendor:publish` command. 32 | 33 | ``` 34 | php artisan vendor:publish --provider="Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider" --tag=config 35 | ``` 36 | 37 | Once you have published the configuration files, you can add your gateway options to the config file in `config/laravel-omnipay.php`. 38 | 39 | #### PayPal Express Example 40 | Here is an example of how to configure password, username and, signature with paypal express checkout driver 41 | 42 | ```php 43 | ... 44 | 'gateways' => [ 45 | 'paypal' => [ 46 | 'driver' => 'PayPal_Express', 47 | 'options' => [ 48 | 'username' => 'coolusername', 49 | 'password' => 'strongpassword', 50 | 'signature' => '', 51 | 'solutionType' => '', 52 | 'landingPage' => '', 53 | 'headerImageUrl' => '', 54 | 'brandName' => 'Your app name', 55 | 'testMode' => true 56 | ] 57 | ], 58 | ] 59 | ... 60 | ``` 61 | 62 | 63 | ## Usage 64 | 65 | ```php 66 | $cardInput = [ 67 | 'number' => '4444333322221111', 68 | 'firstName' => 'MR. WALTER WHITE', 69 | 'expiryMonth' => '03', 70 | 'expiryYear' => '16', 71 | 'cvv' => '333', 72 | ]; 73 | 74 | $card = Omnipay::creditCard($cardInput); 75 | 76 | $response = Omnipay::purchase([ 77 | 'amount' => '100.00', 78 | 'returnUrl' => 'http://bobjones.com/payment/return', 79 | 'cancelUrl' => 'http://bobjones.com/payment/cancel', 80 | 'card' => $cardInput 81 | ])->send(); 82 | 83 | dd($response->getMessage()); 84 | ``` 85 | 86 | This will use the gateway specified in the config as `default`. 87 | 88 | However, you can also specify a gateway to use. 89 | 90 | ```php 91 | Omnipay::setGateway('paypal'); 92 | 93 | $response = Omnipay::purchase([ 94 | 'amount' => '100.00', 95 | 'card' => $cardInput 96 | ])->send(); 97 | 98 | dd($response->getMessage()); 99 | ``` 100 | 101 | In addition you can make an instance of the gateway. 102 | 103 | ```php 104 | $gateway = Omnipay::gateway('paypal'); 105 | ``` 106 | 107 | ## Installation on Other Frameworks 108 | ### Lumen 109 | 110 | For `Lumen` add the following in your bootstrap/app.php 111 | ```php 112 | $app->register(Ignited\LaravelOmnipay\LumenOmnipayServiceProvider::class); 113 | ``` 114 | 115 | Copy the laravel-omnipay.php file from the config directory to config/laravel-omnipay.php 116 | 117 | And also add the following to bootstrap/app.php 118 | ```php 119 | $app->configure('laravel-omnipay'); 120 | ``` 121 | 122 | ## Guzzle 123 | 124 | If you are using Guzzle 6 you need to require the following package. 125 | 126 | composer require php-http/guzzle6-adapter 127 | 128 | Guzzle 7 now implements a PSR http client compliant adapter. So there is no need to include this. 129 | 130 | ## License 131 | This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). 132 | --------------------------------------------------------------------------------