### Install dependencies in development environment Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Install dependencies in a development environment. ```bash composer update ``` -------------------------------- ### Get eligible offers with GetOffersRequest Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Get eligible offers by setting a shop code and amount, then either a maturity list or a maturity range. The example shows both possibilities: setMaturityList('24,36') or setMaturityRangeStep/Min/Max. Requires a shop code (new in v3) and client credentials; sandbox mode is optional. ```php 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()); } ``` -------------------------------- ### Install dependencies for PHP 5.6 or production Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Install dependencies for PHP 5.6 or production mode, ignoring platform requirements and skipping dev dependencies. ```bash composer update --ignore-platform-reqs --no-dev ``` -------------------------------- ### Create a payment with YounitedPay SDK (PostPaymentAdapter) Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Complete example for creating a BNPL/Loan payment using the YounitedPay SDK. It builds an InitializeContract with personal information, basket, merchant URLs, and order context, then converts it to the new API via PostPaymentAdapter, optionally enables sandbox mode, and sends the request with Client. Note the comments about required shop code, API version, and the new BNPL fields (type, installmentCount, purchaseAmount) for 2026-02-01. ```php 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 with GetPaymentStatusRequest Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Loads a payment status by creating a GetPaymentStatus request with the payment ID obtained from contract creation. Optionally enables sandbox mode with different credentials. Prints the status code, reason phrase, and response model, or the exception details on failure. ```php 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 BNPL split payment options with GetPaymentOptionsRequest Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Gets payment options for BNPL split payment (2, 3, and 4 splits) and classic loan options (5x to 84x) using GetPaymentOptionsRequest. Requires a shop code and amount; can set a maturity list or a maturity range. Enables sandbox mode and prints the response details. ```php 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()); } ``` -------------------------------- ### Get available maturities with GetOffersRequest in PHP Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Creates a GetOffers request with a maturity range from 1 to 84 months to retrieve all available maturities. Requires a shop code (ONLINE-SHOP-CODE) and client credentials; sandbox mode can be enabled with enableSandbox(). The response model is iterated to build a unique maturity list, though the sort uses an undefined $validOffers variable. ```php 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()); } ``` -------------------------------- ### Get Payment Options Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Retrieves payment options for BNPL split payment and classic loan options. ```APIDOC ## Get Payment Options ### Description Retrieves payment options for BNPL split payment and classic loan options. ### Method POST ### Endpoint /get-payment-options ### Parameters #### Request Body - **shopCode** (string) - Required - The shop code for the online shop. - **amount** (float) - Required - The amount for which payment options are requested. - **maturityList** (string) - Optional - Comma-separated list of maturities for BNPL split payment options (e.g., '2,3,4'). - **maturityRangeStep** (int) - Optional - Step for maturity range. - **maturityRangeMin** (int) - Optional - Minimum maturity for range. - **maturityRangeMax** (int) - Optional - Maximum maturity for range. ### Request Example ```php $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()); } ``` ### Response #### Success Response (200) - **statusCode** (int) - HTTP status code. - **reasonPhrase** (string) - Reason phrase for status code or error. - **model** (object) - Response model containing payment options. #### Response Example ```php $response->getStatusCode(); $response->getReasonPhrase(); $response->getModel(); ``` ``` -------------------------------- ### Get shop codes with ShopsRequest Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Retrieve shop codes for a merchant using the ShopsRequest. Requires client credentials and optionally enables sandbox mode. The response model contains shop codes; the code extracts name and code pairs. Note that the code, not the name, is needed for API calls. ```php 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 '
'; } ``` -------------------------------- ### Create a payment with YounitedPay SDK PHP Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Initializes a contract by building an InitializeContract model, converting it to the new API with CreatePaymentAdapter, optionally enabling sandbox mode, and sending the request with Client. Requires valid client credentials and shop code; note that webhook URLs and formats differ between old and new API. ```php 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 payment with GetPaymentRequest Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Loads payment information by creating a GetPaymentRequest with a payment ID. Uses the paymentId retrieved from contract creation instead of the contract reference. Optionally enables sandbox mode and prints the status code, reason phrase, and response model. ```php 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()); } ``` -------------------------------- ### Execute payment with ExecutePaymentRequest Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Executes a payment by creating an ExecutePaymentRequest with a payment ID. Optionally enables sandbox mode and prints the status code, reason phrase, and response model. ```php 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()); } ``` -------------------------------- ### Refund payment with RefundPaymentRequest Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Refunds a payment (totally or partially) by creating a RefundPaymentRequest. Sets the payment ID, amount as a float, and an idempotency key. Optionally enables sandbox mode and prints the status code, reason phrase, and response model. ```php 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()); } ``` -------------------------------- ### Verify webhook signature with Webhook class Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Verifies that an incoming webhook request was signed by Younited Pay using the provided secret webhook hash. On error, prints the error response with possible causes (400 decode failure, 401 missing/empty headers, 401 hash not accepted). On success, prints the decoded payload and notification type; still call the API to confirm contract status. ```php 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()); } ``` -------------------------------- ### Cancel a payment with CancelPaymentRequest Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Cancels a payment by creating a CancelPaymentRequest with the payment ID from the contract. Enables sandbox mode before sending the request and prints the status code, reason phrase, and response model. ```php 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()); } ``` -------------------------------- ### Cancel Payment Source: https://github.com/younitedcredit/younitedpay-sdk-php/blob/develop/README.md Cancels a payment by creating a request with the payment ID. ```APIDOC ## Cancel Payment ### Description Cancels a payment by creating a request with the payment ID. ### Method POST ### Endpoint /cancel-payment ### Parameters #### Request Body - **id** (string) - Required - The payment ID of the contract to cancel. ### Request Example ```php $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()); } ``` ### Response #### Success Response (200) - **statusCode** (int) - HTTP status code. - **reasonPhrase** (string) - Reason phrase for status code or error. - **model** (object) - Response model containing cancellation details. #### Response Example ```php $response->getStatusCode(); $response->getReasonPhrase(); $response->getModel(); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.