aboodma/aramex-integration
Composer 安装命令:
composer require aboodma/aramex-integration
包简介
Integration With Aramex Services (Tracking / Shipment / Rate Calculator)
README 文档
README
This PHP library allows for easy integration with the Aramex shipping API. It provides a set of models and a client to interact with the API for creating shipments, generating labels, and more.
Requirements
- PHP 8 or higher
- Composer
Installation
Install the library using Composer:
composer require aboodma/aramex-integration
Usage
Configuration
Create a configuration object with your Aramex account details:
use Aboodma\AramexIntegration\Config; $config = (new Config()) ->setUsername("your_username") ->setPassword("your_password") ->setVersion("v1.0") ->setAccountNumber("your_account_number") ->setAccountPin("your_account_pin") ->setAccountEntity("your_account_entity") ->setAccountCountryCode("your_account_country_code") ->setSource(24);
Creating a Shipment
use Aboodma\AramexIntegration\Models\Address; use Aboodma\AramexIntegration\Models\Contact; use Aboodma\AramexIntegration\Models\Party; use Aboodma\AramexIntegration\Models\Dimensions; use Aboodma\AramexIntegration\Models\Weight; use Aboodma\AramexIntegration\Models\Amount; use Aboodma\AramexIntegration\Models\ShipmentDetails; use Aboodma\AramexIntegration\Models\Shipment; use Aboodma\AramexIntegration\Models\LabelInfo; use Aboodma\AramexIntegration\Models\ClientInfo; use Aboodma\AramexIntegration\AramexClient; use Aboodma\AramexIntegration\Exceptions\AramexException; // Shipper details $shipperAddress = (new Address()) ->setLine1("Test Shipper Address Line1") ->setLine2("Test Shipper Address Line2") ->setCity("Dubai") ->setPostCode("000000") ->setCountryCode("AE"); $shipperContact = (new Contact()) ->setPersonName("Test Shipper Name") ->setCompanyName("Test Shipper Company Name") ->setPhoneNumber1("048707766") ->setCellPhone("971556893100") ->setEmailAddress("test@aramex.com"); $shipper = (new Party()) ->setReference1("Shipper Reference") ->setAccountNumber("45796") ->setPartyAddress($shipperAddress) ->setContact($shipperContact); // Consignee details $consigneeAddress = (new Address()) ->setLine1("Test Consignee Address Line1") ->setLine2("Test Consignee Address Line2") ->setLine3("Test Consignee Address Line3") ->setCity("Dubai") ->setStateOrProvinceCode("FU") ->setCountryCode("AE"); $consigneeContact = (new Contact()) ->setPersonName("Test Consignee Name") ->setCompanyName("Test Consignee Company Name") ->setPhoneNumber1("048707766") ->setCellPhone("971556893100") ->setEmailAddress("tets@hotmail.com"); $consignee = (new Party()) ->setAccountNumber("0") ->setPartyAddress($consigneeAddress) ->setContact($consigneeContact); // Shipment details $dimensions = (new Dimensions()) ->setLength(0) ->setWidth(0) ->setHeight(0) ->setUnit("CM"); $actualWeight = (new Weight()) ->setUnit("KG") ->setValue(0.1); $chargeableWeight = (new Weight()) ->setUnit("KG") ->setValue(0); $amount = (new Amount()) ->setCurrencyCode("AED") ->setValue(10); $details = (new ShipmentDetails()) ->setDimensions($dimensions) ->setActualWeight($actualWeight) ->setChargeableWeight($chargeableWeight) ->setDescriptionOfGoods("Items") ->setGoodsOriginCountry("AE") ->setNumberOfPieces(1) ->setProductGroup("DOM") ->setProductType("ONP") ->setPaymentType("P") ->setPaymentOptions("ACCT") ->setCustomsValueAmount($amount); $shipment = (new Shipment()) ->setShipper($shipper) ->setConsignee($consignee) ->setDetails($details) ->setReference1("Shipment Reference"); // Label info $labelInfo = (new LabelInfo()) ->setReportID(9729) ->setReportType("URL"); // Client info $clientInfo = (new ClientInfo()) ->setUserName("testingapi@aramex.com") ->setPassword('R123456789$r') ->setVersion("v1.0") ->setAccountNumber("45796") ->setAccountPin("116216") ->setAccountEntity("DXB") ->setAccountCountryCode("AE") ->setSource(24); // Initialize AramexClient and make the request $client = new AramexClient($config); try { $response = $client->createShipment($shipment, $labelInfo, $clientInfo); echo json_encode($response, JSON_PRETTY_PRINT); } catch (AramexException $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; echo 'HTTP Status Code: ' . $e->getHttpStatusCode() . PHP_EOL; echo 'Error Details: ' . print_r($e->getErrorDetails(), true); }
Models
Address
Represents an address.
setLine1(string $line1): selfsetLine2(string $line2): selfsetLine3(string $line3): selfsetCity(string $city): selfsetStateOrProvinceCode(string $stateOrProvinceCode): selfsetPostCode(string $postCode): selfsetCountryCode(string $countryCode): self
Contact
Represents a contact.
setPersonName(string $personName): selfsetCompanyName(string $companyName): selfsetPhoneNumber1(string $phoneNumber1): selfsetPhoneNumber1Ext(string $phoneNumber1Ext): selfsetPhoneNumber2(string $phoneNumber2): selfsetPhoneNumber2Ext(string $phoneNumber2Ext): selfsetFaxNumber(string $faxNumber): selfsetCellPhone(string $cellPhone): selfsetEmailAddress(string $emailAddress): selfsetType(string $type): self
Party
Represents a party involved in the shipment (shipper or consignee).
setReference1(string $reference1): selfsetReference2(string $reference2): selfsetAccountNumber(string $accountNumber): selfsetPartyAddress(Address $partyAddress): selfsetContact(Contact $contact): self
Dimensions
Represents the dimensions of a shipment.
setLength(float $length): selfsetWidth(float $width): selfsetHeight(float $height): selfsetUnit(string $unit): self
Weight
Represents the weight of a shipment.
setUnit(string $unit): selfsetValue(float $value): self
Amount
Represents a monetary amount.
setCurrencyCode(string $currencyCode): selfsetValue(float $value): self
ShipmentDetails
Represents the details of a shipment.
setDimensions(Dimensions $dimensions): selfsetActualWeight(Weight $actualWeight): selfsetChargeableWeight(Weight $chargeableWeight): selfsetDescriptionOfGoods(string $descriptionOfGoods): selfsetGoodsOriginCountry(string $goodsOriginCountry): selfsetNumberOfPieces(int $numberOfPieces): selfsetProductGroup(string $productGroup): selfsetProductType(string $productType): selfsetPaymentType(string $paymentType): selfsetPaymentOptions(string $paymentOptions): selfsetCustomsValueAmount(Amount $customsValueAmount): selfsetCashOnDeliveryAmount(Amount $cashOnDeliveryAmount): selfsetInsuranceAmount(Amount $insuranceAmount): selfsetCashAdditionalAmount(Amount $cashAdditionalAmount): selfsetCashAdditionalAmountDescription(string $cashAdditionalAmountDescription): selfsetCollectAmount(Amount $collectAmount): selfsetServices(string $services): selfsetItems(array $items): selfsetDeliveryInstructions(string $deliveryInstructions): selfsetAdditionalProperties(string $additionalProperties): selfsetContainsDangerousGoods(bool $containsDangerousGoods): self
Shipment
Represents a shipment.
setReference1(string $reference1): selfsetReference2(string $reference2): selfsetReference3(string $reference3): selfsetShipper(Party $shipper): selfsetConsignee(Party $consignee): selfsetThirdParty(Party $thirdParty): selfsetShippingDateTime(\DateTime $shippingDateTime): selfsetDueDate(\DateTime $dueDate): selfsetComments(string $comments): selfsetPickupLocation(string $pickupLocation): selfsetOperationsInstructions(string $operationsInstructions): selfsetAccountingInstructions(string $accountingInstructions): selfsetDetails(ShipmentDetails $details): selfsetAttachments(array $attachments): selfsetForeignHAWB(string $foreignHAWB): selfsetTransportType(string $transportType): selfsetPickupGUID(string $pickupGUID): selfsetNumber(string $number): selfsetScheduledDelivery(\DateTime $scheduledDelivery): self
LabelInfo
Represents label information for the shipment.
setReportID(int $reportID): selfsetReportType(string $reportType): self
ClientInfo
Represents client information.
setUserName(string $userName): selfsetPassword(string $password): selfsetVersion(string $version): selfsetAccountNumber(string $accountNumber): selfsetAccountPin(string $accountPin): selfsetAccountEntity(string $accountEntity): selfsetAccountCountryCode(string $accountCountryCode): selfsetSource(int $source): self
Error Handling
If the API request fails, an AramexException will be thrown. This exception contains the error message, HTTP status code, and error details returned by the API.
try { $response = $client->createShipment($shipment, $labelInfo, $clientInfo); echo json_encode($response, JSON_PRETTY_PRINT); } catch (AramexException $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; echo 'HTTP Status Code: ' . $e->getHttpStatusCode() . PHP_EOL; echo 'Error Details: ' . print_r($e->getErrorDetails(), true); }
Logging
The library logs request payloads, response payloads, and error responses to log files for debugging purposes.
Contributing
Please submit issues and pull requests on the GitHub repository.
License
This project is licensed under the MIT License.
aboodma/aramex-integration 适用场景与选型建议
aboodma/aramex-integration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 aboodma/aramex-integration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aboodma/aramex-integration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 54
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-08