PHP library for Royal Mail shipping shipping methods
This repository contains the source code for the Meanbee Royal Mail PHP Library. It takes the country code, package value, and package weight and then outputs an array of objects containing the available shipping methods.
To use the library, call the getMethods method with your country code (in the ISO 3166 format), package value, and package weight.
$calculateMethodClass = new CalculateMethodClass(); $calculateMethodClass->getMethods('GB', 20, 0.050);
This will return an array of objects where each object contains the shipping method name, minimum weight, maximum weight, price of the method, maximum insurance value, and proper name of the shipping method.
This program is automatically unit tested with phpunit and travis.
This library uses six CSV files to determine which shipping methods are available:
- Country code
- World zone. Each country, defined by its country code can be in more then one zone. The code "GB" for Great Britain is in the EU and the GB World zone. There are four world zones:
- World zone
- Shipping zone.
Each shipping method's name starts with the world zone it links to as prices differ between zones.
- Delivery method
- Minimum price of method
- Maximum price available to the method (the maximum price of shipping cart this method applies to)
- Max insurance available on method
- Human-friendly method name
- Delivery group
- Method name
- Minimum weight
- Maximum weight
- Price of method
- Max insurance value
- In the case of small or medium parcel up to 2kg in weight "SMALL" or "MEDIUM" else blank
Method names are constructed in the WORLDZONE_NAME_WITH_UNDERSCORES format with a separate method being added for each separate foramt. Examples of these can be seen in multiple of the csvs. In the case of extra insurance available on the item, another method must be created. An example can be seen in the 3_deliveryMethodMeta.csv.