202ecommerce / younitedpay-sdk
younited pay API SDK
Requires
- ext-curl: *
- ext-json: *
- psr/cache: ^3.0.0
- psr/http-client: ^1.0
- psr/http-message: ^2.0
- psr/log: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- phpstan/phpstan: ^0.12.81
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-11-24 09:52:51 UTC
README
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
This package is compatible with PHP 5.6+.
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
How to try this SDK ?
Get Younited Pay eligible offers, per maturities
You can easily get list of offer by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Request\BestPriceRequest; use YounitedPaySDK\Model\BestPrice; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $body = (new BestPrice()) ->setBorrowedAmount(149.0); $request = (new BestPriceRequest()) ->setModel($body) ->enableSandbox(); $client = new Client(); try { $response = $client->setCredential($clientId, $clientSecret) ->sendRequest($request); echo '<pre>'; echo 'Status Code:<br />'; var_dump($response->getStatusCode()); echo '<br />Reason phrase (for statut code or error):<br />'; var_dump($response->getReasonPhrase()); echo 'Response:<br />'; var_dump($response->getModel()); echo '</pre>'; } catch (Exception $e) { echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString()); }
You can also use the client api service to get list of offer
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Service\ClientApiService; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $borrowedAmount = 149.0; $client = (new Client()) ->setCredential($clientId, $clientSecret); $response = (new ClientApiService($client)) ->enableTest() ->getBestPrice($borrowedAmount);
Get Available Maturities
Get available maturities documentation
You can easily get available maturities by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Request\AvailableMaturitiesRequest; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $request = (new AvailableMaturitiesRequest()) ->enableSandbox() $client = new Client(); try { $response = $client->setCredential($clientId, $clientSecret) ->sendRequest($request); echo '<pre>'; echo 'Status Code:<br />'; var_dump($response->getStatusCode()); echo '<br />Reason phrase (for statut code or error):<br />'; var_dump($response->getReasonPhrase()); echo 'Response:<br />'; var_dump($response->getModel()); echo '</pre>'; } catch (Exception $e) { echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString()); }
You can also use the client api service to get available maturities
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Service\ClientApiService; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $contractReference = 'contract-reference'; $client = (new Client()) ->setCredential($clientId, $clientSecret); $response = (new ClientApiService($client)) ->enableTest() ->getAvailableMaturities();
Load Contract
You can easily load a contract by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Request\LoadContractRequest; use YounitedPaySDK\Model\LoadContract; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $body = (new LoadContract()) ->setContractReference('contract-ref'); $request = (new LoadContractRequest()) ->setModel($body) ->enableSandbox(); $client = new Client(); try { $response = $client->setCredential($clientId, $clientSecret) ->sendRequest($request); echo '<pre>'; echo 'Status Code:<br />'; var_dump($response->getStatusCode()); echo '<br />Reason phrase (for statut code or error):<br />'; var_dump($response->getReasonPhrase()); echo 'Response:<br />'; var_dump($response->getModel()); echo '</pre>'; } catch (Exception $e) { echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString()); }
You can also use the client api service to load a contract
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Service\ClientApiService; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $contractReference = 'contract-reference'; $client = (new Client()) ->setCredential($clientId, $clientSecret); $response = (new ClientApiService($client)) ->enableTest() ->loadContract($contractReference);
Initialize a contract
Initialize a contract documentation
You can easily initialize a contract by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Request\InitializeContractRequest; use YounitedPaySDK\Model\Address; use YounitedPaySDK\Model\PersonalInformation; use YounitedPaySDK\Model\BasketItem; use YounitedPaySDK\Model\Basket; use YounitedPaySDK\Model\MerchantUrls; use YounitedPaySDK\Model\MerchantOrderContext; use YounitedPaySDK\Model\InitializeContract; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $datetime = new \DateTime('1970-01-01T00:00:00'); $address = (new Address()) ->setStreetNumber('123') ->setStreetName('StreetName') ->setAdditionalAddress('') ->setCity('Country') ->setPostalCode('12345') ->setCountryCode('FR'); $personalInformation = (new PersonalInformation()) ->setFirstName('FirstName') ->setLastName('LastName') ->setGenderCode('MALE') ->setEmailAddress('firstname.lastname@mail.com') ->setCellPhoneNumber('33611223344') ->setBirthDate($datetime) ->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); $request = (new InitializeContractRequest()) ->setModel($body) ->enableSandbox(); $client = new Client(); try { $response = $client->setCredential($clientId, $clientSecret) ->sendRequest($request); echo '<pre>'; echo 'Status Code:<br />'; var_dump($response->getStatusCode()); echo '<br />Reason phrase (for statut code or error):<br />'; var_dump($response->getReasonPhrase()); echo 'Response:<br />'; var_dump($response->getModel()); echo '</pre>'; } catch (Exception $e) { echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString()); }
You can also use the client api service to initialize a contract
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Model\Address; use YounitedPaySDK\Model\PersonalInformation; use YounitedPaySDK\Model\BasketItem; use YounitedPaySDK\Model\Basket; use YounitedPaySDK\Model\MerchantUrls; use YounitedPaySDK\Model\MerchantOrderContext; use YounitedPaySDK\Service\ClientApiService; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $requestedMaturity = 10; $datetime = new \DateTime('1970-01-01T00:00:00'); $address = (new Address()) ->setStreetNumber('123') ->setStreetName('StreetName') ->setAdditionalAddress('') ->setCity('Country') ->setPostalCode('12345') ->setCountryCode('FR'); $personalInformation = (new PersonalInformation()) ->setFirstName('FirstName') ->setLastName('LastName') ->setGenderCode('MALE') ->setEmailAddress('firstname.lastname@mail.com') ->setCellPhoneNumber('33611223344') ->setBirthDate($datetime) ->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'); $client = (new Client()) ->setCredential($clientId, $clientSecret); $response = (new ClientApiService($client)) ->enableTest() ->initializeContract($requestMaturity, $personalInformation, $basket, $merchantUrls, $merchantOrderContext);
Confirm Contract
Confirm a contract documentation
You can easily confirm a contract by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Request\ConfirmContractRequest; use YounitedPaySDK\Model\ConfirmContract; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $body = (new ConfirmContract()) ->setContractReference('contract-ref') ->setMerchantOrderId('order-id'); $request = (new ConfirmContractRequest()) ->setModel($body) ->enableSandbox(); $client = new Client(); try { $response = $client->setCredential($clientId, $clientSecret) ->sendRequest($request); echo '<pre>'; echo 'Status Code:<br />'; var_dump($response->getStatusCode()); echo '<br />Reason phrase (for statut code or error):<br />'; var_dump($response->getReasonPhrase()); echo 'Response:<br />'; var_dump($response->getModel()); echo '</pre>'; } catch (Exception $e) { echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString()); }
You can also use the client api service to confirm a contract
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Service\ClientApiService; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $contractReference = 'contract-reference'; $merchantOrderId = 'merchant-order_id'; $client = (new Client()) ->setCredential($clientId, $clientSecret); $response = (new ClientApiService($client)) ->enableTest() ->confirmContract($contractReference, $merchantOrderId = null);
Activate Contract
Activate a contract documentation
You can easily activate a contract by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Request\ActivateContractRequest; use YounitedPaySDK\Model\ActivateContract; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $body = (new ActivateContract()) ->setContractReference('contract-ref'); $request = (new ActivateContractRequest()) ->setModel($body) ->enableSandbox(); $client = new Client(); try { $response = $client->setCredential($clientId, $clientSecret) ->sendRequest($request); echo '<pre>'; echo 'Status Code:<br />'; var_dump($response->getStatusCode()); echo '<br />Reason phrase (for statut code or error):<br />'; var_dump($response->getReasonPhrase()); echo 'Response:<br />'; var_dump($response->getModel()); echo '</pre>'; } catch (Exception $e) { echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString()); }
You can also use the client api service to activate a contract
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Service\ClientApiService; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $contractReference = 'contract-reference'; $client = (new Client()) ->setCredential($clientId, $clientSecret); $response = (new ClientApiService($client)) ->enableTest() ->activateContract($contractReference);
Withdraw Contract
Withdraw a contract documentation
You can easily withdraw a contract by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Request\WithdrawContractRequest; use YounitedPaySDK\Model\WithdrawContract; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $body = (new WithdrawContract()) ->setContractReference('contract-ref') ->setAmount(149.0); $request = (new WithdrawContractRequest()) ->setModel($body) ->enableSandbox(); $client = new Client(); try { $response = $client->setCredential($clientId, $clientSecret) ->sendRequest($request); echo '<pre>'; echo 'Status Code:<br />'; var_dump($response->getStatusCode()); echo '<br />Reason phrase (for statut code or error):<br />'; var_dump($response->getReasonPhrase()); echo 'Response:<br />'; var_dump($response->getModel()); echo '</pre>'; } catch (Exception $e) { echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString()); }
You can also use the client api service to withdraw a contract
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Service\ClientApiService; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $contractReference = 'contract-reference'; $amount = '149.0'; $client = (new Client()) ->setCredential($clientId, $clientSecret); $response = (new ClientApiService($client)) ->enableTest() ->withdrawContract($contractReference, $amount);
Cancel Contract
Cancel a contract documentation
You can easily cancel a contract by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Request\CancelContractRequest; use YounitedPaySDK\Model\CancelContract; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $body = (new CancelContract()) ->setContractReference('contract-ref'); $request = (new CancelContractRequest()) ->setModel($body) ->enableSandbox(); $client = new Client(); try { $response = $client->setCredential($clientId, $clientSecret) ->sendRequest($request); echo '<pre>'; echo 'Status Code:<br />'; var_dump($response->getStatusCode()); echo '<br />Reason phrase (for statut code or error):<br />'; var_dump($response->getReasonPhrase()); echo 'Response:<br />'; var_dump($response->getModel()); echo '</pre>'; } catch (Exception $e) { echo ($e->getMessage() . $e->getFile() . ':' . $e->getLine(). $e->getTraceAsString()); }
You can also use the client api service to cancel a contract
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Service\ClientApiService; $clientId = 'your-client-id'; $clientSecret = 'your-secret-idtoken'; $contractReference = 'contract-reference'; $client = (new Client()) ->setCredential($clientId, $clientSecret); $response = (new ClientApiService($client)) ->enableTest() ->cancelContract($contractReference);
Get Callback Response to configure Webhook
Get callback response documentation
You can easily get available maturities by creating a request
require 'vendor/autoload.php'; use YounitedPaySDK\Client; use YounitedPaySDK\Service\ClientApiService; $response = (new Client())->retrieveCallbackResponse(); // Do webhook process