PHP code example of clippings / omnipay-paypal

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

    

clippings / omnipay-paypal example snippets


$gateway = Omnipay::create('PaypalRest');
$gateway->setClientId('abc123');
$gateway->setSecret('abc123');

$purchase = $gateway->purchase(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'description' => 'This is a purchase',
));

$purchase = $gateway->purchase(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'description' => 'This is a purchase',
    'redirectUrl' => 'http://example.com/completed',
    'cancelUrl' => 'http://example.com/cancel',
));

$response = $purchase->send();

// redirect to $response->getRedirectUrl()
$response->redirect();
$key = $response->getTransactionReference();

// You'll need to pass $key as well as "payerid" query parameter that you'll get from paypal redirecting back to your site

$completePurchase = $gateway->completePurchase(array(
    'transactionReference' => $key,
    'payerId' => $_GET['PAYERID'],
));

$response2 = $completePurchase->send();

$createCard = $gateway->createCard(array(
    'card' => ...,
    'payerId' => 'payer id',
));

$response = $createCard->send();
$cardId = $response->getTransactionReference();

$purchase = $gateway->purchase(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'cardReference' => $cardId,
));

$response = $purchase->send();

$purchase = $gateway->purchase(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'card' => ...,
));

$response = $purchase->send();

$authorise = $gateway->authorise(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'card' => ...,
));

$response = $authorise->send();
$id = $response->getTransactionReference();

$capture = $gateway->capture(array(
    'transactionReference' => $id,
    'amount' => '15.00',
));

$capture->send();

// Or

$capture = $gateway->void(array(
    'transactionReference' => $id,
));

$capture->send();


$createCard = $gateway->createCard(array(
    'card' => ...,
    'payerId' => '123123' // Optional, if set, will be y->updateCard(array(
    'card' => ...,
));

$deleteCard = $gateway->deleteCard(array(
    'card' => ...,
));

$refund = $gateway->refund(array(
    'transactionReference' => $id,
));

$refund->send();

// If you are refunding a capture
$refund = $gateway->refund(array(
    'transactionReference' => $id,
    'type' => 'capture'
));

$refund->send();

// Partial refund
$refund = $gateway->refund(array(
    'transactionReference' => $id,
    'amount' => '10.00'
    'currency' => 'GBP'
));

$refund->send();