PHP code example of descom / omnipay-paypal

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

    

descom / omnipay-paypal example snippets


use Omnipay\Omnipay;

$gateway = Omnipay::create('PayPal');

$gateway->initialize([
    'clientId' => 'YOUR_CLIENT_ID',
    'secret'   => 'YOUR_SECRET',
    'testMode' => true, // sandbox
    'currency' => 'EUR',
]);

$response = $gateway->purchase([
    'amount'         => '12.00',
    'currency'       => 'EUR',
    'transactionId'  => 'ORDER-42',
    'description'    => 'My order',
    'returnUrl'      => 'https://shop.test/paypal/return',
    'cancelUrl'      => 'https://shop.test/paypal/cancel',
])->send();

// Redirect the buyer (GET) to the PayPal approval page.
$response->redirect();

$response = $gateway->completePurchase([
    'token' => $_GET['token'],
])->send();

if ($response->isSuccessful()) {
    // $response->getTransactionReference() -> capture id
}