-
Notifications
You must be signed in to change notification settings - Fork 4
Migration ‐ Exchange
Wouter Jonker edited this page Jan 27, 2026
·
2 revisions
Install the new PHP SDK via Composer:
composer require paynl/php-sdk
This migration guide is based on the samples available in both the old and the new SDK.
In the old SDK, configuration is loaded via config.php
In the new SDK, configuration is set via the (new) global config/config.global.php
Add the following at the top of your script:
use PayNL\Sdk\Util\Exchange;
$exchange = new Exchange(); $payOrder = $exchange->process();And remove the next line, which is now done using process():
$transaction = \Paynl\Transaction::status($transactionId);Also remove the following:
$transactionId = $_REQUEST['order_id'];
$action = $_REQUEST['action'];
// ...and remove:
if (\Paynl\Config::getIgnoreOnPending() && $action == 'pending') {
die("TRUE| Ignoring pending");
}
// ..and remove:
if ($transaction->isBeingVerified()) {
$approved = false;
$declined = false;
if ($approved) {
$transaction->approve();
die("TRUE| Transaction approved");
} elseif ($declined) {
$transaction->decline();
die("TRUE| Transaction declined");
}
}Change this:
if ($transaction->isPaid() || $transaction->isAuthorized()) {
// process the payment
} elseif ($transaction->isCanceled()) {
// payment canceled, restock items
}Into this:
if ($payOrder->isPending()) {
$responseResult = yourCodeToProcessPendingOrder($payOrder->getReference());
$responseMessage = 'Processed pending';
} elseif ($payOrder->isPaid() || $payOrder->isAuthorized()) {
$responseResult = yourCodeToProcessPaidOrder($payOrder->getReference());
$responseMessage = 'Processed paid. Order: ' . $payOrder->getReference();
} // etc..From
// always start your response 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() ? 'Paid' : 'Not paid';Into
$exchange->setResponse($responseResult, $responseMessage);Note: \Paynl\Error\Error no longer exists in the new SDK.
Old:
catch (\Paynl\Error\Error $e)New:
catch (Throwable $e)Old
<?php
require_once 'vendor/autoload.php';
require_once 'config.php';
try {
$transactionId = $_REQUEST['order_id'];
$action = $_REQUEST['action'];
if (\Paynl\Config::getIgnoreOnPending() && $action == 'pending') {
die("TRUE| Ignoring pending");
}
$transaction = \Paynl\Transaction::status($transactionId);
if ($transaction->isBeingVerified()) {
// here you can do your own checks and approve or decline the order yourself
// the script is stopped after approving or declining, after which a new exchange call will follow.
// the status of this new exchange call will be paid (approved) or canceled (declined)
$approved = false; // use your own function to determine if this should be true or false.
$declined = false; // use your own function to determine if this should be true or false.
if ($approved) {
$transaction->approve();
die("TRUE| Transaction approved");
} elseif ($declined) {
$transaction->decline();
die("TRUE| Transaction declined");
}
}
if ($transaction->isPaid() || $transaction->isAuthorized()) {
// process the payment
} elseif ($transaction->isCanceled()) {
// payment canceled, restock items
}
// always start your response 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() ? 'Paid' : 'Not paid';
} catch (\Paynl\Error\Error $e) {
echo "Fout: " . $e->getMessage();
}New:
<?php
require_once 'vendor/autoload.php';
use PayNL\Sdk\Util\Exchange;
$exchange = new Exchange();
try {
$payOrder = $exchange->process();
$transactionId = $_REQUEST['order_id'];
$action = $_REQUEST['action'];
if ($payOrder->isPending()) {
$responseResult = yourCodeToProcessPendingOrder($payOrder->getReference());
$responseMessage = 'Processed pending';
} elseif ($payOrder->isPaid() || $payOrder->isAuthorized())
{
$responseResult = yourCodeToProcessPaidOrder($payOrder->getReference());
$responseMessage = 'Processed paid. Order: ' . $payOrder->getReference();
} // etc..
} catch (Throwable $exception) {
$responseResult = false;
$responseMessage = $exception->getMessage();
}
$exchange->setResponse($responseResult ?? false, $responseMessage ?? '');