From 66187ba1ba75c07f8af36c540f1742efa95a6eb7 Mon Sep 17 00:00:00 2001 From: Moustafa22 Date: Sun, 17 Jan 2021 17:43:08 +0200 Subject: [PATCH] update shipment options and documentation * add references * update decumentation references * sync error responses in create shipment --- README.md | 21 ++++++++++++++++++--- src/Aramex.php | 5 +++++ src/Core.php | 34 ++++++++++++++++++---------------- src/Helpers/AramexHelper.php | 7 +++++-- src/Validators/Validator.php | 1 - src/config/main.php | 2 +- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index d7eed0d..544d255 100644 --- a/README.md +++ b/README.md @@ -160,10 +160,25 @@ composer require octw/aramex 'due_date' => time() + 60000, // due date of the shipment 'comments' => 'No Comment', // ,comments 'pickup_location' => 'at reception', // location as pickup - 'pickup_guid' => $guid, // GUID taken from createPickup method + 'pickup_guid' => $guid, // GUID taken from createPickup method (optional) 'weight' => 1, // weight - 'number_of_pieces' => 1, // number of boxes + 'goods_country' => null, // optional + 'number_of_pieces' => 1, // number of items 'description' => 'Goods Description, like Boxes of flowers', // description + 'reference' => '01020102' // reference to print on shipment report (policy) + 'shipper_reference' => '19191', // optional + 'consignee_reference' => '010101', // optional + 'services' => 'CODS,FIRST,FRDM, .. ' // ',' seperated string, refer to services in the official documentation + 'cash_on_delivery_amount' => 10.32 // in case of CODS (in USD only "as they want") + 'insurance_amount' => 0, // optional + 'collect_amount' => 0, // optional + 'customs_value_amount' => 0, //optional (required for express shipping) + 'cash_additional_amount' => 0, // optional + 'cash_additional_amount_description' => 'Something here', + 'product_group' => 'DOM', // or EXP (defined in config file, if you dont pass it will take the config value) + 'product_type' => 'PPX', // refer to the official documentation (defined in config file, if you dont pass it will take the config value) + 'payment_type' => 'P', // P,C, 3 refer to the official documentation (defined in config file, if you dont pass it will take the config value) + 'payment_option' => null, // refer to the official documentation (defined in config file, if you dont pass it will take the config value) ``` retrun stdClass: @@ -286,7 +301,7 @@ composer require octw/aramex 'due_date' => time() + 60000, 'comments' => 'No Comment', 'pickup_location' => 'at reception', - 'pickup_guid' => $guid, + // 'pickup_guid' => $guid, 'weight' => 1, 'number_of_pieces' => 1, 'description' => 'Goods Description, like Boxes of flowers', diff --git a/src/Aramex.php b/src/Aramex.php index 688503f..912d92c 100644 --- a/src/Aramex.php +++ b/src/Aramex.php @@ -120,6 +120,11 @@ public static function createShipment($param =[]) if ($call->HasErrors) { $ret->error = 1; + if (isset($call->Notifications->Notification)) + { + $ret->errors = [$call->Notifications->Notification]; + } + if (is_object($call->Shipments->ProcessedShipment->Notifications->Notification)) { $ret->errors = [ $call->Shipments->ProcessedShipment->Notifications->Notification ]; diff --git a/src/Core.php b/src/Core.php index 4f6840f..b7507f5 100644 --- a/src/Core.php +++ b/src/Core.php @@ -72,8 +72,9 @@ public function __construct() public function initializeShipment($shipper , $consignee , $details) { $this->param['Shipments'] = [ - 'Shipment' => [ + [ 'Shipper' => [ + 'Reference1' => $details->ShipperReference, // for response 'AccountNumber' => $this->accNum, 'Contact' => [ 'PersonName' => $shipper->PersonName, @@ -95,8 +96,7 @@ public function initializeShipment($shipper , $consignee , $details) ], ], 'Consignee' => [ - 'Reference1' => time(), // for response - 'Reference2' => '', // for response + 'Reference1' => $details->ConsgineeReference, // for response 'AccountNumber' => $this->accNum, //Account Number 'Contact' => [ 'PersonName' => $consignee->PersonName,//Person Name @@ -114,17 +114,17 @@ public function initializeShipment($shipper , $consignee , $details) ], ], - - 'ShippingDateTime' => $details->ShippingDateTime, // Should be Filled - "DueDate"=> $details->DueDate, // Should be Filled - "Comments"=> $details->Comments, //Should Be Filled - "PickupLocation"=> $details->PickupLocation, // Should be Filled - "Attachments"=> null, - "ForeignHAWB"=> null, - "TransportType"=> "0", - "PickupGUID"=> $details->PickupGUID, - "Number"=> null, - 'Details' => [ + 'ShippingDateTime' => $details->ShippingDateTime, // Should be Filled + "DueDate" => $details->DueDate, // Should be Filled + "Comments" => $details->Comments, //Should Be Filled + "PickupLocation" => $details->PickupLocation, // Should be Filled + "Attachments" => null, + "ForeignHAWB" => null, + 'Reference1' => $details->Reference1, // for response + "TransportType" => 0, + "PickupGUID" => $details->PickupGUID, + "Number" => null, + 'Details' => [ 'ActualWeight' => [ 'Value' => $details->ActualWeight, 'Unit' => 'Kg' @@ -138,6 +138,7 @@ public function initializeShipment($shipper , $consignee , $details) 'DescriptionOfGoods' => $details->DescriptionOfGoods, 'GoodsOriginCountry' => $details->GoodsOriginCountry, 'Services' => $details->Services, + 'Items' => $details->NumberOfPieces, // Optionals Depending on Payment terms above @@ -148,7 +149,8 @@ public function initializeShipment($shipper , $consignee , $details) 'CashOnDeliveryAmount' => [ 'Value' => $details->CashOnDeliveryAmount, - 'CurrencyCode' => $details->CurrencyCode + 'CurrencyCode' => 'USD' + // 'CurrencyCode' => $details->CurrencyCode ], 'InsuranceAmount' => [ @@ -168,7 +170,7 @@ public function initializeShipment($shipper , $consignee , $details) ], ] - ] + ] ]; } diff --git a/src/Helpers/AramexHelper.php b/src/Helpers/AramexHelper.php index 7e86ef1..8abc3f6 100644 --- a/src/Helpers/AramexHelper.php +++ b/src/Helpers/AramexHelper.php @@ -184,10 +184,13 @@ public static function extractShipmentDetails($param = []){ $shipmentDetails->ProductGroup = $param['product_group'] ?? config('aramex.ProductGroup'); $shipmentDetails->ProductType = $param['product_type'] ?? config('aramex.ProductType'); - $shipmentDetails->PaymentType = $param['payment_type'] ?? config('aramex.Payment'); $shipmentDetails->PaymentType = $param['payment_type'] ?? config('aramex.Payment'); - $shipmentDetails->PaymentOptions = $param['payment_options'] ?? config('aramex.PaymentOptions'); + $shipmentDetails->PaymentOptions = $param['payment_option'] ?? config('aramex.PaymentOptions'); $shipmentDetails->Services = $param['services'] ?? config('aramex.Services'); + $shipmentDetails->Reference1 = $param['reference'] ?? ''; + $shipmentDetails->ShipperReference = $param['shipper_reference'] ?? ''; + $shipmentDetails->ConsgineeReference = $param['consignee_reference'] ?? ''; + $shipmentDetails->DescriptionOfGoods = $param['description'] ?? ""; diff --git a/src/Validators/Validator.php b/src/Validators/Validator.php index 3b0f6ae..20eccc6 100644 --- a/src/Validators/Validator.php +++ b/src/Validators/Validator.php @@ -53,7 +53,6 @@ public static function validateShipmentDetails($param) 'shipping_date_time' => 'required', 'due_date' => 'required', 'pickup_location' => 'required', - 'pickup_guid' => 'required', 'weight' => 'required', ]); if ($validator->fails()) diff --git a/src/config/main.php b/src/config/main.php index b4e35d1..3914b47 100644 --- a/src/config/main.php +++ b/src/config/main.php @@ -155,7 +155,7 @@ /** * Label Information * Available Values: - * ReportID => 9201 only (No one knows why do we send it if its only can be set to 9201 !!) + * ReportID => 9201, 9729 (9729 use it when COD to extract readable reports, 9201 with COD will not be accepted) * ReportType => “URL” to get report hosted on URL as PDF * “RPT” to get a streamed file */