فهرست مستندات پروژه
چاپار (Chapar Express)
شرکت حمل خصوصی. REST API. پشتیبانی از برچسب، pickup و پسکرایه.
پیکربندی
use Eram\Ersal\Provider\Chapar\ChaparConfig;
$config = new ChaparConfig(
apiKey: 'your-api-key',
sandbox: false,
baseUrl: null,
);
| پارامتر | نوع | اجباری | پیشفرض | توضیح |
|---|---|---|---|---|
apiKey | string | بله | — | کلید API از پرتال چاپار |
sandbox | bool | خیر | false | محیط تست |
baseUrl | ?string | خیر | null | بازنویسی آدرس API |
قابلیتها
| رابط | پشتیبانی |
|---|---|
ShippingInterface | ✅ |
SupportsLabel | ✅ |
SupportsPickup | ✅ |
SupportsCOD | ✅ |
SupportsBranches | ❌ |
راهاندازی
use Eram\Ersal\Ersal;
use Eram\Ersal\Provider\Chapar\ChaparConfig;
$chapar = (new Ersal())->create('chapar', new ChaparConfig(apiKey: 'your-key'));
چاپار از هدر X-Api-Key استفاده میکند.
quote()
use Eram\Ersal\Address\Parcel;
use Eram\Ersal\Request\QuoteRequest;
$quotes = $chapar->quote(new QuoteRequest(
origin: $origin, destination: $destination,
parcel: new Parcel(weightGrams: 1000, lengthMm: 200, widthMm: 150, heightMm: 80),
));
foreach ($quotes as $quote) {
printf("%s — %s تومان، تحویل %s روز\n",
$quote->serviceLevel, $quote->cost->inToman(), $quote->etaDays);
}
createShipment()
use Eram\Ersal\Request\BookingRequest;
$shipment = $chapar->createShipment(new BookingRequest(
origin: $origin, destination: $destination, parcel: $parcel,
orderId: 'ORDER-CHP-001',
serviceLevel: 'standard',
quoteId: $quotes[0]->quoteId,
description: 'وسایل الکترونیکی',
));
پسکرایه
use Eram\Ersal\Contracts\SupportsCOD;
use Eram\Ersal\Money\Amount;
if ($chapar instanceof SupportsCOD) {
$booking = (new BookingRequest(
origin: $origin, destination: $destination, parcel: $parcel,
orderId: 'ORDER-CHP-COD-001',
))->withCashOnDelivery(Amount::fromToman(1_200_000));
$shipment = $chapar->createShipment($booking);
}
track()
$tracked = $chapar->track($shipment->getId());
foreach ($tracked->getHistory() as $event) {
printf("[%s] %s\n", $event->at->format('Y-m-d H:i'), $event->description);
}
cancel()
$cancelled = $chapar->cancel($shipment->getId());
getLabel()
use Eram\Ersal\Contracts\SupportsLabel;
if ($chapar instanceof SupportsLabel) {
$label = $chapar->getLabel($shipment->getId());
file_put_contents("chapar-{$shipment->getId()}.pdf", $label->bytes);
}
schedulePickup()
use Eram\Ersal\Contracts\SupportsPickup;
use Eram\Ersal\Request\PickupRequest;
if ($chapar instanceof SupportsPickup) {
$chapar->schedulePickup($shipment->getId(), new PickupRequest(
windowStart: new DateTimeImmutable('tomorrow 9:00'),
windowEnd: new DateTimeImmutable('tomorrow 11:00'),
instructions: 'پشت در تحویل دهید',
));
}
مدیریت خطا
use Eram\Ersal\Exception\ProviderException;
use Eram\Ersal\Provider\Chapar\ChaparErrorCode;
try {
$chapar->createShipment($booking);
} catch (ProviderException $e) {
$code = ChaparErrorCode::tryFrom((int) $e->getErrorCode());
echo $code?->message('fa') ?? $e->getMessage();
}
نکات
- هزینه به ریال، وزن به گرم، ابعاد به میلیمتر
- آدرس endpointها را با مستندات توسعهدهنده چاپار تایید کنید
⁅شرکت حمل خصوصی rest api پشتیبانی از برچسب pickup و پسکرایه پس کرایه use eram ersal provider chapar chaparconfig config new chaparconfig apikey your api key sandbox false baseurl null پارامتر نوع اجباری پیشفرض پیش فرض توضیح apikey string بله کلید api از پرتال چاپار sandbox bool خیر false محیط تست baseurl string خیر null بازنویسی آدرس ادرس api رابط پشتیبانی shippinginterface supportslabel supportspickup supportscod supportsbranches use eram ersal ersal use eram ersal provider chapar chaparconfig chapar new ersal create chapar new chaparconfig apikey your key چاپار از هدر x api key استفاد کرد use eram ersal address parcel use eram ersal request quoterequest quotes chapar quote new quoterequest origin origin destination destination parcel new parcel weightgrams 1000 lengthmm 200 widthmm 150 heightmm 80 foreach quotes as quote printf s s توم تحویل s روز n quote servicelevel quote cost intoman quote etadays use eram ersal request bookingrequest shipment chapar createshipment new bookingrequest origin origin destination destination parcel parcel orderid order chp 001 servicelevel standard quoteid quotes 0 quoteid description وسایل الکترونیکی use eram ersal contracts supportscod use eram ersal money amount if chapar instanceof supportscod booking new bookingrequest origin origin destination destination parcel parcel orderid order chp cod 001 withcashondelivery amount fromtoman 1 200 000 shipment chapar createshipment booking tracked chapar track shipment getid foreach tracked gethistory as event printf s s n event at format y m d h i event description cancelled chapar cancel shipment getid use eram ersal contracts supportslabel if chapar instanceof supportslabel label chapar getlabel shipment getid file put contents chapar shipment getid pdf label bytes use eram ersal contracts supportspickup use eram ersal request pickuprequest if chapar instanceof supportspickup chapar schedulepickup shipment getid new pickuprequest windowstart new datetimeimmutable tomorrow 9 00 windowend new datetimeimmutable tomorrow 11 00 instructions پشت در تحویل داد use eram ersal exception providerexception use eram ersal provider chapar chaparerrorcode try chapar createshipment booking catch providerexception e code chaparerrorcode tryfrom int e geterrorcode echo code message fa e getmessage هزینه به ریال وزن به گرم بعد به میل میلی متر آدرس ادرس endpoint را با مستند توسعهد توسعه دهنده چاپار تای کرد⁆
⁅چاپار chapar express⁆
⁅پیکربندیقابلیتهاراهاندازیquote پیکربندیقابلیت هاراه اندازیquote createshipment پسکرایهtrack پس کرایهtrack cancel getlabel schedulepickup مدیریت خطانک⁆