Units you can read in the code.
Use integer grams and millimeters for parcels, and Amount for money. Keep addresses and parcels in typed objects.
Addresses and parcelsAdd Iranian shipping services to your PHP application. Quote, book and track through a shared API, with clear parcel data and carrier-specific capabilities.
composer require eram/ersal:^0.2@betaDEMO-1042ShipmentInterfaceBEFORE THE PARCEL LEAVES
chargeableWeightGrams()Here, the actual weight is greater than the volumetric weight.
use Eram\Ersal\Address\Parcel;
$parcel = new Parcel(
weightGrams: 1500,
lengthMm: 300,
widthMm: 200,
heightMm: 100,
);
$parcel->volumetricWeightGrams(); // 1200
$parcel->chargeableWeightGrams(); // 1500chargeableWeightGrams()The box is still 1.5 kg, but its volume produces a larger calculated weight.
use Eram\Ersal\Address\Parcel;
$parcel = new Parcel(
weightGrams: 1500,
lengthMm: 400,
widthMm: 300,
heightMm: 300,
);
$parcel->volumetricWeightGrams(); // 7200
$parcel->chargeableWeightGrams(); // 7200Calculated by Ersal using its fixed volumetric divisor of 5000. This illustrates the Parcel helper, not a carrier price or guaranteed billing weight. Confirm your carrier’s rules. The buttons reveal recorded PHP output.
FROM CHECKOUT TO TRACKING
A simulated standard-service quote. This is not a current Tipax rate.
use Eram\Ersal\Request\QuoteRequest;
$quotes = $provider->quote(new QuoteRequest(
origin: $origin,
destination: $destination,
parcel: $parcel,
));
$quotes[0]->cost->inToman(); // 85000 (fixture)Store the shipment ID and provider with your order. Booking is confirmed; delivery is still ahead.
bookeduse Eram\Ersal\Request\BookingRequest;
$shipment = $provider->createShipment(new BookingRequest(
origin: $origin,
destination: $destination,
parcel: $parcel,
orderId: 'DEMO-1042',
serviceLevel: $quotes[0]->serviceLevel,
quoteId: $quotes[0]->quoteId,
));
$shipment->getTrackingCode(); // 'DEMO-1042'bookedpicked_upin_transitThe response “on_the_way” becomes in_transit. Call track() to fetch a new snapshot; this is not a live tracking feed.
$tracked = $provider->track($shipment->getId());
$tracked->getStatus()->value; // 'in_transit'
foreach ($tracked->getHistory() as $event) {
$event->at;
$event->status->value;
$event->raw; // original carrier event
}Configure your carrier account on the server. The steps above share these objects; real requests need valid recipient details and your own token.
use Eram\Ersal\Ersal;
use Eram\Ersal\Provider\Tipax\TipaxConfig;
use Eram\Ersal\Address\{Address, Parcel};
$provider = (new Ersal())->create('tipax',
new TipaxConfig(token: $yourToken)
);
// Replace these sample addresses with real order details.
$origin = new Address(
'Demo', 'Shop', '09000000000',
'تهران', 'تهران', 'نشانی نمونه'
);
$destination = new Address(
'Demo', 'Recipient', '09000000000',
'فارس', 'شیراز', 'نشانی نمونه'
);
$parcel = new Parcel(
weightGrams: 1500,
lengthMm: 300, widthMm: 200, heightMm: 100,
);Recorded with Ersal 0.2.0-beta.2 and an in-memory HTTP transport. Prices, addresses and tracking data are fixtures. No carrier is contacted and no shipment is booked on this page.
SEVEN ADAPTERS, DIFFERENT CAPABILITIES
posttipaxchaparmahexamadastCore shipping methods
payganalopeykCapabilities describe interfaces implemented in this library release, not a guarantee about a carrier account or current API access. Check the provider guide and test against your contracted service.
Use integer grams and millimeters for parcels, and Amount for money. Keep addresses and parcels in typed objects.
Addresses and parcelsInject an HTTP client, logger or event dispatcher. Use the library in plain PHP or your existing framework.
HTTP and loggingYour application stores shipments and schedules polling. Ersal returns the status and history; webhook parsing is not built in.
Tracking guideInstall the beta, configure one carrier, and test a complete shipping flow with your account before using it for customer orders.