فهرست مستندات پروژه
پست ایران
سرویس پست ملی. API مبتنی بر SOAP. پشتیبانی از برچسب و شعب.
پیکربندی
use Eram\Ersal\Provider\Post\PostConfig;
$config = new PostConfig(
username: 'api-username',
password: 'api-password',
contractCode: 'your-contract-code',
sandbox: false,
wsdlUrl: null,
);
| پارامتر | نوع | اجباری | پیشفرض | توضیح |
|---|---|---|---|---|
username | string | بله | — | نام کاربری API |
password | string | بله | — | رمز عبور API |
contractCode | string | بله | — | کد قرارداد پذیرنده |
sandbox | bool | خیر | false | WSDL محیط تست |
wsdlUrl | ?string | خیر | null | بازنویسی آدرس WSDL |
قابلیتها
| رابط | پشتیبانی |
|---|---|
ShippingInterface | ✅ |
SupportsLabel | ✅ |
SupportsBranches | ✅ |
SupportsPickup | ❌ |
SupportsCOD | ❌ |
راهاندازی
use Eram\Ersal\Ersal;
use Eram\Ersal\Provider\Post\PostConfig;
$post = (new Ersal())->create('post', new PostConfig(
username: 'u', password: 'p', contractCode: 'c',
));
سطوح سرویس
| مقدار | فارسی | توضیح |
|---|---|---|
pishtaz | پیشتاز | داخلی اولویتدار |
sefareshi | سفارشی | ثبتشده استاندارد |
special | ویژه | داخلی پریمیوم |
international | بینالملل | بسته بینالمللی |
quote()
use Eram\Ersal\Address\Address;
use Eram\Ersal\Address\Parcel;
use Eram\Ersal\Request\QuoteRequest;
$origin = new Address(
firstName: 'Sender', lastName: 'N',
phone: '09123456789',
province: 'تهران', city: 'تهران',
addressLine: 'خیابان انقلاب، پلاک ۱',
postalCode: '1234567890',
);
$destination = new Address(
firstName: 'Receiver', lastName: 'N',
phone: '09121111111',
province: 'فارس', city: 'شیراز',
addressLine: 'خیابان زند، پلاک ۵۰',
postalCode: '7145678901',
);
$parcel = new Parcel(weightGrams: 2000, lengthMm: 400, widthMm: 300, heightMm: 100);
$quotes = $post->quote(new QuoteRequest(
origin: $origin, destination: $destination, parcel: $parcel,
serviceLevel: 'pishtaz',
));
foreach ($quotes as $quote) {
echo "{$quote->serviceLevel}: {$quote->cost->inToman()} تومان\n";
}
createShipment()
use Eram\Ersal\Request\BookingRequest;
$shipment = $post->createShipment(new BookingRequest(
origin: $origin, destination: $destination, parcel: $parcel,
orderId: 'ORDER-POST-001',
serviceLevel: 'pishtaz',
description: 'کتاب',
));
echo $shipment->getTrackingCode(); // مثلاً 'RB123456789IR'
track()
$tracked = $post->track($shipment->getId());
echo $tracked->getStatus()->label('fa');
foreach ($tracked->getHistory() as $event) {
printf("[%s] %s\n", $event->at->format('Y-m-d H:i'), $event->description);
}
cancel()
use Eram\Ersal\Exception\CancellationException;
try {
$cancelled = $post->cancel($shipment->getId());
} catch (CancellationException $e) {
// پست ایران فقط قبل از جمعآوری اجازه لغو میدهد
}
getLabel()
use Eram\Ersal\Contracts\SupportsLabel;
if ($post instanceof SupportsLabel) {
$label = $post->getLabel($shipment->getId());
file_put_contents("labels/post-{$shipment->getId()}.pdf", $label->bytes);
}
listBranches()
use Eram\Ersal\Contracts\SupportsBranches;
if ($post instanceof SupportsBranches) {
$branches = $post->listBranches('اصفهان');
foreach ($branches as $branch) {
printf("%s — %s (lat: %s, lng: %s)\n",
$branch->name, $branch->address,
$branch->lat, $branch->lng);
}
}
مدیریت خطا
use Eram\Ersal\Exception\ProviderException;
use Eram\Ersal\Provider\Post\PostErrorCode;
try {
$post->createShipment($booking);
} catch (ProviderException $e) {
$code = PostErrorCode::tryFrom((int) $e->getErrorCode());
echo $code?->message('fa') ?? $e->getMessage();
}
نکات
- از
ext-soapnative استفاده میکند — بدون وابستگی Composer - WSDL به صورت پیشفرض cache میشود
- آدرس WSDL و امضای متدها را با کاتالوگ API منتشر شده پست ایران تایید کنید
- COD و pickup در قرارداد استاندارد SOAP عرضه نمیشوند؛ برای آنها از تیپاکس یا چاپار استفاده کنید
⁅سرویس پست ملی api مبتنی بر soap پشتیبانی از برچسب و شعب use eram ersal provider post postconfig config new postconfig username api username password api password contractcode your contract code sandbox false wsdlurl null پارامتر نوع اجباری پیشفرض پیش فرض توضیح username string بله نام کاربری api password string بله رمز عبور api contractcode string بله کد قرارداد پذیرنده sandbox bool خیر false wsdl محیط تست wsdlurl string خیر null بازنویسی آدرس ادرس wsdl رابط پشتیبانی shippinginterface supportslabel supportsbranches supportspickup supportscod use eram ersal ersal use eram ersal provider post postconfig post new ersal create post new postconfig username u password p contractcode c مقدار فارسی توضیح pishtaz پیشتاز داخلی اولویتدار اولویت دار sefareshi سفارشی ثبتشد ثبت شد استاندارد special ویژه داخلی پریمیو international بینالملل بین الملل بست بینالمللی بین المللی use eram ersal address address use eram ersal address parcel use eram ersal request quoterequest origin new address firstname sender lastname n phone 09123456789 province تهران city تهران addressline خیابان انقلاب پلاک 1 postalcode 1234567890 destination new address firstname receiver lastname n phone 09121111111 province فارس city شیراز addressline خیابان زند پلاک 50 postalcode 7145678901 parcel new parcel weightgrams 2000 lengthmm 400 widthmm 300 heightmm 100 quotes post quote new quoterequest origin origin destination destination parcel parcel servicelevel pishtaz foreach quotes as quote echo quote servicelevel quote cost intoman توم n use eram ersal request bookingrequest shipment post createshipment new bookingrequest origin origin destination destination parcel parcel orderid order post 001 servicelevel pishtaz description کتاب echo shipment gettrackingcode مثلا rb123456789ir tracked post track shipment getid echo tracked getstatus label fa foreach tracked gethistory as event printf s s n event at format y m d h i event description use eram ersal exception cancellationexception try cancelled post cancel shipment getid catch cancellationexception e پست ایران فقط قبل از جمعآوری جمعاوری جمع آوری اجازه لغو داد use eram ersal contracts supportslabel if post instanceof supportslabel label post getlabel shipment getid file put contents labels post shipment getid pdf label bytes use eram ersal contracts supportsbranches if post instanceof supportsbranches branches post listbranches اصفهان foreach branches as branch printf s s lat s lng s n branch name branch address branch lat branch lng use eram ersal exception providerexception use eram ersal provider post posterrorcode try post createshipment booking catch providerexception e code posterrorcode tryfrom int e geterrorcode echo code message fa e getmessage از ext soap native استفاد کرد بدون وابستگی composer wsdl به صورت پیشفرض پیش فرض cache شد آدرس ادرس wsdl و امض متد را با کاتالوگ api منتشر شد پست ایران تای کرد cod و pickup در قرارداد استاندارد soap عرضه نشد برای آن آنها ان از تیپاکس یا چاپار استفاد کرد⁆
⁅پست ایران⁆
⁅پیکربندیقابلیتهاراهاندازیسطوح پیکربندیقابلیت هاراه اندازیسطوح سرویسquote createshipment track cancel getlabel listbranches مدیریت خطانک⁆