Skip to content

Commit a7e9d66

Browse files
committed
Bring up-to-date for Laravel 5.7
New root namespace and provider name to prevent classes if moving from a version from upstream.
1 parent f87bcf9 commit a7e9d66

8 files changed

+117
-68
lines changed

Diff for: README.md

+46-44
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,76 @@ Omnipay for Laravel 5 & Lumen
77

88
Integrates the [Omnipay](https://github.com/adrianmacneil/omnipay) PHP library with Laravel 5.6 via a ServiceProvider to make Configuring multiple payment tunnels a breeze!
99

10-
### Laravel 4 Support
11-
12-
For Laravel 4 see the [version 1.x](https://github.com/ignited/laravel-omnipay/tree/1.1.0) tree
13-
1410
### Now using Omnipay 3.0
1511

16-
Version `2.0` and onwards has been updated to use Omnipay 3.0.
17-
18-
Version `2.2` and onwards is using Omnipay 2.5
19-
20-
Version `2.3` and onwards supports Laravel 5.4
12+
* Version `2.0` and onwards has been updated to use Omnipay 3.0.
13+
* Version `2.2` and onwards is using Omnipay 2.5
14+
* Version `2.3` and onwards supports Laravel 5.4
2115

2216
### Composer Configuration
2317

2418
Include the laravel-omnipay package as a dependency in your `composer.json`:
2519

26-
"laravel-omnipay/laravel-omnipay": "3.*"
27-
20+
"academe/laravel-omnipay": "3.*"
21+
2822
**Note:** You don't need to include the `omnipay/common` in your composer.json - it is a requirement of the `laravel-omnipay` package.
2923

30-
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:
24+
Each gateway driver is a seperate package.
25+
The `omnipay/common` package includes the core framework.
26+
You will then need to include each gateway as you require.
27+
Example:
28+
29+
"omnipay/eway": "3.*"
3130

32-
"omnipay/eway": "*"
33-
3431
Alternatively you can include every gateway by requring:
3532

36-
"omnipay/omnipay": "*"
33+
"omnipay/omnipay": "3.*"
3734

38-
**Note:** this requires a large amount of composer work as it needs to fetch each seperate repository. This is not recommended.
35+
**Note:** This requires a large amount of composer work as it needs to fetch each seperate repository.
36+
This is not recommended.
3937

4038
### Installation
4139

4240
Run `composer install` to download the dependencies.
4341

4442
#### Laravel 5
4543

44+
**Note:** For Laravel 5.6, the following steps are automated through the discovery process,
45+
so you will not need to add the provider and facade manually.
46+
4647
Add a ServiceProvider to your providers array in `config/app.php`:
4748

4849
```php
4950
'providers' => [
5051

51-
'Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider',
52+
Academe\LaravelOmnipay\LaravelOmnipayServiceProvider::class,
5253

5354
]
5455
```
5556

5657
Add the `Omnipay` facade to your facades array:
5758

5859
```php
59-
'Omnipay' => 'Ignited\LaravelOmnipay\Facades\OmnipayFacade',
60+
'Omnipay' => Academe\LaravelOmnipay\Facades\OmnipayFacade::class,
6061
```
6162

6263
Finally, publish the configuration files:
6364

6465
```
65-
php artisan vendor:publish --provider="Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider" --tag=config
66+
php artisan vendor:publish --provider="Academe\LaravelOmnipay\LaravelOmnipayServiceProvider" --tag=config
6667
```
6768

6869
#### Lumen
6970

7071
For `Lumen` add the following in your bootstrap/app.php
7172
```php
72-
$app->register(Ignited\LaravelOmnipay\LumenOmnipayServiceProvider::class);
73+
$app->register(Academe\LaravelOmnipay\LumenOmnipayServiceProvider::class);
7374
```
7475

75-
Copy the laravel-omnipay.php file from the config directory to config/laravel-omnipay.php
76+
Copy the `laravel-omnipay.php` file from the config directory to `config/laravel-omnipay.php`
77+
78+
Also add the following to `bootstrap/app.php`:
7679

77-
And also add the following to bootstrap/app.php
7880
```php
7981
$app->configure('laravel-omnipay');
8082
```
@@ -84,6 +86,7 @@ $app->configure('laravel-omnipay');
8486
Once you have published the configuration files, you can add your gateway options to the config file in `config/laravel-omnipay.php`.
8587

8688
#### PayPal Express Example
89+
8790
Here is an example of how to configure password, username and, signature with paypal express checkout driver
8891

8992
```php
@@ -92,58 +95,57 @@ Here is an example of how to configure password, username and, signature with pa
9295
'paypal' => [
9396
'driver' => 'PayPal_Express',
9497
'options' => [
95-
'username' => env( 'OMNIPAY_PAYPAL_EXPRESS_USERNAME', '' ),
96-
'password' => env( 'OMNIPAY_PAYPAL_EXPRESS_PASSWORD', '' ),
97-
'signature' => env( 'OMNIPAY_PAYPAL_EXPRESS_SIGNATURE', '' ),
98-
'solutionType' => env( 'OMNIPAY_PAYPAL_EXPRESS_SOLUTION_TYPE', '' ),
99-
'landingPage' => env( 'OMNIPAY_PAYPAL_EXPRESS_LANDING_PAGE', '' ),
100-
'headerImageUrl' => env( 'OMNIPAY_PAYPAL_EXPRESS_HEADER_IMAGE_URL', '' ),
101-
'brandName' => 'Your app name',
102-
'testMode' => env( 'OMNIPAY_PAYPAL_TEST_MODE', true )
98+
'username' => env('OMNIPAY_PAYPAL_EXPRESS_USERNAME'),
99+
'password' => env('OMNIPAY_PAYPAL_EXPRESS_PASSWORD'),
100+
'signature' => env('OMNIPAY_PAYPAL_EXPRESS_SIGNATURE'),
101+
'solutionType' => env('OMNIPAY_PAYPAL_EXPRESS_SOLUTION_TYPE'),
102+
'landingPage' => env('OMNIPAY_PAYPAL_EXPRESS_LANDING_PAGE'),
103+
'headerImageUrl' => env('OMNIPAY_PAYPAL_EXPRESS_HEADER_IMAGE_URL'),
104+
'brandName' => 'Your app name',
105+
'testMode' => env('OMNIPAY_PAYPAL_TEST_MODE', true)
103106
]
104107
],
105108
]
106109
...
107110
```
108111

109-
110112
### Usage
111113

112114
```php
113115
$cardInput = [
114-
'number' => '4444333322221111',
115-
'firstName' => 'MR. WALTER WHITE',
116-
'expiryMonth' => '03',
117-
'expiryYear' => '16',
118-
'cvv' => '333',
116+
'number' => '4444333322221111',
117+
'firstName' => 'MR. WALTER WHITE',
118+
'expiryMonth' => '03',
119+
'expiryYear' => '16',
120+
'cvv' => '333',
119121
];
120122

121123
$card = Omnipay::creditCard($cardInput);
122124
$response = Omnipay::purchase([
123-
'amount' => '100.00',
124-
'returnUrl' => 'http://bobjones.com/payment/return',
125-
'cancelUrl' => 'http://bobjones.com/payment/cancel',
126-
'card' => $cardInput
125+
'amount' => '100.00',
126+
'returnUrl' => 'http://bobjones.com/payment/return',
127+
'cancelUrl' => 'http://bobjones.com/payment/cancel',
128+
'card' => $cardInput
127129
])->send();
128130

129131
dd($response->getMessage());
130132
```
131133

132134
This will use the gateway specified in the config as `default`.
133135

134-
However, you can also specify a gateway to use.
136+
You can explicitly specify a gateway to use:
135137

136138
```php
137139
Omnipay::setGateway('eway');
138140

139141
$response = Omnipay::purchase([
140-
'amount' => '100.00',
141-
'card' => $cardInput
142+
'amount' => '100.00',
143+
'card' => $cardInput
142144
])->send();
143145

144146
dd($response->getMessage());
145147
```
146-
148+
147149
In addition you can take an instance of the gateway.
148150

149151
```php

Diff for: composer.json

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
{
2-
"name": "laravel-omnipay/laravel-omnipay",
2+
"name": "academe/laravel-omnipay",
33
"description": "Integerates Omnipay with Laravel and provides an easy configuration.",
4-
"keywords": ["omnipay", "payments", "laravel", "laravel5"],
4+
"keywords": ["omnipay", "omnipay3", "payments", "laravel", "laravel5"],
55
"authors": [
66
{
77
"name": "Alex Whiteside",
88
"email": "[email protected]"
9+
},
10+
{
11+
"name": "Jason Judge",
12+
"email": "[email protected]"
913
}
1014
],
1115
"require": {
12-
"php": ">=5.4.0",
13-
"php-http/guzzle6-adapter": "^1.1",
16+
"php": ">=7.0.0",
17+
"laravel/framework": "~5",
1418
"illuminate/support": "~5",
1519
"omnipay/common": "~3.0"
1620
},
1721
"autoload": {
18-
"psr-0": {
19-
"Omnipay\\LaravelOmnipay": "src/"
22+
"psr-4": {
23+
"Academe\\LaravelOmnipay\\": "src/"
2024
}
2125
},
2226
"extra": {
2327
"branch-alias": {
2428
"dev-master": "3.1-dev"
29+
},
30+
"laravel": {
31+
"providers": [
32+
"Academe\\LaravelOmnipay\\LaravelOmnipayServiceProvider"
33+
],
34+
"aliases": {
35+
"Omnipay": "Academe\\LaravelOmnipay\\Facades\\OmnipayFacade"
36+
}
2537
}
2638
},
2739
"minimum-stability": "dev"
File renamed without changes.

Diff for: src/BaseServiceProvider.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
<?php namespace Omnipay\LaravelOmnipay;
1+
<?php
2+
3+
namespace Academe\LaravelOmnipay;
24

35
use Illuminate\Support\ServiceProvider;
46
use Omnipay\Common\GatewayFactory;
57

68
abstract class BaseServiceProvider extends ServiceProvider
79
{
10+
const PROVIDES = 'laravel-omnipay';
811

912
/**
1013
* Indicates if loading of the provider is deferred.
@@ -28,7 +31,7 @@ public function register()
2831
*/
2932
public function registerManager()
3033
{
31-
$this->app->singleton('omnipay', function ($app) {
34+
$this->app->singleton(static::PROVIDES, function ($app) {
3235
$factory = new GatewayFactory;
3336
$manager = new LaravelOmnipayManager($app, $factory);
3437

@@ -43,6 +46,6 @@ public function registerManager()
4346
*/
4447
public function provides()
4548
{
46-
return ['omnipay'];
49+
return [static::PROVIDES];
4750
}
4851
}

Diff for: src/Facades/OmnipayFacade.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
<?php namespace Omnipay\LaravelOmnipay\Facades;
1+
<?php
2+
3+
namespace Academe\LaravelOmnipay\Facades;
24

35
use Illuminate\Support\Facades\Facade;
6+
use Academe\LaravelOmnipay\BaseServiceProvider;
47

58
class OmnipayFacade extends Facade
69
{
710
protected static function getFacadeAccessor()
811
{
9-
return 'omnipay';
12+
return BaseServiceProvider::PROVIDES;
1013
}
1114
}

Diff for: src/LaravelOmnipayManager.php

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
<?php namespace Omnipay\LaravelOmnipay;
1+
<?php
2+
3+
namespace Academe\LaravelOmnipay;
24

35
use Closure;
46
use Omnipay\Common\GatewayFactory;
57
use Omnipay\Common\Helper;
68
use Omnipay\Common\CreditCard;
79

10+
use UnexpectedValueException;
11+
use BadMethodCallException;
12+
use ReflectionClass;
13+
814
class LaravelOmnipayManager
915
{
1016
/**
@@ -72,16 +78,22 @@ protected function resolve($name)
7278
$config = $this->getConfig($name);
7379

7480
if (is_null($config)) {
75-
throw new \UnexpectedValueException("Gateway [$name] is not defined.");
81+
throw new UnexpectedValueException(sprintf(
82+
'Gateway [%s] is not defined.',
83+
$name
84+
));
7685
}
7786

78-
$gateway = $this->factory->create($config['driver'], $this->getHttpClient());
87+
$gateway = $this->factory->create(
88+
$config['driver'],
89+
$this->getHttpClient()
90+
);
7991

8092
$class = trim(Helper::getGatewayClassName($config['driver']), "\\");
8193

82-
$reflection = new \ReflectionClass($class);
94+
$reflection = new ReflectionClass($class);
8395

84-
foreach ($config['options'] as $optionName=>$value) {
96+
foreach ($config['options'] as $optionName => $value) {
8597
$method = 'set' . ucfirst($optionName);
8698

8799
if ($reflection->hasMethod($method)) {
@@ -99,19 +111,20 @@ public function creditCard($cardInput)
99111

100112
protected function getDefault()
101113
{
102-
return $this->app['config']['laravel-omnipay.default'];
114+
return $this->app['config']['laravel-omnipay.default'] ?? null;
103115
}
104116

105117
protected function getConfig($name)
106118
{
107-
return $this->app['config']["laravel-omnipay.gateways.{$name}"];
119+
return $this->app['config']["laravel-omnipay.gateways.{$name}"] ?? null;
108120
}
109121

110122
public function getGateway()
111123
{
112124
if (!isset($this->gateway)) {
113125
$this->gateway = $this->getDefault();
114126
}
127+
115128
return $this->gateway;
116129
}
117130

@@ -138,6 +151,10 @@ public function __call($method, $parameters)
138151
return call_user_func_array($callable, $parameters);
139152
}
140153

141-
throw new \BadMethodCallException("Method [$method] is not supported by the gateway [$this->gateway].");
154+
throw new BadMethodCallException(sprintf(
155+
'Method [%s] is not supported by the gateway [%s].',
156+
$method,
157+
$this->gateway
158+
));
142159
}
143160
}

Diff for: src/LaravelOmnipayServiceProvider.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
<?php namespace Omnipay\LaravelOmnipay;
1+
<?php
2+
3+
namespace Academe\LaravelOmnipay;
24

35
class LaravelOmnipayServiceProvider extends BaseServiceProvider
46
{
57
public function boot()
68
{
79
// Publish config
8-
$configPath = __DIR__ . '/config/config.php';
9-
$this->publishes([$configPath => config_path('laravel-omnipay.php')], 'config');
10+
11+
$configPath = __DIR__ . '/../config/laravel-omnipay.php';
12+
13+
$this->publishes(
14+
[$configPath => config_path('laravel-omnipay.php')],
15+
'config'
16+
);
1017
}
1118
}

0 commit comments

Comments
 (0)