Repository: barryvdh/laravel-omnipay Branch: master Commit: c7282d335f8b Files: 8 Total size: 8.7 KB Directory structure: gitextract_np4t_39x/ ├── .gitignore ├── LICENSE ├── composer.json ├── config/ │ └── omnipay.php ├── readme.md └── src/ ├── Facade.php ├── GatewayManager.php └── ServiceProvider.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ /.idea /vendor composer.phar composer.lock .DS_Store ================================================ FILE: LICENSE ================================================ Copyright (C) 2014 Barry vd. Heuvel 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. ================================================ FILE: composer.json ================================================ { "name": "barryvdh/laravel-omnipay", "description": "Omnipay Service Provider for Laravel", "keywords": [ "laravel", "omnipay" ], "license": "MIT", "authors": [ { "name": "Barry vd. Heuvel", "email": "barryvdh@gmail.com" } ], "require": { "php": "^8.1", "illuminate/support": "^9|^10|^11|^12|^13", "league/omnipay": "~3.0" }, "autoload": { "psr-4": { "Barryvdh\\Omnipay\\": "src/" } }, "extra": { "branch-alias": { "dev-master": "0.3-dev" }, "laravel": { "providers": [ "Barryvdh\\Omnipay\\ServiceProvider" ], "aliases": { "Omnipay": "Barryvdh\\Omnipay\\Facade" } } }, "minimum-stability": "dev" } ================================================ FILE: config/omnipay.php ================================================ env('OMNIPAY_GATEWAY', 'PayPal_Express'), /* |-------------------------------------------------------------------------- | Default settings |-------------------------------------------------------------------------- | | Here you can specify default settings for gateways. | */ 'defaults' => [ 'testMode' => env('OMNIPAY_TESTMODE', false), ], /* |-------------------------------------------------------------------------- | Gateway specific settings |-------------------------------------------------------------------------- | | Here you can specify gateway specific settings. | */ 'gateways' => [ 'PayPal_Express' => [ 'username' => env('OMNIPAY_PAYPAL_USERNAME'), 'landingPage' => ['billing', 'login'], ], ], ]; ================================================ FILE: readme.md ================================================ ## Omnipay for Laravel This is a package to integrate [Omnipay](https://github.com/omnipay/omnipay) with Laravel. You can use it to easily manage your configuration, and use the Facade to provide shortcuts to your gateway. ## Installation Require this package with composer. ``` $ composer require barryvdh/laravel-omnipay ``` Pre Laravel 5.5: After updating composer, add the ServiceProvider to the providers array in config/app.php ```php 'Barryvdh\Omnipay\ServiceProvider', ``` You need to publish the config for this package. A sample configuration is provided. The defaults will be merged with gateway specific configuration. ``` $ php artisan vendor:publish --provider=Barryvdh\Omnipay\ServiceProvider ``` To use the Facade (`Omnipay::purchase()` instead of `App::make(`omnipay`)->purchase()`), add that to the facades array. ```php 'Omnipay' => 'Barryvdh\Omnipay\Facade', ``` When calling the Omnipay facade/instance, it will create the default gateway, based on the configuration. You can change the default gateway by calling `Omnipay::setDefaultGateway('My\Gateway')`. You can get a different gateway by calling `Omnipay::gateway('My\Cass')` ## Examples ```php $params = [ 'amount' => $order->amount, 'issuer' => $issuerId, 'description' => $order->description, 'returnUrl' => URL::action('PurchaseController@return', [$order->id]), ]; $response = Omnipay::purchase($params)->send(); if ($response->isSuccessful()) { // payment was successful: update database print_r($response); } elseif ($response->isRedirect()) { // redirect to offsite payment gateway return $response->getRedirectResponse(); } else { // payment failed: display message to customer echo $response->getMessage(); } ``` Besides the gateway calls, there is also a shortcut for the creditcard: ```php $formInputData = [ 'firstName' => 'Bobby', 'lastName' => 'Tables', 'number' => '4111111111111111', ]; $card = Omnipay::CreditCard($formInputData); ``` ================================================ FILE: src/Facade.php ================================================ app = $app; $this->factory = $factory; $this->defaults = $defaults; } /** * Get a gateway * * @param string The gateway to retrieve (null=default) * @return \Omnipay\Common\GatewayInterface */ public function gateway($class = null) { $class = $class ?: $this->getDefaultGateway(); if (!isset($this->gateways[$class])) { $gateway = $this->factory->create($class, null, $this->app['request']); $gateway->initialize($this->getConfig($class)); $this->gateways[$class] = $gateway; } return $this->gateways[$class]; } /** * Get the configuration, based on the config and the defaults. */ protected function getConfig($name) { return array_merge( $this->defaults, $this->app['config']->get('omnipay.gateways.'.$name, []) ); } /** * Get the default gateway name. * * @return string */ public function getDefaultGateway() { return $this->app['config']['omnipay.gateway']; } /** * Set the default gateway name. * * @param string $name * @return void */ public function setDefaultGateway($name) { $this->app['config']['omnipay.gateway'] = $name; } /** * Dynamically call the default driver instance. * * @param string $method * @param array $parameters * @return mixed */ public function __call($method, $parameters) { return call_user_func_array([$this->gateway(), $method], $parameters); } } ================================================ FILE: src/ServiceProvider.php ================================================ publishes([$configPath => config_path('omnipay.php')]); $this->app->singleton('omnipay', function ($app) { $defaults = $app['config']->get('omnipay.defaults', array()); return new GatewayManager($app, new GatewayFactory, $defaults); }); } /** * Get the services provided by the provider. * * @return array */ public function provides() { return array('omnipay'); } }