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
curlextensionjsonextension- 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');
| Parameter | Description |
|---|---|
service_name | Service name from your Payment Point settings |
secret_hash | Secret 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
| Parameter | Type | Required | Description |
|---|---|---|---|
value | string | Yes | Payment amount (format: "10.00") |
url_success | string | Yes | Redirect URL after a successful payment |
url_fail | string | Yes | Redirect URL after a failed payment |
url_ipn | string | Yes | URL for IPN notifications |
description | string | No | Transaction description visible to the customer |
custom | string | No | Custom 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();
}