فهرست مستندات پروژه
پایگان (Paygan)
تحویل درونشهری / لحظهای. REST API. پشتیبانی از پسکرایه.
پیکربندی
use Eram\Ersal\Provider\Paygan\PayganConfig;
$config = new PayganConfig(
apiKey: 'your-api-key',
sandbox: false,
baseUrl: null,
);
قابلیتها
| رابط | پشتیبانی |
|---|---|
ShippingInterface | ✅ |
SupportsCOD | ✅ |
SupportsLabel | ❌ |
SupportsPickup | ❌ (ضمنی — لحظهای) |
SupportsBranches | ❌ |
راهاندازی
use Eram\Ersal\Ersal;
use Eram\Ersal\Provider\Paygan\PayganConfig;
$paygan = (new Ersal())->create('paygan', new PayganConfig(apiKey: 'your-key'));
پایگان از هدر X-Api-Key استفاده میکند.
quote()
قیمتگذاری وابسته به فاصله است — مختصات جغرافیایی روی آدرسها دقت را افزایش میدهد.
use Eram\Ersal\Address\Address;
use Eram\Ersal\Address\Parcel;
use Eram\Ersal\Request\QuoteRequest;
$origin = new Address(
firstName: 'Merchant', lastName: 'X',
phone: '09123456789',
province: 'تهران', city: 'تهران',
addressLine: 'خیابان ستارخان',
lat: 35.7123, lng: 51.3456,
);
$destination = new Address(
firstName: 'Customer', lastName: 'Y',
phone: '09121111111',
province: 'تهران', city: 'تهران',
addressLine: 'خیابان شریعتی',
lat: 35.7321, lng: 51.4567,
);
$quotes = $paygan->quote(new QuoteRequest(
origin: $origin, destination: $destination,
parcel: new Parcel(weightGrams: 800),
));
foreach ($quotes as $quote) {
echo "{$quote->cost->inToman()} تومان ({$quote->etaDays} روز تحویل)\n";
}
createShipment()
use Eram\Ersal\Request\BookingRequest;
$shipment = $paygan->createShipment(new BookingRequest(
origin: $origin, destination: $destination,
parcel: new Parcel(weightGrams: 800),
orderId: 'ORDER-PG-001',
));
پسکرایه
use Eram\Ersal\Contracts\SupportsCOD;
use Eram\Ersal\Money\Amount;
if ($paygan instanceof SupportsCOD) {
$booking = (new BookingRequest(
origin: $origin, destination: $destination,
parcel: new Parcel(weightGrams: 800),
orderId: 'ORDER-PG-COD-001',
))->withCashOnDelivery(Amount::fromToman(350_000));
$shipment = $paygan->createShipment($booking);
}
track()
$tracked = $paygan->track($shipment->getId());
foreach ($tracked->getHistory() as $event) {
printf("[%s] %s\n", $event->at->format('H:i'), $event->description);
}
cancel()
$cancelled = $paygan->cancel($shipment->getId());
مدیریت خطا
use Eram\Ersal\Exception\ProviderException;
use Eram\Ersal\Provider\Paygan\PayganErrorCode;
try {
$paygan->createShipment($booking);
} catch (ProviderException $e) {
$code = PayganErrorCode::tryFrom((int) $e->getErrorCode());
echo $code?->message('fa') ?? $e->getMessage();
}
نکات
- بهینهشده برای ارسال درونشهری یا مسافت کوتاه
- Pickup ضمنی است (لحظهای) — گام جمعآوری مجزا ندارد
- آدرس endpointها را با مستندات توسعهدهنده پایگان تایید کنید
⁅تحویل درونشهری درون شهری لحظه لحظ rest api پشتیبانی از پسکرایه پس کرایه use eram ersal provider paygan payganconfig config new payganconfig apikey your api key sandbox false baseurl null رابط پشتیبانی shippinginterface supportscod supportslabel supportspickup ضمنی لحظه لحظ supportsbranches use eram ersal ersal use eram ersal provider paygan payganconfig paygan new ersal create paygan new payganconfig apikey your key پای از هدر x api key استفاد کرد قیمتگذاری قیمت گذاری وابست به فاصله است مختصات جغرافیایی روی آدرس ادرس دقت را افز داد use eram ersal address address use eram ersal address parcel use eram ersal request quoterequest origin new address firstname merchant lastname x phone 09123456789 province تهران city تهران addressline خیابان ستارخ lat 35 7123 lng 51 3456 destination new address firstname customer lastname y phone 09121111111 province تهران city تهران addressline خیابان شریعتی lat 35 7321 lng 51 4567 quotes paygan quote new quoterequest origin origin destination destination parcel new parcel weightgrams 800 foreach quotes as quote echo quote cost intoman توم quote etadays روز تحویل n use eram ersal request bookingrequest shipment paygan createshipment new bookingrequest origin origin destination destination parcel new parcel weightgrams 800 orderid order pg 001 use eram ersal contracts supportscod use eram ersal money amount if paygan instanceof supportscod booking new bookingrequest origin origin destination destination parcel new parcel weightgrams 800 orderid order pg cod 001 withcashondelivery amount fromtoman 350 000 shipment paygan createshipment booking tracked paygan track shipment getid foreach tracked gethistory as event printf s s n event at format h i event description cancelled paygan cancel shipment getid use eram ersal exception providerexception use eram ersal provider paygan payganerrorcode try paygan createshipment booking catch providerexception e code payganerrorcode tryfrom int e geterrorcode echo code message fa e getmessage بهینهشد بهینه شد برای ارسال درونشهری درون شهری یا مسافت کوتاه pickup ضمنی است لحظه لحظ گام جمعآوری جمعاوری جمع آوری مجزا نداشت آدرس ادرس endpoint را با مستند توسعهد توسعه دهنده پای تای کرد⁆
⁅پای paygan⁆
⁅پیکربندیقابلیتهاراهاندازیquote پیکربندیقابلیت هاراه اندازیquote createshipment پسکرایهtrack پس کرایهtrack cancel مدیریت خطانک⁆