Skip to content

Commit e6bfc4c

Browse files
authored
Merge pull request #29 from RSpeekenbrink/code-cleanup
Code cleanup and PSR-2 compatibility
2 parents a001f83 + 86a53ec commit e6bfc4c

File tree

6 files changed

+96
-58
lines changed

6 files changed

+96
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.idea
12
/vendor
23
composer.phar
34
composer.lock

config/omnipay.php

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
<?php
22

3-
return array(
3+
return [
44

5-
/** The default gateway name */
6-
'gateway' => 'PayPal_Express',
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Default Gateway
8+
|--------------------------------------------------------------------------
9+
|
10+
| Here you can specify the gateway that the facade should use by default.
11+
|
12+
*/
13+
'gateway' => env('OMNIPAY_GATEWAY', 'PayPal_Express'),
714

8-
/** The default settings, applied to all gateways */
9-
'defaults' => array(
10-
'testMode' => false,
11-
),
15+
/*
16+
|--------------------------------------------------------------------------
17+
| Default settings
18+
|--------------------------------------------------------------------------
19+
|
20+
| Here you can specify default settings for gateways.
21+
|
22+
*/
23+
'defaults' => [
24+
'testMode' => env('OMNIPAY_TESTMODE', false),
25+
],
1226

13-
/** Gateway specific parameters */
14-
'gateways' => array(
15-
'PayPal_Express' => array(
16-
'username' => '',
17-
'landingPage' => array('billing', 'login'),
18-
),
19-
),
27+
/*
28+
|--------------------------------------------------------------------------
29+
| Gateway specific settings
30+
|--------------------------------------------------------------------------
31+
|
32+
| Here you can specify gateway specific settings.
33+
|
34+
*/
35+
'gateways' => [
36+
'PayPal_Express' => [
37+
'username' => env('OMNIPAY_PAYPAL_USERNAME'),
38+
'landingPage' => ['billing', 'login'],
39+
],
40+
],
2041

21-
);
42+
];

readme.md

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,70 @@
1-
## Omnipay for Laravel 5
1+
## Omnipay for Laravel
22

