|
| 1 | +Example request: |
| 2 | +```php |
| 3 | +$shipment = new ShipmentRequest(); |
| 4 | +$shipment->SiteID = $order->auth->account_number; |
| 5 | +$shipment->Password = $order->auth->password; |
| 6 | +$shipment->MessageTime = Carbon::now()->format(Carbon::ATOM); |
| 7 | +$shipment->MessageReference = substr($reference, 0, 30); |
| 8 | +$shipment->LanguageCode = 'en'; |
| 9 | +$shipment->PiecesEnabled = 'Y'; |
| 10 | +$shipment->Reference->ReferenceID = $client->account . '-' . $order->id; |
| 11 | + |
| 12 | +$shipment->Billing->ShipperAccountNumber = $order->auth->shipper_account; |
| 13 | +$shipment->Billing->ShippingPaymentType = 'S'; |
| 14 | +$shipment->Billing->BillingAccountNumber = $order->auth->billing_account; |
| 15 | + |
| 16 | +// Outside EU changes Tax info |
| 17 | +if (!Country::isEu($shipping_address->country)) { |
| 18 | + $shipment->Billing->DutyPaymentType = 'R'; |
| 19 | +} |
| 20 | + |
| 21 | +$contact_name = $shipping_address->first_name . ' ' . $shipping_address->last_name; |
| 22 | +$shipment->Consignee->CompanyName = $shipping_address->organisation ?? '--'; |
| 23 | +$shipment->Consignee->Contact->PersonName = $contact_name; |
| 24 | +$shipment->Consignee->addAddressLine(substr($shipping_address->address1, 0, 35)); |
| 25 | +$shipment->Consignee->addAddressLine(substr($shipping_address->address2, 0, 35)); |
| 26 | +$shipment->Consignee->City = $shipping_address->city; |
| 27 | +$shipment->Consignee->PostalCode = $shipping_address->postcode; |
| 28 | +$shipment->Consignee->Division = $shipping_address->state ?? ''; |
| 29 | +$shipment->Consignee->CountryCode = $shipping_address->country; |
| 30 | +$shipment->Consignee->CountryName = Country::getNameFromCode($shipping_address->country); |
| 31 | +$shipment->Consignee->Contact->PhoneNumber = $order->info->contact_no; |
| 32 | +$shipment->Consignee->Contact->Email = $order->info->email; |
| 33 | +$shipment->Consignee->Contact->PhoneExtension = ''; |
| 34 | +$shipment->Consignee->Contact->FaxNumber = ''; |
| 35 | +$shipment->Consignee->Contact->Telex = ''; |
| 36 | +$shipment->RegionCode = Country::getDHLRegionCode($shipping_address->country); |
| 37 | + |
| 38 | +$order_value = $order->order_cost - $order->delivery_cost > 0 ? $order->order_cost - $order->delivery_cost : 1.0; |
| 39 | +$shipment->Dutiable->DeclaredValue = $order_value; |
| 40 | +$shipment->Dutiable->DeclaredCurrency = 'GBP'; |
| 41 | +$shipment->Dutiable->TermsOfTrade = 'DDP'; |
| 42 | + |
| 43 | +$shipment->Shipper->ShipperID = $order->auth->shipper_id; |
| 44 | +$shipment->Shipper->RegisteredAccount = $order->auth->shipper_account_number; |
| 45 | +$shipment->Shipper->CompanyName = $collection_address->organisation; |
| 46 | +$shipment->Shipper->addAddressLine($collection_address->address1); |
| 47 | +$shipment->Shipper->addAddressLine($collection_address->address2); |
| 48 | +$shipment->Shipper->City = $collection_address->city; |
| 49 | +$shipment->Shipper->PostalCode = $collection_address->postcode; |
| 50 | +$shipment->Shipper->CountryCode = $collection_address->country; |
| 51 | +$shipment->Shipper->CountryName = Country::getNameFromCode($collection_address->country); |
| 52 | + |
| 53 | +$shipment->Shipper->Contact->PersonName = $collection_address->contact_name; |
| 54 | +$shipment->Shipper->Contact->PhoneNumber = $collection_address->contact_phone; |
| 55 | +$shipment->Shipper->Contact->Email = $collection_address->contact_email; |
| 56 | +$shipment->Shipper->Contact->PhoneExtension = ''; |
| 57 | +$shipment->Shipper->Contact->FaxNumber = ''; |
| 58 | +$shipment->Shipper->Contact->Telex = ''; |
| 59 | + |
| 60 | +// Delivery Service is obtained via Quote request which will find valid services for shipment |
| 61 | +$shipment->ShipmentDetails->GlobalProductCode = $delivery_service->code; |
| 62 | +$shipment->ShipmentDetails->LocalProductCode = $delivery_service->format; |
| 63 | + |
| 64 | +if (Country::isEu($shipping_address->country) === false) { |
| 65 | + $shipment->ShipmentDetails->DoorTo = 'DD'; |
| 66 | +} |
| 67 | +$shipment->ShipmentDetails->Contents = 'Shipment Description'; |
| 68 | +$shipment->ShipmentDetails->CurrencyCode = 'GBP'; |
| 69 | +$shipment->ShipmentDetails->WeightUnit = 'K'; |
| 70 | +$shipment->ShipmentDetails->Weight = collect($packages)->sum('weight'); |
| 71 | +$shipment->ShipmentDetails->Date = Carbon::now()->format('Y-m-d'); |
| 72 | +$shipment->ShipmentDetails->DimensionUnit = 'C'; |
| 73 | +$shipment->ShipmentDetails->InsuredAmount = $order->insurance_total ?? 0; |
| 74 | +$shipment->ShipmentDetails->PackageType = $order->package_type ?? 'PA'; |
| 75 | +$shipment->ShipmentDetails->IsDutiable = Country::isEu($shipping_address->country) ? 'Y' : 'N'; |
| 76 | + |
| 77 | +$shipment->ShipmentDetails->AdditionalProtection = new AdditionalProtection(); |
| 78 | +$shipment->ShipmentDetails->DOSFlag = 'N'; |
| 79 | +$shipment->ShipmentDetails->CustData = $contact_name; |
| 80 | + |
| 81 | +// Information about Packages in shipment |
| 82 | +$shipment->ShipmentDetails->NumberOfPieces = count($packages); |
| 83 | +foreach ($packages as $package_id => $package) { |
| 84 | + $piece = new Piece(); |
| 85 | + $piece->PieceID = $client->account . $order->id . $package_id; |
| 86 | + $piece->PackageType = $order->package_type ?? 'CP'; |
| 87 | + $piece->Weight = $package['weight']; |
| 88 | + $piece->DimWeight = $package['weight']; |
| 89 | + $shipment->ShipmentDetails->addPiece($piece); |
| 90 | +} |
| 91 | + |
| 92 | +$shipment->EProcShip = 'N'; |
| 93 | +$shipment->LabelImageFormat = 'PDF'; |
| 94 | +$shipment->Label->LabelTemplate = '8X4_PDF'; |
| 95 | + |
| 96 | +$client = new Web($this->getEnvironment()); |
| 97 | +$xml_response = $client->call($shipment); |
| 98 | +``` |
| 99 | + |
| 100 | +If you need XML request for the DHL certification you can obtain by calling the following code |
| 101 | +```php |
| 102 | +$request_xml = $shipment->toXml(); |
| 103 | +``` |
0 commit comments