PHP code example of paynl / sdk-alliance

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




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

$merchant = \Paynl\Alliance\Merchant::add((array)$merchantData);

/* 
 *  Save the merchantId to your database.
 *  You'll need this id in the next call
 */
$merchantId = $merchant->getMerchantId();


/* 
 * Possible states are: new, accepted, deleted.
 * You can omit this value to get all merchants
 */
$result = Paynl\Alliance\Merchant::getList(array('state' => 'new')); 
$merchants = $result->getMerchants();

foreach ($merchants as $merchant) {
    echo $merchant->getMerchantId() . ' ' . $merchant->getMerchantName() . "<br />";
}


$merchant = Paynl\Alliance\Merchant::get(array('merchantId' => 'M-1820-9300'));

# Documents that still need to be uploaded (for the next example)
$documents = $merchant->getMissingDocuments();

var_dump($documents);


$result = Paynl\Alliance\Document::upload(array(
      'documentId' => 'D-####-####',
      'path' => '/path/to/the/file',
      'filename' => 'bankStatement.pdf' # Optional, when you leave this blank, the filename from the path will be used
	));

if ($result->success()) {
}


$result = Paynl\Alliance\Document::upload(array(
      'documentId' => 'D-####-####',
      'path' => array('/path/to/the/file', 'path/to/the/second/file'),
      'filename' => 'bankStatement.pdf' # Optional, when you leave this blank, the filename from the path will be used
	));

if ($result->success()) {
}


$categories = Paynl\Alliance\Service::getCategories();
$data = $categories->getData();

var_dump($data);

$result = Paynl\Alliance\Service::add(array(
    'merchantId' => 'M-####-####',
    'name' => 'The name of my sales location tells us what my Sales location is about', 
    'description' => 'This description describes what people are paying for',
    'categoryId' => 'CY-####-####', # Use Paynl\Alliance\Service::getCategories() to get the list of available categories
    'url' => 'https://www.pay.nl',
    'extraUrls' => array(
        'https://phpsdk.webshop.pay.nl',
        'https://sdkalliance.webshop.pay.nl'
    ),
    'alwaysSendExchange' => true # Set to false if you only want a notification on successfull payment (not recommended)
));


$paymentOptions = Paynl\Alliance\Service::getAvailablePaymentMethods(array('serviceId' => 'SL-####-####'));
$data = $paymentOptions->getData();

var_dump($data);

\Paynl\Config::setServiceId('SL-####-####'); 
$paymentMethods = \Paynl\Paymentmethods::getList();
var_dump($paymentMethods);


$success = Paynl\Alliance\Service::enablePaymentMethod(array(
    'serviceId' => 'SL-####-####',
    'paymentMethodId' => 739,
    'settings' => array( # Optional for payment methods that have settings.
        'merchantId' => 1234,
        'merchantPassword' => 'p4ssw0rd',
        'portefeuilleId' => '1'
    )
));

if($success) {
    # Enabled
}

$success = Paynl\Alliance\Service::disablePaymentMethod(array(
    'serviceId' => 'SL-####-####',
    'paymentMethodId' => 739    
));

if($success) {
   # Disabled
}

\Paynl\Alliance\Statistics::PERIOD_THIS_WEEK
\Paynl\Alliance\Statistics::PERIOD_LAST_WEEK
\Paynl\Alliance\Statistics::PERIOD_THIS_MONTH
\Paynl\Alliance\Statistics::PERIOD_LAST_MONTH

$result = Paynl\Alliance\Statistics::getStats(array(
    'period' => \Paynl\Alliance\Statistics::PERIOD_LAST_WEEK
));
var_dump($result->getData());

$result = Paynl\Alliance\Statistics::getStats(array(
    'startDate' => new DateTime('2015-03-01'),
    'endDate' => new DateTime('2015-03-10')
));
var_dump($result->getData());

\Paynl\Config::setServiceId('SL-####-####');

$result = Paynl\Alliance\Invoice::add(array(

    # Required
    'merchantId' => 'M-####-####', # The id of the merchant
    'serviceId' => 'SL-####-####', # The serviceid (of the Alliance) to book the payment on
    'invoiceId' => 'INV012345',# Your reference number to the invoice
    'amount' => 25.75, # The total amount of the invoice
    'description' => 'Test invoice', # The description of the invoice

    # Optional
    'invoiceUrl' => 'https://url.to.the/invoice.pdf', # The url to the invoice
    'makeYesterday' => true # If the invoice needs to be added in today's clearing, set this to true
    'extra1' => 'free variable 1',
    'extra2' => 'free variable 2',
    'extra3' => 'free variable 3',
    "merchantServiceId": "SL-####-####", # The ServiceId of the submerchant that needs to be invoiced  
));

$referenceId = $result->referenceId();

$result = \Paynl\Alliance\Merchant::addClearing(array(

    # Required
    'amount' => '123', # The amount to clear, in cents.

    # Optional
    'merchantId' => 'M-1234-5678', # The id of the merchant
    'contentCategoryId' => 'CT-1234-5678' # The content category Id
));

$referenceId = $result->referenceId();