33
This is a package to integrate [Omnipay](https://github.com/omnipay/omnipay) with Laravel.
44
You can use it to easily manage your configuration, and use the Facade to provide shortcuts to your gateway.
55

66
## Installation
77

8-
Require this package in your composer.json and run composer update (or run `composer require barryvdh/laravel-omnipay:0.3.x` directly):
9-
10-
"barryvdh/laravel-omnipay": "0.3.*@dev"
8+
Require this package in your composer.json and run composer update (or run `composer require barryvdh/laravel-omnipay` directly):
119

10+
```php
11+
"barryvdh/laravel-omnipay": "0.3.*"
12+
```
13+
1214
Pre Laravel 5.5: After updating composer, add the ServiceProvider to the providers array in config/app.php
1315

14-
'Barryvdh\Omnipay\ServiceProvider',
16+
```php
17+
'Barryvdh\Omnipay\ServiceProvider',
18+
```
1519

1620
You need to publish the config for this package. A sample configuration is provided. The defaults will be merged with gateway specific configuration.
1721

18-
$ php artisan vendor:publish --provider='Barryvdh\Omnipay\ServiceProvider'
22+
```
23+
$ php artisan vendor:publish --provider='Barryvdh\Omnipay\ServiceProvider'
24+
```
1925

2026
To use the Facade (`Omnipay::purchase()` instead of `App::make(`omnipay`)->purchase()`), add that to the facades array.
2127

22-
'Omnipay' => 'Barryvdh\Omnipay\Facade',
28+
```php
29+
'Omnipay' => 'Barryvdh\Omnipay\Facade',
30+
```
2331

2432
When calling the Omnipay facade/instance, it will create the default gateway, based on the configuration.
2533
You can change the default gateway by calling `Omnipay::setDefaultGateway('My\Gateway')`.
2634
You can get a different gateway by calling `Omnipay::gateway('My\Cass')`
2735

2836
## Examples
2937

30-
$params = [
31-
'amount' => $order->amount,
32-
'issuer' => $issuerId,
33-
'description' => $order->description,
34-
'returnUrl' => URL::action('PurchaseController@return', [$order->id]),
35-
];
36-
$response = Omnipay::purchase($params)->send();
37-
38-
if ($response->isSuccessful()) {
39-
// payment was successful: update database
40-
print_r($response);
41-
} elseif ($response->isRedirect()) {
42-
// redirect to offsite payment gateway
43-
return $response->getRedirectResponse();
44-
} else {
45-
// payment failed: display message to customer
46-
echo $response->getMessage();
47-
}
38+
```php
39+
$params = [
40+
'amount' => $order->amount,
41+
'issuer' => $issuerId,
42+
'description' => $order->description,
43+
'returnUrl' => URL::action('PurchaseController@return', [$order->id]),
44+
];
45+
46+
$response = Omnipay::purchase($params)->send();
47+
48+
if ($response->isSuccessful()) {
49+
// payment was successful: update database
50+
print_r($response);
51+
} elseif ($response->isRedirect()) {
52+
// redirect to offsite payment gateway
53+
return $response->getRedirectResponse();
54+
} else {
55+
// payment failed: display message to customer
56+
echo $response->getMessage();
57+
}
58+
```
4859

4960
Besides the gateway calls, there is also a shortcut for the creditcard:
5061

51-
$formInputData = array(
52-
'firstName' => 'Bobby',
53-
'lastName' => 'Tables',
54-
'number' => '4111111111111111',
55-
);
56-
$card = Omnipay::CreditCard($formInputData);
62+
```php
63+
$formInputData = [
64+
'firstName' => 'Bobby',
65+
'lastName' => 'Tables',
66+
'number' => '4111111111111111',
67+
];
68+
69+
$card = Omnipay::CreditCard($formInputData);
70+
```

src/Facade.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
use Omnipay\Common\CreditCard;
44

5-
class Facade extends \Illuminate\Support\Facades\Facade {
6-
5+
class Facade extends \Illuminate\Support\Facades\Facade
6+
{
77
/**
88
* @param array $parameters
99
* @return CreditCard
@@ -16,6 +16,8 @@ public static function creditCard($parameters = null)
1616
/**
1717
* {@inheritDoc}
1818
*/
19-
protected static function getFacadeAccessor() { return 'omnipay'; }
20-
19+
protected static function getFacadeAccessor()
20+
{
21+
return 'omnipay';
22+
}
2123
}

src/GatewayManager.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
use Omnipay\Common\GatewayFactory;
44

5-
class GatewayManager{
6-
5+
class GatewayManager
6+
{
77
/**
88
* The application instance.
99
*
@@ -45,7 +45,7 @@ public function gateway($class = null)
4545
{
4646
$class = $class ?: $this->getDefaultGateway();
4747

48-
if(!isset($this->gateways[$class])){
48+
if (!isset($this->gateways[$class])) {
4949
$gateway = $this->factory->create($class, null, $this->app['request']);
5050
$gateway->initialize($this->getConfig($class));
5151
$this->gateways[$class] = $gateway;
@@ -61,7 +61,7 @@ protected function getConfig($name)
6161
{
6262
return array_merge(
6363
$this->defaults,
64-
$this->app['config']->get('omnipay.gateways.'.$name, array())
64+
$this->app['config']->get('omnipay.gateways.'.$name, [])
6565
);
6666
}
6767

@@ -95,7 +95,6 @@ public function setDefaultGateway($name)
9595
*/
9696
public function __call($method, $parameters)
9797
{
98-
return call_user_func_array(array($this->gateway(), $method), $parameters);
98+
return call_user_func_array([$this->gateway(), $method], $parameters);
9999
}
100-
101100
}

src/ServiceProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
use Omnipay\Common\GatewayFactory;
44

5-
class ServiceProvider extends \Illuminate\Support\ServiceProvider {
5+
class ServiceProvider extends \Illuminate\Support\ServiceProvider
6+
{
67

78
/**
89
* Indicates if loading of the provider is deferred.
@@ -21,7 +22,7 @@ public function register()
2122
$configPath = __DIR__ . '/../config/omnipay.php';
2223
$this->publishes([$configPath => config_path('omnipay.php')]);
2324

24-
$this->app->singleton('omnipay',function ($app){
25+
$this->app->singleton('omnipay', function ($app) {
2526
$defaults = $app['config']->get('omnipay.defaults', array());
2627
return new GatewayManager($app, new GatewayFactory, $defaults);
2728
});

0 commit comments

Comments
 (0)