Download the PHP package rairlie/postage-calculator without Composer
On this page you can find all versions of the php package rairlie/postage-calculator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download rairlie/postage-calculator
More information about rairlie/postage-calculator
Files in rairlie/postage-calculator
Download rairlie/postage-calculator
More information about rairlie/postage-calculator
Files in rairlie/postage-calculator
Vendor rairlie
Package postage-calculator
Short Description Calculate postage costs for a parcel
License MIT
Package postage-calculator
Short Description Calculate postage costs for a parcel
License MIT
Keywords calculatorpostage
Please rate this library. Is it a good library?
Informations about the package postage-calculator
postage-calculator
Calculates price for UK postal services
Requires
PHP 7.0+
Installation
$ composer require rairlie/postage-calculator
Usage
use Rairlie\PostageCalculator\PostageCalculator;
use Rairlie\PostageCalculator\ParcelForce;
// Calculate postage for a Royal Mail parcel
$postageCalculator = new PostageCalculator();
$price = $postageCalculator
->getService(PostageCalculator::SERVICE_ROYAL_MAIL)
->getPrice(
450, // Weight in grams
[10, 22, 8] // Dimensions in cm - length, width, depth
);
// Calculate postage for a Parcelforce parcel
$price = $postageCalculator
->getService(PostageCalculator::SERVICE_PARCELFORCE_24)
->getPrice(
450, // Weight in grams
ParcelForce::METHOD_DROP_POST_OFFICE
);
Parcelforce parcels can be sent by four methods:
- ParcelForce::METHOD_COLLECT - Parcel to be collected from a pick-up address
- ParcelForce::METHOD_DROP_POST_OFFICE - Parcel to be dropped at a PostOffice
- ParcelForce::METHOD_DROP_DEPOT - Parcel to be dropped at a depot
- ParcelForce::METHOD_DEPOT_TO_DEPOT - Parcel to be dropped at and collected from a depot
Configuration
The prices are derived from configuration files in src/Defaults:
src/Defaults/RoyalMail.php
src/Defaults/ParcelForce24.php
src/Defaults/ParcelForce48.php
The format should be fairly self-explanatory, and prices are correct as of January 2018. If you need to customise them, for example to load them from a DB or to facilitate unit testing, you can pass your own price configs into the constructor:
$postageCalculator = new PostageCalculator([
PostageCalculator::SERVICE_ROYAL_MAIL => $myRoyalMailPrices,
PostageCalculator::SERVICE_PARCELFORCE_24 => $myParcelForce24Prices,
PostageCalculator::SERVICE_PARCELFORCE_48 => $myParcelForce48Prices,
]);
Exceptions
The following exceptions may be thrown:
- ParcelTooHeavyException - the parcel is too heavy to send with the service
- ParcelTooLargeException - the parcel is too large (dimensions) to send with the service
- MethodUnavailableException - its not possible to use the specified delivery method to send this parcel (Parcelforce only)
All versions of postage-calculator with dependencies
PHP Build Version
Package Version
Requires
php Version
>=7.0.0
The package rairlie/postage-calculator contains the following files
Loading the files please wait ....