PHP code example of amsgames / laravel-shop-gateway-paypal

1. Go to this page and download the library: Download amsgames/laravel-shop-gateway-paypal 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/ */

    

amsgames / laravel-shop-gateway-paypal example snippets


'paypal'            =>  Amsgames\LaravelShopGatewayPaypal\GatewayPayPal::class,
'paypalExpress'     =>  Amsgames\LaravelShopGatewayPaypal\GatewayPayPalExpress::class,

    'paypal' => [
        'client_id' => env('PAYPAL_CLIENT_ID', ''),
        'secret' => env('PAYPAL_SECRET', ''),
        'sandbox' => env('PAYPAL_SANDBOX', true),
    ],

// (1) - Set gateway
Shop::setGateway('paypal');

// (2) - Add credit card for validation
Shop::gateway()->setCreditCard(
  $cartType   = 'visa',
  $cardNumber = '4111111111111111',
  $month      = '1',
  $year       = '2019',
  $cvv        = '123',
  $firstname  = 'John',
  $lastname   = 'Doe'
);

// (3) - Call checkout
if (!Shop::checkout()) {
  echo Shop::exception()->getMessage(); // echos: card validation error.
}

// (4) - Create order
$order = Shop::placeOrder();

// (5) - Review payment
if ($order->hasFailed) {

  echo Shop::exception()->getMessage(); // echos: payment error.

}

    /*
    |--------------------------------------------------------------------------
    | Redirect route after callback
    |--------------------------------------------------------------------------
    |
    | Which route to call after the callback has been processed.
    |
    */
    'callback_redirect_route' => 'home',

// (1) - Set gateway
Shop::setGateway('paypalExpress');

// (2) - Call checkout / OPTIONAL
// You can call this to keep a standard flow
// Although this step for this gateway is not needed.
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.