Skip to main content

PHP SDK

Available - stable release

Official PHP library for integrating with the dpay.pl API. It automates checksum generation, payment registration, and IPN notification verification.


Requirements

  • PHP 8.1 or newer
  • curl extension
  • json extension
  • Composer

Installation

Install the package using Composer:

composer require dpay/dpay-php

Configuration

Create a client instance using the credentials from the dpay.pl Panel:

use DPay\Client;

$dpay = new DPay\Client('service_name', 'secret_hash');
ParameterDescription
service_nameService name from your Payment Point settings
secret_hashSecret hash used for checksum generation

Registering a payment

$dpay = new DPay\Client('service_name', 'secret_hash');

$payment = $dpay->registerPayment([
'value' => '10.00',
'url_success' => 'https://myshop.pl/success',
'url_fail' => 'https://myshop.pl/fail',
'url_ipn' => 'https://myshop.pl/ipn',
]);

// Redirect the user to the payment page
header('Location: ' . $payment->msg);
exit;

Payment parameters

ParameterTypeRequiredDescription
valuestringYesPayment amount (format: "10.00")
url_successstringYesRedirect URL after a successful payment
url_failstringYesRedirect URL after a failed payment
url_ipnstringYesURL for IPN notifications
descriptionstringNoTransaction description visible to the customer
customstringNoCustom data identifying the order

IPN handling

Verification and handling of Instant Payment Notification messages:

$dpay = new DPay\Client('service_name', 'secret_hash');

try {
$notification = $dpay->handleIPN($_POST);

if ($notification->status === 'completed') {
// Payment completed successfully
// Update the order status in your database
}

// Respond with status 200 to confirm receipt
http_response_code(200);
echo 'OK';
} catch (\DPay\Exception\InvalidSignatureException $e) {
// Invalid signature - possible tampering attempt
http_response_code(400);
echo 'Invalid signature';
}

Error handling

The SDK throws dedicated exceptions to simplify handling of different scenarios:

use DPay\Exception\ApiException;
use DPay\Exception\InvalidSignatureException;
use DPay\Exception\NetworkException;

try {
$payment = $dpay->registerPayment([...]);
} catch (NetworkException $e) {
// Network connection issue
} catch (ApiException $e) {
// Error returned by the dpay.pl API
echo $e->getErrorCode();
echo $e->getMessage();
}

More information