https://github.com/barryvdh/laravel-omnipay
Omnipay ServiceProvider for Laravel
https://github.com/barryvdh/laravel-omnipay
Last synced: about 2 months ago
JSON representation
Omnipay ServiceProvider for Laravel
- Host: GitHub
- URL: https://github.com/barryvdh/laravel-omnipay
- Owner: barryvdh
- License: mit
- Created: 2014-03-28T16:23:14.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2025-02-25T10:45:57.000Z (3 months ago)
- Last Synced: 2025-04-13T00:48:12.687Z (about 2 months ago)
- Language: PHP
- Size: 29.3 KB
- Stars: 170
- Watchers: 7
- Forks: 45
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## 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);
```