-
Notifications
You must be signed in to change notification settings - Fork 3
Exchange
Wouter Jonker edited this page Nov 27, 2025
·
3 revisions
The SDK includes functionality to make it very easy to setup your exchange handler, and process your orders.
<?php
# Include your autoload.php
require 'vendor/autoload.php';
use PayNL\Sdk\Util\ExchangeResponse;
use PayNL\Sdk\Util\Exchange;
# Instantiate the exchange object using the settings from config/config.global.php
$exchange = new Exchange();
try {
# Process the exchange request. This will take care of any type of exchange: GET, POST and even requests.
# This function will return a payOrder object or throws an exception when something went wrong.
$payOrder = $exchange->process();
if ($payOrder->isPending()) {
$response = new ExchangeResponse(true, 'Ignoring pending');
} elseif ($payOrder->isPaid()) {
$response = yourCodeToProcessPaidOrder($payOrder->getReference());
} else {
$response = new ExchangeResponse(true, 'No action defined for payment state ' . $payOrder->getStateId());
}
} catch (Throwable $exception) {
$response = new ExchangeResponse(false, 'failed: ' . $exception->getMessage());
}
# Finally the response of your exchange handler
$exchange->setExchangeResponse($response);
/**
* @param $reference
* @return ExchangeResponse
*/
function yourCodeToProcessPaidOrder($reference): ExchangeResponse
{
try {
// try to set your order to status paid
return new ExchangeResponse(true, 'successfully processed');
} catch (Throwable $exception) {
return new ExchangeResponse(false, 'could not process: ' . $exception->getMessage());
}
}See also the sample in the repository.
| Function | Description |
|---|---|
| isPaid | To check whether the payment was fully paid |
| isFastCheckout | To determine whether the transaction is a fastCheckout-transaction |
| getReference | To retrieve your payment reference |