PHP SDK
The official PHP SDK provides a convenient, type-safe interface for Paysera Checkout.
The official PHP SDK for Paysera Checkout provides a convenient, type-safe interface for integrating payments into your PHP applications.
Features​
- Type-safe API - Full type hints and IDE autocompletion
- Automatic token management - Handles OAuth2 token lifecycle
- Signature verification - Built-in webhook signature validation
- Error handling - Structured exceptions for error cases
- Flexible configuration - Supports custom repositories for persistence
Requirements​
- PHP 7.4 or higher
- Composer
- cURL extension
Quick Start​
Installation​
composer require paysera/lib-checkout-integration-sdk
Basic Usage​
<?php
use Paysera\CheckoutSdk\SdkFacadeBuilder;
use Paysera\CheckoutSdk\Entity\PaymentApiCredentials;
// Build the SDK
$sdk = (new SdkFacadeBuilder())->build();
// Authenticate
$credentials = new PaymentApiCredentials(
'your-client-id',
'your-client-secret'
);
$sdk->getAuthorizationFacade()->authorize($credentials);
// Create a payment
$paymentsFacade = $sdk->getPaymentsFacade();
$orderRequest = $paymentsFacade->buildPaymentOrderCreateRequest([
'redirect_urls' => [
'success_url' => 'https://example.com/success',
'failure_url' => 'https://example.com/failure',
'callback_url' => 'https://example.com/webhook',
],
'metadata' => [
'referrer' => 'https://your-site.com',
'platform' => 'custom',
'platform_version' => '1.0.0',
'plugin_name' => 'my-integration',
'plugin_version' => '1.0.0',
],
'purchase' => [
'reference' => 'ORDER-001',
'amount' => 2500, // 25.00 EUR in cents
'currency' => 'EUR',
],
]);
$linkRequest = $paymentsFacade->buildPaymentLinkCreateRequest([
'name' => 'Order #001',
'lifetime' => 3600,
]);
$response = $paymentsFacade->initiatePayment($orderRequest, $linkRequest);
// Redirect to payment page
header('Location: ' . $response->getPaymentUrl());
SDK Architecture​
The SDK is organized around facades that group related functionality:
| Facade | Purpose |
|---|---|
| Authorization | OAuth2 authentication |
| Payments | Orders, links, payment methods |
| Callbacks | Webhook processing and verification |
| Infrastructure | Environment configuration |
Facade Access​
$sdk = (new SdkFacadeBuilder())->build();
// Access facades
$authFacade = $sdk->getAuthorizationFacade();
$paymentsFacade = $sdk->getPaymentsFacade();
$callbacksFacade = $sdk->getCallbacksFacade();
$infraFacade = $sdk->getInfrastructureFacade();
Configuration​
With Token Persistence​
$sdk = (new SdkFacadeBuilder())
->setPaymentApiAuthTokenRepository($myTokenRepository)
->setPaymentApiCredentialsRepository($myCredentialsRepository)
->build();
With Custom Logger​
use Psr\Log\LoggerInterface;
$sdk = (new SdkFacadeBuilder())
->setLogger($myLogger) // PSR-3 compatible logger
->build();
Error Handling​
The SDK throws typed exceptions:
use Paysera\CheckoutSdk\Exception\IntegrationException;
use Paysera\CheckoutSdk\Exception\ValidationException;
try {
$response = $paymentsFacade->initiatePayment($orderRequest, $linkRequest);
} catch (ValidationException $e) {
// Invalid request data
echo "Validation error: " . $e->getMessage();
} catch (IntegrationException $e) {
// API or network error
echo "Integration error: " . $e->getMessage();
}
Documentation​
- Installation - Detailed installation guide
- Authorization - Authentication setup
- Payments - Creating payments
- Callbacks - Webhook handling
Source Code​
The SDK is open source and available on GitHub. See the repository for:
- Full source code
- Issue tracking
- Contribution guidelines