PHP code example of 202ecommerce / younitedpay-sdk
1. Go to this page and download the library: Download 202ecommerce/younitedpay-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
202ecommerce / younitedpay-sdk example snippets
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());
}
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);
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());
}
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();
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());
}
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);
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('[email protected] ')
->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('[email protected] ');
$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());
}
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('[email protected] ')
->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('[email protected] ');
$client = (new Client())
->setCredential($clientId, $clientSecret);
$response = (new ClientApiService($client))
->enableTest()
->initializeContract($requestMaturity, $personalInformation, $basket, $merchantUrls, $merchantOrderContext);
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());
}
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);
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());
}
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);
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());
}
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);
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());
}
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);
use YounitedPaySDK\Client;
use YounitedPaySDK\Service\ClientApiService;
$response = (new Client())->retrieveCallbackResponse();
// Do webhook process