PHPackages                             202ecommerce/younitedpay-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. 202ecommerce/younitedpay-sdk

ActiveLibrary[API Development](/categories/api)

202ecommerce/younitedpay-sdk
============================

younited pay API SDK

3.5(1mo ago)03.1k↓12.5%[1 PRs](https://github.com/YounitedCredit/younitedpay-sdk-php/pulls)1AFL-3.0PHPCI passing

Since Jun 16Pushed 2w ago4 watchersCompare

[ Source](https://github.com/YounitedCredit/younitedpay-sdk-php)[ Packagist](https://packagist.org/packages/202ecommerce/younitedpay-sdk)[ Docs](https://docs.younited.com/)[ RSS](/packages/202ecommerce-younitedpay-sdk/feed)WikiDiscussions develop Synced 3d ago

READMEChangelog (10)Dependencies (6)Versions (28)Used By (1)

Younited Pay SDK for PHP
========================

[](#younited-pay-sdk-for-php)

[![Coding Standart](https://github.com/YounitedCredit/younitedpay-sdk-php/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/YounitedCredit/younitedpay-sdk-php/actions/workflows/main.yml) [![Unit test](https://github.com/YounitedCredit/younitedpay-sdk-php/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/YounitedCredit/younitedpay-sdk-php/actions/workflows/phpunit.yml)

This package is a Younited Pay PHP SDK. It let you mange exchange between your shop and Younited Pay.

This package is a dependancy of Younited Credit PrestaShop or Magento plugin.

Versions scope
--------------

[](#versions-scope)

This package is compatible with PHP 5.6+.

PHP VersionSDK VersionPHP 5.6 to PHP 8.0 (not included)v1.XPHP 8.0+v2.XPHP 5.6+ to PHP8+v3.XHow to install it ?
-------------------

[](#how-to-install-it-)

Todo: Composer via packagist

To use this package with php 5.6 or in production mode, please install this dependancy with :

```
composer update --ignore-platform-reqs --no-dev

```

in a eveloppement environment

```
composer update

```

Recommandations
---------------

[](#recommandations)

You can see one example of use of this SDK here : Each application should consider several points :

- Security
    You have an example of how should be check a payment on an application. We should not trust requests (even verified webhooks) and make an API call to check if payment is done and if the amount paid is the right one related to the order we have to place.
- Performance
    Application must implement cache to avoid making the same requests and get token each call.
    Token expire each hour, offers every days.

How to try this SDK ?
---------------------

[](#how-to-try-this-sdk-)

First of all, you will need to create your account and get credentials from Younited Pay. Then you can use them to retrieve your shop codes and begin the adventure !

### Get shop codes for one merchant

[](#get-shop-codes-for-one-merchant)

[Shop Codes documentation](https://docs.younited.com/pay/#tag/shops/GET/shops)

This is usefull for merchants with several point of sales and mandatory for creating payments. In previous API there was a fallback to get the "ONLINE" one if found by default for the merchant. Please be carefull and prefer to let merchants save this configuration to make API calls.

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Request\NewAPI\ShopsRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$request = new ShopsRequest();
// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    $shopCodes = $response->getModel();

    $shopCodesNames = [];
    foreach ($shopCodes as $oneShopCode) {
        if (isset($oneShopCode['name']) && isset($oneShopCode['code'])) {
            $shopCodesNames[] = [
                'name' => $oneShopCode['name'],
                'code' => $oneShopCode['code'],
            ];
        }
    }
    echo 'Shop codes name and code only:';
    var_dump($shopCodesNames);
    echo '';
}
```

Please note that this is the code which is needed (not the name ) !

### Get Younited Pay eligible offers, per maturities

[](#get-younited-pay-eligible-offers-per-maturities)

[Get Offers documentation](https://docs.younited.com/pay/#tag/personal-loans/GET/personal-loans/offers)

You can easily get list of offer by creating a request

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Model\NewAPI\GetOffers;
use YounitedPaySDK\Request\NewAPI\GetOffersRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$body = (new GetOffers())
        ->setShopCode('ONLINE-SHOP-CODE') // New in v3 - shop code needed - see Shop Codes documentation
        ->setAmount(149.0);

// First possibility: we want only a list of maturities (no range needed)
$body->setMaturityList('24,36');

// Other possitiliby: we want a range (eg: from 24 to 36)
$body->setMaturityRangeStep(1)
     ->setMaturityRangeMin(24)
     ->setMaturityRangeMax(36);

$request = (new GetOffersRequest())->setModel($body);

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Get Available Maturities

[](#get-available-maturities)

[Get Offers documentation - Get only maturities](https://docs.younited.com/pay/#tag/personal-loans/GET/personal-loans/offers)

You can easily get available maturities by creating a request

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Model\NewAPI\GetOffers;
use YounitedPaySDK\Request\NewAPI\GetOffersRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

// Important note - in v3.0 available maturities request disapear - we use range offers to get them
// We use from 1 to 84 to get every available, feel free to adapt your needs
$body = (new GetOffers())
    ->setShopCode('ONLINE-SHOP-CODE') // New in v3 - shop code needed - see Shop Codes documentation
    ->setAmount(1499.0)
    ->setMaturityRangeStep(1) //
    ->setMaturityRangeMin(1)
    ->setMaturityRangeMax(84);

$request = (new GetOffersRequest())->setModel($body);

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    $maturityList = [];
    foreach ($response->getModel() as $oneOffer) {
        if (in_array((int) $oneOffer->getMaturityInMonths(), $maturityList) === false) {
            $maturityList[] = (int) $oneOffer->getMaturityInMonths();
        }
    }
    // Sort maturities - min to max
    usort($validOffers, function ($a, $b) {
        return $a > $b ? 1 : -1;
    });
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Create a payment

[](#create-a-payment)

[Create a payment documentation](https://docs.younited.com/pay/#tag/payments/POST/payments/personal-loan)

You can easily initialize a contract by creating a request

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Adapter\CreatePaymentAdapter;
use YounitedPaySDK\Model\Address;
use YounitedPaySDK\Model\Basket;
use YounitedPaySDK\Model\BasketItem;
use YounitedPaySDK\Model\InitializeContract;
use YounitedPaySDK\Model\MerchantOrderContext;
use YounitedPaySDK\Model\MerchantUrls;
use YounitedPaySDK\Model\NewAPI\CustomExperience;
use YounitedPaySDK\Model\NewAPI\Request\GetPayment;
use YounitedPaySDK\Model\NewAPI\TechnicalInformation;
use YounitedPaySDK\Model\PersonalInformation;
use YounitedPaySDK\Request\InitializeContractRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$datetime = new \DateTime('1970-01-01T00:00:00');

$address = (new Address())
    ->setStreetNumber('123')
    ->setStreetName('StreetName') // 32 caracs max
    ->setAdditionalAddress('') // 32 caracs max
    ->setCity('Country')
    ->setPostalCode('12345')
    ->setCountryCode('FR');

$personalInformation = (new PersonalInformation())
    ->setFirstName('FirstName')
    ->setLastName('LastName')
    ->setGenderCode('MALE')
    ->setEmailAddress('firstname.lastname@mail.com')
    ->setCellPhoneNumber('+33611223344') // Send null if format number is not good (not internationnal or empty)
    ->setBirthDate($datetime) // Warning - must be a valide date see documentation
    ->setAddress($address);

$basketItem1 = (new BasketItem())
    ->setItemName('Item basket 1')
    ->setQuantity(2)
    ->setUnitPrice(45.0);

$basketItem2 = (new BasketItem())
    ->setItemName('Item basket 2')
    ->setQuantity(1)
    ->setUnitPrice(33.0);

$basket = (new Basket())
    ->setBasketAmount(123.0)
    ->setItems([$basketItem1, $basketItem2]);

$merchantUrls = (new MerchantUrls())
    ->setOnApplicationFailedRedirectUrl('on-application-failed-redirect-url.com')
    ->setOnApplicationSucceededRedirectUrl('on-application-succeeded-redirect-url.com')
    ->setOnCanceledWebhookUrl('on-canceled-webhook-url.com')
    ->setOnWithdrawnWebhookUrl('on-withdrawn-webhook-url.com');

$merchantOrderContext = (new MerchantOrderContext())
    ->setChannel('test')
    ->setShopCode('TEST')
    ->setMerchantReference('MerchantReference')
    ->setAgentEmailAddress('merchant@mail.com');

$body = (new InitializeContract())
    ->setRequestedMaturity(10)
    ->setPersonalInformation($personalInformation)
    ->setBasket($basket)
    ->setMerchantUrls($merchantUrls)
    ->setMerchantOrderContext($merchantOrderContext);

$oldRequest = (new InitializeContractRequest())->setModel($body);

// Convert "Old" API calls for new API
// This converter allow you to keep previous code and adapt to your need with new API
$newWebhookUrl = 'new-webhook-url-for-new-api';
$newRedirectUrl = 'new-redirect-url-for-new-api';
// Have new controllers for new URL is recommanded. Only one URL is accepted now for success, cancel and other cases.
// Concerning webhooks, please note that old webhooks will be sent if a contract was done with "old" API.
// So you should keep both use cases. Please note too that webhook format has changes (see end documentation on this point)

$technicalInformation = (new TechnicalInformation())
    ->setWebhookNotificationUrl($webhookUrl)
    ->setApiVersion('2025-01-01'); // See https://docs.younited.com/pay - API Version list and new Request objects

$customExperience = (new CustomExperience())
    ->setCustomerRedirectUrl($redirectUrl);

$request = (new CreatePaymentAdapter())
    ->setShopCode('ONLINE-SHOP-CODE') // New in v2 - shop code needed - see Shop Codes documentation
    ->setTechnicalInformation($technicalInformation)
    ->setCustomExperience($customExperience)
    ->convertInitializeContract($oldRequest);

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Load Contract

[](#load-contract)

[Get a payment documentation](https://docs.younited.com/pay/#tag/payments/GET/payments/%7Bid%7D)

You can easily load a payment information by creating a request. Please not that now we retrieve the paymentId from contract creation and use it for each calls (instead of contract reference)

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Model\NewAPI\GetPayment;
use YounitedPaySDK\Request\NewAPI\GetPaymentRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$getPaymentRequestModel = (new GetPayment())->setId('payment-id');
$request = (new GetPaymentRequest())->setModel($getPaymentRequestModel);

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Confirm Contract (depracated)

[](#confirm-contract-depracated)

It will not be needed anymore to confirm a payment as it was for a contract. More details on migration guide here :

### Activate Contract

[](#activate-contract)

[Execute a payment documentation](https://docs.younited.com/pay/#tag/payments/POST/payments/%7Bid%7D/execute)

You can easily execute a payment by creating a request

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Model\NewAPI\Request\ExecutePayment;
use YounitedPaySDK\Request\NewAPI\ExecutePaymentRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$body = (new ExecutePayment())->setId('payment-id');

$request = new ExecutePaymentRequest();

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Withdraw Contract

[](#withdraw-contract)

[Refund a payment documentation](https://docs.younited.com/pay/#tag/refunds/POST/refunds)

You can easily refund a payment (totally or partially) by creating a request

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Request\NewAPI\RefundPaymentRequest;
use YounitedPaySDK\Model\NewAPI\Request\RefundPayment;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$body = (new RefundPayment())
        ->setPaymentId('payment-id')
        ->setAmount((float) round(150, 2)) // Amount to withdrawn float
        ->setIdempotencyKey('your-idempotency-key');

$request = new RefundPaymentRequest();

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)
        ->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Cancel Contract

[](#cancel-contract)

[Cancel a payment documentation](https://docs.younited.com/pay/#tag/payments/POST/payments/%7Bid%7D/cancel)

You can easily cancel a payment by creating a request

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Model\NewAPI\Request\CancelPayment;
use YounitedPaySDK\Request\NewAPI\CancelPaymentRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$body = (new CancelPayment())
        ->setId($younitedContract->payment_id);

$request = new CancelPaymentRequest();

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)
        ->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

BNPL - Split Payment - Added: 2026-02-01
----------------------------------------

[](#bnpl---split-payment---added-2026-02-01)

### New endpoint to get offers with Split Payment BNPL (payment options)

[](#new-endpoint-to-get-offers-with-split-payment-bnpl-payment-options)

[Get new payment options documentation](https://docs.younited.com/pay/index.html?version=2026-02-01#tag/payments/GET/payments/options)

Here is an example with this new request to get 2,3 and 4 split BNPL options and classic loan options (5x to 84x) :

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Model\NewAPI\GetOffers;
use YounitedPaySDK\Request\NewAPI\GetPaymentOptionsRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$body = (new GetOffers())
        ->setShopCode('ONLINE-SHOP-CODE') // New in v2 - shop code needed - see Shop Codes documentation
        ->setAmount(1499.0);

// First possibility: we want only a list of maturities (no range needed)
// New with this endpoint : We can combine Range and list for BNPL options (in example below)
$body->setMaturityList('2,3,4'); // BNPL split payment options

// Other possitiliby: we want a range (eg: from 24 to 84)
$body->setMaturityRangeStep(2)
     ->setMaturityRangeMin(5)
     ->setMaturityRangeMax(84);

$request = (new GetPaymentOptionsRequest())->setModel($body);

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Create a payment

[](#create-a-payment-1)

[Create a payment for BNPL / Loan payment documentation](https://docs.younited.com/pay/index.html?version=2026-02-01#tag/payments/POST/payments)

You can easily initialize a contract by creating a request

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Adapter\PostPaymentAdapter;
use YounitedPaySDK\Model\Address;
use YounitedPaySDK\Model\Basket;
use YounitedPaySDK\Model\BasketItem;
use YounitedPaySDK\Model\InitializeContract;
use YounitedPaySDK\Model\MerchantOrderContext;
use YounitedPaySDK\Model\MerchantUrls;
use YounitedPaySDK\Model\NewAPI\CustomExperience;
use YounitedPaySDK\Model\NewAPI\Request\GetPayment;
use YounitedPaySDK\Model\NewAPI\TechnicalInformation;
use YounitedPaySDK\Model\PersonalInformation;
use YounitedPaySDK\Request\InitializeContractRequest;
use YounitedPaySDK\Request\NewAPI\PostPaymentsRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$datetime = new \DateTime('1970-01-01T00:00:00');

$address = (new Address())
    ->setStreetNumber('123')
    ->setStreetName('StreetName') // 32 caracs max
    ->setAdditionalAddress('') // 32 caracs max
    ->setCity('Country')
    ->setPostalCode('12345')
    ->setCountryCode('FR');

$personalInformation = (new PersonalInformation())
    ->setFirstName('FirstName')
    ->setLastName('LastName')
    ->setGenderCode('MALE')
    ->setEmailAddress('firstname.lastname@mail.com')
    ->setCellPhoneNumber('+33611223344') // Send null if format number is not good (not internationnal or empty)
    ->setBirthDate($datetime) // Warning - must be a valide date see documentation
    ->setAddress($address);

$basketItem1 = (new BasketItem())
    ->setItemName('Item basket 1')
    ->setQuantity(2)
    ->setUnitPrice(45.0);

$basketItem2 = (new BasketItem())
    ->setItemName('Item basket 2')
    ->setQuantity(1)
    ->setUnitPrice(33.0);

$basket = (new Basket())
    ->setBasketAmount(123.0)
    ->setItems([$basketItem1, $basketItem2]);

$merchantUrls = (new MerchantUrls())
    ->setOnApplicationFailedRedirectUrl('on-application-failed-redirect-url.com')
    ->setOnApplicationSucceededRedirectUrl('on-application-succeeded-redirect-url.com')
    ->setOnCanceledWebhookUrl('on-canceled-webhook-url.com')
    ->setOnWithdrawnWebhookUrl('on-withdrawn-webhook-url.com');

$merchantOrderContext = (new MerchantOrderContext())
    ->setChannel('test')
    ->setShopCode('TEST')
    ->setMerchantReference('MerchantReference')
    ->setAgentEmailAddress('merchant@mail.com');

$body = (new InitializeContract())
    ->setRequestedMaturity(10)
    ->setPersonalInformation($personalInformation)
    ->setBasket($basket)
    ->setMerchantUrls($merchantUrls)
    ->setMerchantOrderContext($merchantOrderContext);

$oldRequest = (new InitializeContractRequest())->setModel($body);

// Convert "Old" API calls for new API
// This converter allow you to keep previous code and adapt to your need with new API
$newWebhookUrl = 'new-webhook-url-for-new-api';
$newRedirectUrl = 'new-redirect-url-for-new-api';
// Have new controllers for new URL is recommanded. Only one URL is accepted now for success, cancel and other cases.
// Concerning webhooks, please note that old webhooks will be sent if a contract was done with "old" API.
// So you should keep both use cases. Please note too that webhook format has changes (see end documentation on this point)

$technicalInformation = (new TechnicalInformation())
    ->setWebhookNotificationUrl($webhookUrl)
    ->setApiVersion('2026-02-01'); // See https://docs.younited.com/pay - API Version list and new Request objects

$customExperience = (new CustomExperience())
    ->setCustomerRedirectUrl($redirectUrl);

// New informations here, the amount, installment, type of payment comes now here
$request = (new PostPaymentAdapter())
    ->setShopCode('ONLINE-SHOP-CODE') // New in v2 - shop code needed - see Shop Codes documentation
    // New From 2026-02-01 for BNPL
    ->setType('SplitPayment') // new in BNPL endpoint - PersonalLoan | SplitPayment
    ->setInstallmentCount('SplitPayment') // new in BNPL endpoint - Maturity
    ->setPurchaseAmount('SplitPayment') // new in BNPL endpoint - Maturity
    // END new 2026-02-01 for BNPL
    ->setTechnicalInformation($technicalInformation)
    ->setCustomExperience($customExperience)
    ->convertInitializeContract($oldRequest);

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Get payment status

[](#get-payment-status)

[Get a payment status documentation](https://docs.younited.com/pay/index.html?version=2026-02-01#tag/payments/GET/payments/%7Bid%7D/status)

You can easily load a payment information by creating a request. Please not that now we retrieve the paymentId from contract creation and use it for each calls (instead of contract reference)

```
require 'vendor/autoload.php';

use YounitedPaySDK\Client;
use YounitedPaySDK\Model\NewAPI\GetPaymentStatus;
use YounitedPaySDK\Request\NewAPI\GetPaymentStatusRequest;

$clientId = 'your-client-id';
$clientSecret = 'your-secret-idtoken';

$getPaymentRequestModel = (new GetPaymentStatus())->setId('payment-id');
$request = (new GetPaymentStatusRequest())->setModel($getPaymentRequestModel);

// If we want to set sandbox mode (different credentials than production)
$request = $request->enableSandbox();

$client = new Client();
try {
    $response = $client->setCredential($clientId, $clientSecret)->sendRequest($request);
    echo '';
    echo 'Status Code:';
    var_dump($response->getStatusCode());
    echo 'Reason phrase (for statut code or error):';
    var_dump($response->getReasonPhrase());
    echo 'Response:';
    var_dump($response->getModel());
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

### Get Callback Response to configure Webhook

[](#get-callback-response-to-configure-webhook)

[WebHook client to secure response documentation](https://docs.younited.com/pay/#tag/webhooks)

This new class allow to check if request was signed by Younited Pay with the secret webhook hash provided. Unknown request should not be trusted, and even if you have one response you must call the API to verify the contract status.

```
require 'vendor/autoload.php';

use YounitedPaySDK\Webhook\Webhook;

try {
    $webhook = new Webhook('your-webhook-secret');

    echo '';
    if ($webhook->getErrorResponse() !== false) {
        // The response is not good - we get the reason here
        $error = $webhook->getErrorResponse();
        echo 'Webhook error response :' . $error;
        /** Coul be one of :
         * 400 - Unable to decode content
         * it seems response is not well formatted
         *
         * 401 - No Signature or Datetime header
         * No headers on request (X-YOUNITED-DATETIME or X-YOUNITED-HMACSHA256-SIGNATURE)
         *
         * 401 - Signature or Datetime header empty
         * headers are present but at least one is empty (X-YOUNITED-DATETIME or X-YOUNITED-HMACSHA256-SIGNATURE)
         *
         * 401 - Hash not accepted.
         * This means that your webhook secret do not give the same results that younited made - in most of cases error on secret
         */
    } else {
        // No error and webhook payload is well decoded and secure
        // For order creation you should anyway make a call to the API to check amount and status
        $webhookNotification = $webhook->getEventNotification();
        echo 'Webhook payload:';
        var_dump($webhookNotification->jsonSerialize());
        echo 'Webhook type of notification,:';
        echo $webhookNotification->getType();
        // Do webhook process and refund, cancel or update payment if needed
    }
    echo '';
} catch (Exception $e) {
    echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString());
}
```

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance94

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~96 days

Recently: every ~66 days

Total

16

Last Release

38d ago

Major Versions

1.0.3 → 2.0.02022-11-17

1.0.4 → 2.12023-09-19

1.0.5 → 2.0.12024-06-24

2.0.1 → 3.0-beta2025-07-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/03bf57a620e6b61135a0ae54c1bd5ba24df899b43b5386f7758073b107ba72cc?d=identicon)[202](/maintainers/202)

---

Top Contributors

[![kgleizes](https://avatars.githubusercontent.com/u/98040531?v=4)](https://github.com/kgleizes "kgleizes (77 commits)")[![Afayadas](https://avatars.githubusercontent.com/u/87704690?v=4)](https://github.com/Afayadas "Afayadas (69 commits)")[![clotairer](https://avatars.githubusercontent.com/u/52157233?v=4)](https://github.com/clotairer "clotairer (21 commits)")[![202-ecommerce](https://avatars.githubusercontent.com/u/4932192?v=4)](https://github.com/202-ecommerce "202-ecommerce (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/202ecommerce-younitedpay-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/202ecommerce-younitedpay-sdk/health.svg)](https://phpackages.com/packages/202ecommerce-younitedpay-sdk)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k15](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
