PHP code example of amostajo / laravel-shop-gateway-omnipay

1. Go to this page and download the library: Download amostajo/laravel-shop-gateway-omnipay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

amostajo / laravel-shop-gateway-omnipay example snippets


'omnipay'           =>  Amostajo\LaravelShopGatewayOmnipay\GatewayOmnipay::class,

// (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.

}

// (1) - Set gateway
Shop::setGateway('omnipay');
Shop::gateway()->create('Stripe');

// (2) - Setting method / calling specific method
Shop::gateway()->omnipay->setSpecific();

// (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();

// (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.