Skip to content

Commit 1dbb028

Browse files
committed
Initial Commit
0 parents  commit 1dbb028

File tree

10 files changed

+339
-0
lines changed

10 files changed

+339
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Omnipay for Laravel 4
2+
==============
3+
4+
Integrates the [Omnipay](https://github.com/adrianmacneil/omnipay) PHP library with Laravel 4 via a ServiceProvider to make Configuring multiple payment tunnels a breeze!
5+
6+
### Installation
7+
8+
Include the laravel-omnipay package as a dependency in your `composer.json`:
9+
10+
"ignited/laravel-omnipay": "dev-master"
11+
12+
**Note:** You don't need to include the `omnipay/omnipay` in your composer.json - it is a requirement of the `laravel-omnipay` package.
13+
14+
Run `composer install` to download the dependencies.
15+
16+
Add a ServiceProvider to your providers array in `app/config/app.php`:
17+
18+
'providers' => array(
19+
20+
'Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider',
21+
22+
)
23+
24+
Add the `Omnipay` facade to your facades array:
25+
26+
'Omnipay' => 'Ignited\LaravelOmnipay\Facades\OmnipayFacade',
27+
28+
Finally, publish the configuration files via `php artisan config:publish ignited/laravel-omnipay`.
29+
30+
### Configuration
31+
32+
Once you have published the configuration files, you can add your gateway options to the config file in `app/config/packages/ignited/laravel-omnipay/config.php`.
33+
34+
### Usage
35+
36+
$cardInput = array(
37+
'number' => '4444333322221111',
38+
'firstName' => 'MR B BOB BROWN',
39+
'expiryMonth' => '03',
40+
'expiryYear' => '16',
41+
'cvv' => '333',
42+
);
43+
44+
$card = Omnipay::creditCard($cardInput);
45+
$response = Omnipay::purchase([
46+
'amount'=>'100.00',
47+
'returnUrl' => 'http://bobjones.com/payment/return',
48+
'cancelUrl' => 'http://bobjones.com/payment/cancel',
49+
'card'=>$cardInput
50+
])->send();
51+
52+
dd($response->getMessage());
53+
54+
This will use the gateway specified in the config as `default`.
55+
56+
However, you can also specify a gateway to use.
57+
58+
Omnipay::setGateway('eway');
59+
60+
$response = Omnipay::purchase([
61+
'amount'=>'100.00',
62+
'card'=>$cardInput
63+
])->send();
64+
65+
dd($response->getMessage());
66+
67+
In addition you can take an instance of the gateway.
68+
69+
$gateway = Omnipay::gateway('eway');

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "ignited/laravel-omnipay",
3+
"description": "Integerates Omnipay with Laravel and provides an easy configuration.",
4+
"version": "1.0.0",
5+
"keywords": ["omnipay", "payments", "laravel", "laravel4"],
6+
"authors": [
7+
{
8+
"name": "Alex Whiteside",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.3.0",
14+
"illuminate/support": "4.0.x",
15+
"omnipay/omnipay": "1.*"
16+
},
17+
"autoload": {
18+
"psr-0": {
19+
"Ignited\\LaravelOmnipay": "src/"
20+
}
21+
},
22+
"minimum-stability": "dev"
23+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php namespace Ignited\LaravelOmnipay\Facades;
2+
3+
use Illuminate\Support\Facades\Facade;
4+
5+
class OmnipayFacade extends Facade {
6+
7+
protected static function getFacadeAccessor() { return 'omnipay'; }
8+
9+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php namespace Ignited\LaravelOmnipay;
2+
3+
use Closure;
4+
use Omnipay\Common\GatewayFactory;
5+
use Omnipay\Common\Helper;
6+
use Omnipay\Common\CreditCard;
7+
8+
class LaravelOmnipayManager {
9+
/**
10+
* The application instance.
11+
*
12+
* @var \Illuminate\Foundation\Application
13+
*/
14+
protected $app;
15+
16+
/**
17+
* Omnipay Factory Instance
18+
* @var \Omnipay\Common\GatewayFactory
19+
*/
20+
protected $factory;
21+
22+
/**
23+
* The current gateway to use
24+
* @var string
25+
*/
26+
protected $gateway;
27+
28+
/**
29+
* The array of resolved queue connections.
30+
*
31+
* @var array
32+
*/
33+
protected $gateways = array();
34+
35+
/**
36+
* Create a new omnipay manager instance.
37+
*
38+
* @param \Illuminate\Foundation\Application $app
39+
* @return void
40+
*/
41+
public function __construct($app, $factory)
42+
{
43+
$this->app = $app;
44+
$this->factory = $factory;
45+
}
46+
47+
/**
48+
* Get an instance of the specified gateway
49+
* @param index of config array to use
50+
* @return Omnipay\Common\AbstractGateway
51+
*/
52+
public function gateway($name = null)
53+
{
54+
$name = $name ?: $this->getGateway();
55+
56+
if ( ! isset($this->gateways[$name]))
57+
{
58+
$this->gateways[$name] = $this->resolve($name);
59+
}
60+
61+
return $this->gateways[$name];
62+
}
63+
64+
protected function resolve($name)
65+
{
66+
$config = $this->getConfig($name);
67+
68+
if(is_null($config))
69+
{
70+
throw new \UnexpectedValueException("Gateway [$name] is not defined.");
71+
}
72+
73+
$gateway = $this->factory->create($config['driver']);
74+
75+
$class = trim(Helper::getGatewayClassName($config['driver']), "\\");
76+
77+
$reflection = new \ReflectionClass($class);
78+
79+
foreach($config['options'] as $optionName=>$value)
80+
{
81+
$method = 'set' . ucfirst($optionName);
82+
83+
if ($reflection->hasMethod($method)) {
84+
$gateway->{$method}($value);
85+
}
86+
}
87+
88+
return $gateway;
89+
}
90+
91+
public function creditCard($cardInput)
92+
{
93+
return new CreditCard($cardInput);
94+
}
95+
96+
protected function getDefault()
97+
{
98+
return $this->app['config']['ignited/laravel-omnipay::default'];
99+
}
100+
101+
protected function getConfig($name)
102+
{
103+
return $this->app['config']["ignited/laravel-omnipay::gateways.{$name}"];
104+
}
105+
106+
public function getGateway()
107+
{
108+
if(!isset($this->gateway))
109+
{
110+
$this->gateway = $this->getDefault();
111+
}
112+
return $this->gateway;
113+
}
114+
115+
public function setGateway($name)
116+
{
117+
$this->gateway = $name;
118+
}
119+
120+
public function __call($method, $parameters)
121+
{
122+
$callable = array($this->gateway(), $method);
123+
124+
if(method_exists($this->gateway(), $method))
125+
{
126+
return call_user_func_array($callable, $parameters);
127+
}
128+
129+
throw new \BadMethodCallException("Method [$method] is not supported by the gateway [$this->gateway].");
130+
}
131+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php namespace Ignited\LaravelOmnipay;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
use Omnipay\Common\GatewayFactory;
5+
6+
class LaravelOmnipayServiceProvider extends ServiceProvider {
7+
8+
/**
9+
* Indicates if loading of the provider is deferred.
10+
*
11+
* @var bool
12+
*/
13+
protected $defer = false;
14+
15+
public function boot()
16+
{
17+
$this->package('ignited/laravel-omnipay', 'ignited/laravel-omnipay');
18+
}
19+
20+
/**
21+
* Register the service provider.
22+
*
23+
* @return void
24+
*/
25+
public function register()
26+
{
27+
$this->registerManager();
28+
}
29+
30+
/**
31+
* Register the Omnipay manager
32+
*/
33+
public function registerManager()
34+
{
35+
$this->app['omnipay'] = $this->app->share(function($app)
36+
{
37+
$factory = new GatewayFactory;
38+
$manager = new LaravelOmnipayManager($app, $factory);
39+
40+
return $manager;
41+
});
42+
}
43+
44+
/**
45+
* Get the services provided by the provider.
46+
*
47+
* @return array
48+
*/
49+
public function provides()
50+
{
51+
return array('omnipay');
52+
}
53+
54+
}

src/config/config.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
return array(
4+
5+
// The default gateway to use
6+
'default' => 'paypal',
7+
8+
// Add in each gateway here
9+
'gateways' => array(
10+
'paypal' => array(
11+
'driver' => 'Paypal_Express',
12+
'options' => array(
13+
'solutionType' => '',
14+
'landingPage' => '',
15+
'headerImageUrl' => ''
16+
)
17+
)
18+
)
19+
);

tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)