فهرست مستندات پروژه
ماهکس (Mahex)
شرکت حمل داخلی. REST API. پشتیبانی از pickup و پسکرایه.
پیکربندی
use Eram\Ersal\Provider\Mahex\MahexConfig;
$config = new MahexConfig(
token: 'your-bearer-token',
sandbox: false,
baseUrl: null,
);
قابلیتها
| رابط | پشتیبانی |
|---|---|
ShippingInterface | ✅ |
SupportsPickup | ✅ |
SupportsCOD | ✅ |
SupportsLabel | ❌ |
SupportsBranches | ❌ |
راهاندازی
use Eram\Ersal\Ersal;
use Eram\Ersal\Provider\Mahex\MahexConfig;
$mahex = (new Ersal())->create('mahex', new MahexConfig(token: 'your-token'));
ماهکس از هدر Authorization: Bearer <token> استفاده میکند.
quote()
use Eram\Ersal\Address\Parcel;
use Eram\Ersal\Request\QuoteRequest;
$quotes = $mahex->quote(new QuoteRequest(
origin: $origin, destination: $destination,
parcel: new Parcel(weightGrams: 2500),
));
foreach ($quotes as $quote) {
echo "{$quote->serviceLevel}: {$quote->cost->inToman()} تومان\n";
}
createShipment()
use Eram\Ersal\Request\BookingRequest;
$shipment = $mahex->createShipment(new BookingRequest(
origin: $origin, destination: $destination, parcel: $parcel,
orderId: 'ORDER-MHX-001',
serviceLevel: 'standard',
));
پسکرایه
use Eram\Ersal\Contracts\SupportsCOD;
use Eram\Ersal\Money\Amount;
if ($mahex instanceof SupportsCOD) {
$booking = (new BookingRequest(
origin: $origin, destination: $destination, parcel: $parcel,
orderId: 'ORDER-MHX-COD-001',
))->withCashOnDelivery(Amount::fromToman(800_000));
$shipment = $mahex->createShipment($booking);
}
track()
$tracked = $mahex->track($shipment->getId());
echo $tracked->getStatus()->label('fa');
cancel()
$cancelled = $mahex->cancel($shipment->getId());
schedulePickup()
use Eram\Ersal\Contracts\SupportsPickup;
use Eram\Ersal\Request\PickupRequest;
if ($mahex instanceof SupportsPickup) {
$mahex->schedulePickup($shipment->getId(), new PickupRequest(
windowStart: new DateTimeImmutable('tomorrow 14:00'),
windowEnd: new DateTimeImmutable('tomorrow 16:00'),
instructions: 'قبل از حرکت تماس بگیرید',
));
}
مدیریت خطا
use Eram\Ersal\Exception\ProviderException;
use Eram\Ersal\Provider\Mahex\MahexErrorCode;
try {
$mahex->createShipment($booking);
} catch (ProviderException $e) {
$code = MahexErrorCode::tryFrom((int) $e->getErrorCode());
echo $code?->message('fa') ?? $e->getMessage();
}
نکات
- اگر به برچسب چاپی نیاز دارید، از تیپاکس یا چاپار استفاده کنید
- فیلدهای فعلی را با مستندات توسعهدهنده ماهکس تایید کنید
⁅شرکت حمل داخلی rest api پشتیبانی از pickup و پسکرایه پس کرایه use eram ersal provider mahex mahexconfig config new mahexconfig token your bearer token sandbox false baseurl null رابط پشتیبانی shippinginterface supportspickup supportscod supportslabel supportsbranches use eram ersal ersal use eram ersal provider mahex mahexconfig mahex new ersal create mahex new mahexconfig token your token ماهکس از هدر authorization bearer token استفاد کرد use eram ersal address parcel use eram ersal request quoterequest quotes mahex quote new quoterequest origin origin destination destination parcel new parcel weightgrams 2500 foreach quotes as quote echo quote servicelevel quote cost intoman توم n use eram ersal request bookingrequest shipment mahex createshipment new bookingrequest origin origin destination destination parcel parcel orderid order mhx 001 servicelevel standard use eram ersal contracts supportscod use eram ersal money amount if mahex instanceof supportscod booking new bookingrequest origin origin destination destination parcel parcel orderid order mhx cod 001 withcashondelivery amount fromtoman 800 000 shipment mahex createshipment booking tracked mahex track shipment getid echo tracked getstatus label fa cancelled mahex cancel shipment getid use eram ersal contracts supportspickup use eram ersal request pickuprequest if mahex instanceof supportspickup mahex schedulepickup shipment getid new pickuprequest windowstart new datetimeimmutable tomorrow 14 00 windowend new datetimeimmutable tomorrow 16 00 instructions قبل از حرکت تماس گرفت use eram ersal exception providerexception use eram ersal provider mahex mahexerrorcode try mahex createshipment booking catch providerexception e code mahexerrorcode tryfrom int e geterrorcode echo code message fa e getmessage اگر به برچسب چاپی نیاز داشت از تیپاکس یا چاپار استفاد کرد فیلد فعلی را با مستند توسعهد توسعه دهنده ماهکس تای کرد⁆
⁅ماهکس mahex⁆
⁅پیکربندیقابلیتهاراهاندازیquote پیکربندیقابلیت هاراه اندازیquote createshipment پسکرایهtrack پس کرایهtrack cancel schedulepickup مدیریت خطانک⁆