|
1 |
| -## Omnipay for Laravel 5 |
| 1 | +## Omnipay for Laravel |
2 | 2 |
|
3 | 3 | This is a package to integrate [Omnipay](https://github.com/omnipay/omnipay) with Laravel.
|
4 | 4 | You can use it to easily manage your configuration, and use the Facade to provide shortcuts to your gateway.
|
5 | 5 |
|
6 | 6 | ## Installation
|
7 | 7 |
|
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): |
11 | 9 |
|
| 10 | +```php |
| 11 | +"barryvdh/laravel-omnipay": "0.3.*" |
| 12 | +``` |
| 13 | + |
12 | 14 | Pre Laravel 5.5: After updating composer, add the ServiceProvider to the providers array in config/app.php
|
13 | 15 |
|
14 |
| - 'Barryvdh\Omnipay\ServiceProvider', |
| 16 | +```php |
| 17 | +'Barryvdh\Omnipay\ServiceProvider', |
| 18 | +``` |
15 | 19 |
|
16 | 20 | You need to publish the config for this package. A sample configuration is provided. The defaults will be merged with gateway specific configuration.
|
17 | 21 |
|
18 |
| - $ php artisan vendor:publish --provider='Barryvdh\Omnipay\ServiceProvider' |
| 22 | +``` |
| 23 | +$ php artisan vendor:publish --provider='Barryvdh\Omnipay\ServiceProvider' |
| 24 | +``` |
19 | 25 |
|
20 | 26 | To use the Facade (`Omnipay::purchase()` instead of `App::make(`omnipay`)->purchase()`), add that to the facades array.
|
21 | 27 |
|
22 |
| - 'Omnipay' => 'Barryvdh\Omnipay\Facade', |
| 28 | +```php |
| 29 | +'Omnipay' => 'Barryvdh\Omnipay\Facade', |
| 30 | +``` |
23 | 31 |
|
24 | 32 | When calling the Omnipay facade/instance, it will create the default gateway, based on the configuration.
|
25 | 33 | You can change the default gateway by calling `Omnipay::setDefaultGateway('My\Gateway')`.
|
26 | 34 | You can get a different gateway by calling `Omnipay::gateway('My\Cass')`
|
27 | 35 |
|
28 | 36 | ## Examples
|
29 | 37 |
|
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 | +``` |
48 | 59 |
|
49 | 60 | Besides the gateway calls, there is also a shortcut for the creditcard:
|
50 | 61 |
|
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 | +``` |
0 commit comments