PHP code example of qhayat / php-mondialrelay-webservice
1. Go to this page and download the library: Download qhayat/php-mondialrelay-webservice 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/ */
qhayat / php-mondialrelay-webservice example snippets
Initialize Mondial Relay webservice with your credentials.
$mondialrelay = new Webservice('BDTEST13', 'PrivateK');
// 2. Create parameters for the method you want to use.
$parameters = [
'Pays' => 'FR',
'Ville' => 'Paris',
'NbResult' => 5
];
// 3. Call the method using your parameters and get the results in json format
$searchPostcode = $mondialrelay->searchPostcode($parameters)->getResultsInJson();
// {"STAT":"0","Liste":{"Commune":[{"CP":"75001","Ville":"PARIS","Pays":"FR"},{"CP":"75002","Ville":"PARIS","Pays":"FR"},{"CP":"75003","Ville":"PARIS","Pays":"FR"},{"CP":"75004","Ville":"PARIS","Pays":"FR"},{"CP":"75005","Ville":"PARIS","Pays":"FR"}]}}
$mondialrelay = new Webservice('BDTEST13', 'PrivateK');
// E.g. Call a method
$parameters = [...]; // Parameters of the method
// PHP StdClass object results
$searchParcelshop = $mondialrelay->searchParcelshop($parameters)->getResults();
// Json results
$searchParcelshop = $mondialrelay->searchParcelshop($parameters)->getResultsInJson();
$mondialrelay = new Webservice('BDTEST13', 'PrivateK');
// E.g. Call a method
$parameters = [...]; // Parameters of the method
$searchParcelshop = $mondialrelay->searchParcelshop($parameters)->getResults();
$mondialrelay->method->parameters; // Get last method called parameters
$mondialrelay->method->results; // Get last method called results
$mondialrelay->method->request()->results(); // Create another request using last method and parameters called and get the results
$mondialrelay = new Webservice('BDTEST13', 'PrivateK');
// E.g. Call a method
$parameters = [...]; // Parameters of the method
$searchParcelshop = $mondialrelay->searchParcelshop($parameters)->getResults();
print_r($mondialrelay->method->parameters);
$mondialrelay = new Webservice('BDTEST13', 'PrivateK');
// E.g. Call a method
$parameters = ['Pays' => "FRA"]; // Parameters of the method with at least a bad parameter
// Display parameters with error
try {
$searchParcelshop = $mondialrelay->searchParcelshop($parameters)->getResults();
} catch (Exception $e) {
print_r($mondialrelay->method->parameter->getErrors());
}
/*
Array
(
[Pays] => FRA
)
*/