PHP code example of wenson / paypal

1. Go to this page and download the library: Download wenson/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/ */

    

wenson / paypal example snippets


return [
    'mode'    => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
    'sandbox' => [
        'client_id'         => env('PAYPAL_SANDBOX_CLIENT_ID', ''),
        'client_secret'     => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''),
        'app_id'            => 'APP-80W284485P519543T',
    ],
    'live' => [
        'client_id'         => env('PAYPAL_LIVE_CLIENT_ID', ''),
        'client_secret'     => env('PAYPAL_LIVE_CLIENT_SECRET', ''),
        'app_id'            => '',
    ],

    'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order'
    'currency'       => env('PAYPAL_CURRENCY', 'USD'),
    'notify_url'     => env('PAYPAL_NOTIFY_URL', ''), // Change this accordingly for your application.
    'locale'         => env('PAYPAL_LOCALE', 'en_US'), // force gateway language  i.e. it_IT, es_ES, en_US ... (for express checkout only)
    'validate_ssl'   => env('PAYPAL_VALIDATE_SSL', true), // Validate SSL when creating api client.
];

// Import the class namespaces first, before using it directly
use Srmklive\PayPal\Services\PayPal as PayPalClient;

$provider = new PayPalClient;

// Through facade. No need to import namespaces
$provider = PayPal::setProvider();

$provider->setApiCredentials($config);

if (Cache::get('token')) {
    $provider->setAccessToken(Cache::get('token'));
} else {
    $response = $provider->getAccessToken();
    Cache::set('token', $response);
}


$provider->setCurrency('EUR');

$provider->createOrder([
  "intent"=> "CAPTURE",
  "purchase_units"=> [
      0 => [
          "amount"=> [
              "currency_code"=> "USD",
              "value"=? "100.00"
          ]
      ]
  ]
]);

$provider->capturePaymentOrder($order_id); //order id from the createOrder step 

$provider = new Paypal();

// behalf of merchant
$provider->actingAs($merchantId);

// partner referrals
$provider->partnerReferrals($trackingId);
bash
php artisan vendor:publish --provider "Srmklive\PayPal\Providers\PayPalServiceProvider"