Coder Social home page Coder Social logo

php-mondialrelay-webservice's Introduction

PHP Mondialrelay Webservice

An expressive, fluent interface to Mondial Relay's shipping services.

Installation

Install using Composer :

$ composer require cba85/php-mondialrelay-webservice

Note: you must have PHP with Soap enabled.

Getting started

<?php

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

// 1. 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"}]}}

Usage

Webservice

You must obtain Mondial Relay credentials to use the webservice.

You could use Mondial Relay test credentials to try the webservice:

  • Enseigne (merchant): BDTEST13
  • Private key: PrivateK

Available methods

Method name Webservice method name
searchPostcode() WSI2_RechercheCP
searchPostcode() WSI2_RechercheCP
statLabel() WSI2_STAT_Label
searchParcelshop() WSI4_PointRelais_Recherche
createLabel() WSI2_CreationEtiquette
createShipping() WSI2_CreationExpedition
getLabels() WSI3_GetEtiquettes
trackParcel() WSI2_TracingColisDetaille

Results

You can retrieve webservice results as a PHP StdClass Object or in Json format.

$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();

Last method call

You could retrieve the results, parameters or call another request of the webservice using method attribute that contains the last method call:

$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

Parameters

The parameters you pass throught the method are automatically checked based on Mondial Relay regex patterns.

Postal code parameters and phone numbers parameters are automatically checked depending the country parameter they depends on.

Get setted parameters

You can check the setted parameters of the last method you called using:

$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);

Get error parameters

If at least one of your parameter doesn't match its regex patterns during the parameters checking, an exception will be thrown to prevent useless webservice call.

You could retrieve these errors:

$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
)
*/

Documentation

Tests

$ ./vendor/bin/phpunit --bootstrap vendor/autoload.php

If you want to test something specific, just add the filename you want to test.

Example:

$ ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/WebserviceTest.php

php-mondialrelay-webservice's People

Contributors

cba85 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

php-mondialrelay-webservice's Issues

Info doc for functions

Hi, what are the parameters for the functions: createLabel () and createShipping () if we use the widget for the selection of a relay point (we therefore receive a Selected Point Relais code: BE-010270)

Best regards

Fatal error with belgiums params

Hi, I tested your scripts with France without any problem, but the tests with Belgium returns a fatal error.

Fatal error: Uncaught MondialRelay\Exceptions\ParameterException: Bad parameters. in /mondialrelay/php-mondialrelay-webservice-master/src/Traits/Method.php on line 43

$parameters = [
    'ModeCol' => 'REL',
    'ModeLiv' => '24R',
    'Expe_Langage' => 'FR',
    'Expe_Ad1' => 'The sender',
    'Expe_Ad3' => "Sender street",
    'Expe_Ville' => "Huy",
    'Expe_CP' => "4500",
    'Expe_Pays' => "BE",
    'Expe_Tel1' => "+33698765432",
    'Dest_Langage' => 'FR',
    'Dest_Ad1' => "The sender",
    'Dest_Ad3' => "Receiver street",
    'Dest_Ville' => "Huy",
    'Dest_CP' => "4500",
    'Dest_Pays' => "FR",
    'Dest_Tel1' => "+33698765432",
    'Poids' => "400",
    'NbColis' => "1",
    'COL_Rel_Pays' => "BE",
    'COL_Rel' => "040008",
    'CRT_Valeur' => "20",
    'LIV_Rel_Pays' => "BE",
    'LIV_Rel' => "040008",
];
$createShipping = $mondialrelay->createShipping($parameters)->getResults();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.