PHP code example of paynl / omnipay-paynl

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

    

paynl / omnipay-paynl example snippets


# Use PAY. Item class
use Omnipay\Paynl\Common\Item;

# Add items to transaction
$arrItems = array();
$item = new Item();
$item->setProductId('SKU01')
        ->setProductType('ARTICLE')
        ->setVatPercentage(21)
        ->setDescription('Description')
        ->setName('PAY. article')
        ->setPrice('10')
        ->setQuantity(4);
$arrItems[] = $item;

$item = new Item();
$item->setProductId('SHIP01')
        ->setProductType('SHIPPING')
        ->setVatPercentage(21)
        ->setDescription('Description')
        ->setName('PAY. shipping')
        ->setPrice('5')
        ->setQuantity(1);
$arrItems[] = $item;

$item = new Item();
$item->setProductId('SKU02')
        ->setProductType('DISCOUNT')
        ->setVatPercentage(21)
        ->setDescription('Description')
        ->setName('PAY. promotion')
        ->setPrice('1')
        ->setQuantity(1);
$arrItems[] = $item;

# Send purchase request
$response = $gateway->purchase(
    [
        'amount' => '46.00',
        'currency' => 'EUR',
        'transactionReference' => 'referenceID1',
        'clientIp' => '192.168.192.12',
        'returnUrl' => 'http://www.yourdomain.com/return_from_pay.php',
        'items' => $arrItems,
        'card' => array(
            'firstName' => 'Example',
            'lastName' => 'User',
            'gender' => 'M',
            'birthday' => '01-02-1992',
            'phone' => '1111111111111111',
            'email' => '[email protected]',
            'country' => 'NL',

            'shippingAddress1' => 'Shippingstreet 1B',
            'shippingAddress2' => '',
            'shippingCity' => 'Shipingtown',
            'shippingPostcode' => '1234AB',
            'shippingState' => '',
            'country' => 'NL',

            'billingFirstName' => 'Billingexample',
            'billingLastName' => 'Billinguser',
            'billingAddress1' => 'Billingstreet 1B',
            'billingAddress2' => '',
            'billingCity' => 'Billingtown',
            'billingPostcode' => '1234AB',
            'billingState' => '',
            'country' => 'NL'                     
        )
    ]
)->send();
 
# Process response
if ($response->isSuccessful()) {
     
    # Payment was successful
    var_dump($response);
 
} elseif ($response->isRedirect()) {
     
    # Redirect to offsite payment gateway
    $response->redirect();
     
} else {
 
    # Payment failed
    echo $response->getMessage();
}

$response = $gateway->refund([
    'transactionReference' => "PAY. transactionId",
    'amount' => '46.00',
    'currency' => 'USD',
    'transactionId' => 765897
])->send();

if ($response->isSuccessful()) {

    # Refund was successful
    print_r($response);

} else {

    # Refund failed
    echo $response->getMessage();
}


$response = $gateway->capture([
    'transactionReference' => "PAY. transactionId",
    'items' => $arrItems
])->send();

if ($response->isSuccessful()) {

    # Capture was successful
    print_r($response);

} else {

    # Capture failed
    echo $response->getMessage();
}