online-payments / sdk-php
PHP SDK to communicate with the payment platform server-to-server API
Requires
- php: >=8.3
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- ext-zlib: *
- robtimus/multipart: ~1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- phpstan/phpstan: ^2.1.32
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 14.0.0
- 13.1.0
- 13.0.0
- 12.1.0
- 12.0.0
- 11.3.0
- 11.2.1
- 11.2.0
- 11.1.0
- 11.0.0
- 10.2.0
- 10.1.0
- 10.0.0
- 9.6.0
- 9.5.0
- 9.4.0
- 9.3.0
- 9.2.0
- 9.1.0
- 9.0.0
- 8.4.0
- 8.3.0
- 8.2.1
- 8.2.0
- 8.1.0
- 8.0.1
- 8.0.0
- 7.5.0
- 7.4.0
- 7.3.1
- 7.3.0
- 7.2.0
- 7.1.0
- 7.0.0
- 6.2.0
- 6.1.0
- 6.0.0
- 5.18.0
- 5.17.0
- 5.16.1
- 5.16.0
- 5.15.0
- 5.14.0
- 5.13.0
- 5.12.0
- 5.11.0
- 5.10.0
- 5.9.0
- 5.8.2
- 5.8.1
- 5.8.0
- 5.7.0
- 5.6.0
- 5.5.0
- 5.4.0
- 5.3.0
- 5.2.1
- 5.2.0
- 5.1.0
- 5.0.0
- 4.6.0
- 4.5.0
- 4.4.0
- 4.3.0
- 4.1.0
- 4.0.0
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.0
This package is auto-updated.
Last update: 2026-11-27 10:19:22 UTC
README
Introduction
The PHP SDK helps you to communicate with the payment platform server API. Its primary features are:
- convenient PHP library for the API calls and responses
- marshals PHP request objects to HTTP requests
- unmarshals HTTP responses to PHP response objects or PHP exceptions
- handling of all the details concerning authentication
- handling of required metadata
See the Worldline Online Payments Developer Hub for more information on how to use the SDK.
Structure of this repository
This repository consists out of three main components:
- The source code of the SDK itself:
/src: the API clients, request and response classes and exceptions, generated from the API specification/lib: the hand-written runtime, such as communication, authentication, logging and webhooks
- The source code of the SDK unit tests:
/tests/OnlinePayments/Sdk/Unit - The source code of the integration tests:
/tests/OnlinePayments/Sdk/Integration
Both /src and /lib use the OnlinePayments\Sdk namespace.
Requirements
PHP 8.3 or higher is required, with the curl, json, mbstring and zlib extensions. In addition, the following package is required:
- robtimus/multipart 1.0 or higher, for multipart uploads
This package will be installed automatically if the SDK is installed using Composer.
Installation
Using Composer
To install the SDK using Composer, execute the following command:
composer require online-payments/sdk-php
Then include the Composer autoloader in your project, if this is not already done:
require __DIR__ . '/vendor/autoload.php';
Manual installation
- Download the latest version of the PHP SDK from GitHub. Choose the
sdk-php-x.y.z.tar.gzfile from the releases page, wherex.y.zis the version number. - Add the contents of the
tar.gzfile to your project. The contents of the/srcand/libfolders may be combined, if this is required by the project. - Add all classes from the
/srcand/libfolders to your autoloader; all classes inside these folders are compliant with PSR-4. - Install robtimus/multipart in the same way, and add it to your autoloader.
Working with AI agents
The SDK comes with an agent skill for AI coding agents such as Claude Code, Codex, GitHub Copilot and Cursor. It tells the agent how to choose an integration method, which steps each flow needs, which rules every integration must follow, and gives code examples that are checked against this SDK version.
The skill for this version is available:
- online, as plain Markdown for agents: https://raw.githubusercontent.com/Online-Payments/sdk-php/14.0.0/skills/online-payments/SKILL.md
- online, on GitHub: https://github.com/Online-Payments/sdk-php/blob/14.0.0/skills/online-payments/SKILL.md
- in the Composer package:
vendor/online-payments/sdk-php/skills/online-payments/ - in this repository:
skills/online-payments/
To make your agent use it, add this to the AGENTS.md or CLAUDE.md file of your project:
For the Online Payments integration (online-payments/sdk-php), read and follow the agent skill
vendor/online-payments/sdk-php/skills/online-payments/SKILL.md
(online: https://raw.githubusercontent.com/Online-Payments/sdk-php/14.0.0/skills/online-payments/SKILL.md)
Use the code shown in the skill; do not write SDK calls from memory.
Agents that support the Agent Skills format can also load the folder directly, for example by copying vendor/online-payments/sdk-php/skills/online-payments/ to .claude/skills/online-payments/ in your project for Claude Code.
Usage
Creating a client
use OnlinePayments\Sdk\Factory; $client = Factory::createClient( apiEndpoint: 'https://payment.direct.ecom.preprod.worldline-solutions.com', apiKeyId: '...', apiSecret: '...', integrator: 'MyShop', connectTimeout: 10, // seconds readTimeout: 60, // seconds // optional: proxyConfiguration, shoppingCartExtension );
The timeouts must be positive. readTimeout is the maximum time for the whole request, including the transfer of the response.
For large uploads or slow connections, use a higher value.
A proxy can be configured with proxyConfiguration: new ProxyConfiguration('proxy.example.com', 3128), optionally with a username and password.
A client can also be created from a CommunicatorConfiguration with Factory::createClientFromConfiguration($configuration).
The merchant ID is not part of the client configuration; pass it to $client->merchant($merchantId).
Creating requests
Request objects can be built with the fluent with* methods, the setters or the public properties:
use OnlinePayments\Sdk\CallContext; use OnlinePayments\Sdk\Domain\AmountOfMoney; use OnlinePayments\Sdk\Domain\CreatePaymentRequest; use OnlinePayments\Sdk\Domain\Order; $request = (new CreatePaymentRequest()) ->withOrder((new Order()) ->withAmountOfMoney((new AmountOfMoney())->withAmount(125000)->withCurrencyCode('EUR'))); $callContext = new CallContext(); $callContext->setIdempotenceKey('order-42'); $response = $client->merchant($merchantId)->payments()->createPayment($request, $callContext);
Assigning a property that does not exist throws an Exception.
var_dump and print_r of a request or response object show its fields, with card numbers, CVVs and personal data masked.
Handling errors
use OnlinePayments\Sdk\Communication\CommunicationException; use OnlinePayments\Sdk\Communication\ErrorResponseException; use OnlinePayments\Sdk\DeclinedPaymentException; use OnlinePayments\Sdk\ResponseException; try { $response = $client->merchant($merchantId)->payments()->createPayment($request, $callContext); } catch (DeclinedPaymentException $e) { $declinedPayment = $e->getCreatePaymentResponse(); } catch (ResponseException $e) { $logger->error('Payment failed: ' . $e); // the response in the string is masked $errors = $e->getErrors(); $previous = $e->getPrevious(); if ($previous instanceof ErrorResponseException) { $headers = $previous->getHeaders(); // the response headers } } catch (CommunicationException $e) { // $e->getMessage() contains the cURL error }
All exceptions for error responses extend ResponseException, for example ValidationException, AuthorizationException, ReferenceException, IdempotenceException and ApiException.
getHttpStatusCode(), getErrorId() and getErrors() give the details of the error. The unmasked response is available in getResponse().
A timeout, a CommunicationException or a PlatformException during createPayment means the outcome of the payment is unknown.
Check the payment status with getPayment, and always send an idempotence key so that a retry does not create a second payment.
Logging
use OnlinePayments\Sdk\Logging\SplFileObjectLogger; $client->enableLogging(new SplFileObjectLogger(new SplFileObject('sdk.log', 'a'))); // ... $client->disableLogging();
Requests and responses are logged with card numbers, CVVs, personal data and authorization headers masked.
ResourceLogger logs to a PHP stream resource instead; a custom logger implements CommunicatorLogger.
Development and testing
- Install Composer.
- From the root of the repository, execute
composer install.
There are two types of tests: unit tests and integration tests. The unit tests will work out-of-the-box; for the integration tests some configuration is required.
Copy tests/config.json.dist to tests/config.json and replace the template values with your merchant ID, API endpoint, API key and secret API key. The proxy values are optional.
The following commands can then be executed from the root of the repository:
-
Unit tests:
vendor/bin/phpunit --testsuite unit -
Integration tests:
vendor/bin/phpunit --testsuite integration -
Both unit and integration tests:
vendor/bin/phpunit -
Static analysis:
vendor/bin/phpstan analyse -c phpstan.neon -
Code style of the hand-written code and the tests:
composer style -
All automated quality checks (PHPStan, code style and unit tests):
composer quality
Some unit tests start a local PHP web server on port 8080; keep this port free when running them.