Skip to content

Commit

Permalink
chore: parse dates and wrap in try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
sytheveenje committed Jan 24, 2024
1 parent 5114406 commit e6922ff
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/LaravelPostnlApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,31 @@ public function generateLabel(
bool $fullLabel = false,
)
{

$response = Http::withHeaders([
'apikey' => config('postnl-api.api.key'),
'Content-Type' => 'application/json'
])->post(env('POSTNL_API_BASE_URL').'shipment/v2_2/label',
[
'Customer' => $this->customer,
'Message' => [
'MessageTimeStamp' => Carbon::now()->format('dd-mm-yyyy hh:mm:ss'),
'Printertype' => $printertype,
],
'Shipments' => [
'Addresses' => $address,
'Contacts' => $contact,
'ProductCodeDelivery' => $productCodeDelivery,
'ProductOptions' => $productOptions,
'DeliveryDate' => $deliveryDate,
'Barcode' => $barcode,
'Reference' => $reference,
'Remark' => $remark,
],
]);
try {
$response = Http::withHeaders([
'apikey' => config('postnl-api.api.key'),
'Content-Type' => 'application/json'
])->post(env('POSTNL_API_BASE_URL').'shipment/v2_2/label',
[
'Customer' => $this->customer,
'Message' => [
'MessageTimeStamp' => Carbon::now()->format('dd-mm-yyyy hh:mm:ss'),
'Printertype' => $printertype,
],
'Shipments' => [
'Addresses' => $address,
'Contacts' => $contact,
'ProductCodeDelivery' => $productCodeDelivery,
'ProductOptions' => $productOptions,
'DeliveryDate' => Carbon::parse($deliveryDate)->format('d-m-Y H:i:s'),
'Barcode' => $barcode,
'Reference' => $reference,
'Remark' => $remark,
],
]);
} catch (\Exception $e) {
return $e->getMessage();
}

$responseShipments = collect($response->object()->ResponseShipments)->first();

Expand Down Expand Up @@ -136,7 +139,7 @@ public function generateLabelForMultiCollo(
'Contacts' => $contact,
'ProductCodeDelivery' => $productCodeDelivery,
'ProductOptions' => $productOptions,
'DeliveryDate' => $deliveryDate,
'DeliveryDate' => Carbon::parse($deliveryDate)->format('d-m-Y H:i:s'),
'Barcode' => $barcode,
'Reference' => $reference,
'Remark' => $remark,
Expand Down

0 comments on commit e6922ff

Please sign in to comment.