PHP code example of paynl / sdk

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




# Replace tokenCode apitoken and serviceId with your own.
\Paynl\Config::setTokenCode('AT-####-####');
\Paynl\Config::setApiToken('****************************************');
\Paynl\Config::setServiceId('SL-####-####');



\Paynl\Config::setTokenCode('AT-####-####');
\Paynl\Config::setApiToken('****************************************');
\Paynl\Config::setServiceId('SL-####-####');

$paymentMethods = \Paynl\Paymentmethods::getList();
var_dump($paymentMethods);



\Paynl\Config::setTokenCode('AT-####-####');
\Paynl\Config::setApiToken('****************************************');
\Paynl\Config::setServiceId('SL-####-####');

$result = \Paynl\Transaction::start(array(
    # Required
        'amount' => 10.00,
        'returnUrl' => Paynl\Helper::getBaseUrl().'/return.php',

    # Optional
    	'currency' => 'EUR',
        'exchangeUrl' => Paynl\Helper::getBaseUrl().'/exchange.php',
        'paymentMethod' => 10,
        'bank' => 1,
        'description' => 'demo betaling',
        'testmode' => 1,
        'extra1' => 'ext1',
        'extra2' => 'ext2',
        'extra3' => 'ext3',
        'products' => array(
            array(
                'id' => 1,
                'name' => 'een product',
                'price' => 5.00,
                'tax' => 0.87,
                'qty' => 1,
            ),
            array(
                'id' => 2,
                'name' => 'ander product',
                'price' => 5.00,
                'tax' => 0.87,
                'qty' => 1,
            )
        ),
        'language' => 'EN',
        'ipaddress' => '127.0.0.1',
        'invoiceDate' => new DateTime('2016-02-16'),
        'deliveryDate' => new DateTime('2016-06-06'), // in case of tickets for an event, use the event date here
        'enduser' => array(
            'initials' => 'T',
            'lastName' => 'Test',
            'gender' => 'M',
            'birthDate' => new DateTime('1990-01-10'),
            'phoneNumber' => '0612345678',
            'emailAddress' => '[email protected]',
        ),
        'address' => array(
            'streetName' => 'Test',
            'houseNumber' => '10',
            'zipCode' => '1234AB',
            'city' => 'Test',
            'country' => 'NL',
        ),
        'invoiceAddress' => array(
            'initials' => 'IT',
            'lastName' => 'ITEST',
            'streetName' => 'Istreet',
            'houseNumber' => '70',
            'zipCode' => '5678CD',
            'city' => 'ITest',
            'country' => 'NL',
        ),
    ));

# Save this transactionid and link it to your order
$transactionId = $result->getTransactionId();

# Redirect the customer to this url to complete the payment
$redirect = $result->getRedirectUrl();



\Paynl\Config::setTokenCode('AT-####-####');
\Paynl\Config::setApiToken('****************************************');

$transactionId = $_REQUEST['orderId'];

$transaction = \Paynl\Transaction::status($transactionId);

# Manual transfer transactions are always pending when the user is returned
if( $transaction->isPaid() || $transaction->isPending()) {
   # Redirect to thank you page
} elseif($transaction->isCanceled()) {
   # Redirect back to checkout
}



\Paynl\Config::setTokenCode('AT-####-####');
\Paynl\Config::setApiToken('****************************************');

$transactionId = $_REQUEST['order_id'];

$transaction = \Paynl\Transaction::status($transactionId);

if($transaction->isPaid() || $transaction->isAuthorized()) {
    # Process the payment
} elseif($transaction->isCanceled()) {
    # Payment canceled, restock items
}

# Always respond with TRUE|
echo "TRUE| ";

# Optionally you can send a message after TRUE|, you can view these messages in the logs.
# https://admin.pay.nl/logs/payment_state
echo ($transaction->isPaid() || $transaction->isAuthorized())?'Paid':'Not paid';



use Paynl\Config;
use Paynl\Transaction;

nfig::setApiToken('****************************************');
Config::setServiceId('SL-####-####');

# Setting Failover gateway (for available cores, call Config::getCores())
Config::setCore( Config::CORE2 );

# Or for SDK versions lower then 1.6.7, use:
Config::setApiBase('https://rest.achterelkebetaling.nl');

$
vendor/bin/phpunit --bootstrap vendor/autoload.php  tests/