# OMNIPAY GATEWAY (for Laravel Shop Package)
, (*1)
Omnipay Gateway solution for Laravel Shop., (*2)
Enables multiple gateway payment, like PayPal, 2Checkout, Stripe and others.
See the full list at Omnipay's page., (*3)
Gateways
This package comes with:, (*4)
Contents
Installation
Add, (*5)
"amostajo/laravel-shop-gateway-omnipay": "1.0.*"
to your composer.json
. Then run composer install
or composer update
., (*6)
Then in your config/shop.php
add, (*7)
'omnipay' => Amostajo\LaravelShopGatewayOmnipay\GatewayOmnipay::class,
in the gateways
array., (*8)
Gateway Usage
The following example will give you an idea of how use and access omnipay:, (*9)
// (1) - Set gateway
Shop::setGateway('omnipay');
// (2) - Indicate service to use
Shop::gateway()->create('PayPal_Rest');
// (3) - Initialize your service (varies from service)
Shop::gateway()->omnipay->initialize([
'clientId' => '...',
'secret' => '...',
'testMode' => true,
]);
// (4) - Add credit card for validation (optional depending service)
Shop::gateway()->setCreditCard([
'number' => '4111111111111111',
'expiryMonth' => '1',
'expiryYear' => '2019',
'cvv' => '123',
'firstName' => 'John',
'lastName' => 'Doe',
'billingAddress1' => '666 grand canyon',
'billingCountry' => 'US',
'billingCity' => 'TX',
'billingPostcode' => '12345',
'billingState' => 'TX',
]);
// (5) - Call checkout
if (!Shop::checkout()) {
echo Shop::exception()->getMessage(); // echos: card validation error.
}
// (6) - Create order
$order = Shop::placeOrder();
// (7) - Review payment
if ($order->hasFailed) {
echo Shop::exception()->getMessage(); // echos: payment error.
}
The lines may vary depending on the service chosen., (*10)
NOTE: Checkout and placing order shouldn't vary from standard Laravel Shop flow., (*11)
Accessing Omnipay
You can always access the omnipay
object if you need to set or call any specific method required by a service:, (*12)
// (1) - Set gateway
Shop::setGateway('omnipay');
Shop::gateway()->create('Stripe');
// (2) - Setting method / calling specific method
Shop::gateway()->omnipay->setSpecific();
Adding Options
You can add more options, apart from amount
, currency
and card
, to the authorization and purchase methods:, (*13)
// (1) - Set gateway
Shop::setGateway('omnipay');
Shop::gateway()->create('Stripe');
// (2) - Adding an option
Shop::gateway()->addOption('token', $stripetoken);
// (3) - Any operation that follows
Shop::checkout();
Callbacks
Use the following example when callbacks are needed:, (*14)
// (1) - Set gateway
Shop::setGateway('omnipay');
Shop::gateway()->create('PayPal_Express');
// (2) - Authentication
Shop::gateway()->omnipay->setUsername('...');
Shop::gateway()->omnipay->setPassword('...');
// (2) - Call checkout / OPTIONAL
Shop::checkout();
// (3) - Create order
$order = Shop::placeOrder();
// (4) - Review order and redirect to payment
if ($order->isPending) {
// PayPal URL to redirect to proceed with payment
$approvalUrl = Shop::gateway()->getApprovalUrl();
// Redirect to url
return redirect($approvalUrl);
}
// (5) - Callback
// You don't have to do anything.
// Laravel Shop will handle the callback and redirect the customer to the configured route.
Tested Services
License
This package is free software distributed under the terms of the MIT license., (*15)
This package uses Omnipay., (*16)