Skip to content
Stefan Nesbitt edited this page Oct 14, 2015 · 11 revisions

Basic Usage

All interaction with the API module is done via the RoyalMail class. By default it operates in a 'fake it while you make it' development mode, with no live contact made with the Royal Mail API server.

The responses returned are from the sample files provided by RM and don't change according to the request parameters submitted.

The request parameters are validated, however, and parsed against the WSDL to verify they fit the required schema.

Additionally there is a development helper module which (so far) provides valid request parameter arrays to allow easy access to all the available responses.

Development example

Code available as a PHPUnit test in ~/examples/BasicUsageTest.php

    // Create an instance of the main entry/dispatcher class.
    $interface  = new \RoyalMail\RoyalMail;

    // Get a copy of the development helper utility.
    $dev_helper = $interface->getDevelopmentHelper();

    // Valid parameters for the action given. 
    // Currently available for actions listed in ~/tests/resources/requests
    $req_params = $dev_helper->getSampleRequest('cancelShipment');

    // "Send" the request and return the interpreted response. 
    // In development mode this just loads the RM supplied
    // sample XML for the given action (files in ~reference/responses)
    $response = $interface->cancelShipment($req_params);

    // Will display RQ221150275GB
    echo $response['cancelled_shipments'][0] . "\n"; 
Clone this wiki locally