Skip to content

Commit

Permalink
chore: fix errorhandling + add method to get Status from PostNL
Browse files Browse the repository at this point in the history
  • Loading branch information
sytheveenje committed May 11, 2023
1 parent 3971a15 commit d3752be
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/LaravelPostnlApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function confirmShipment(
$response = Http::withHeaders([
'apikey' => config('postnl-api.api.key'),
'Content-Type' => 'application/json'
])->post(env('POSTNL_API_BASE_URL').'shipment/v2_2/confirm',
])->post(env('POSTNL_API_BASE_URL').'shipment/v2/confirm',
[
'Customer' => $this->customer,
'Message' => [
Expand All @@ -208,10 +208,27 @@ public function confirmShipment(
]);

if($response->successful()) {
return collect($response->object()->ResponseShipments)->first();
return $response->object()->ResponseShipments;
} else {
abort(500, 'PostNL API Error');
}

}

public function findStatusForShipment(
string $barcode = null,
string $language = 'NL'
)
{
$response = Http::withHeaders([
'apikey' => config('postnl-api.api.key'),
'Content-Type' => 'application/json'
])->get(env('POSTNL_API_BASE_URL').'shipment/v2/status/barcode/'.$barcode.'?detail=true&language='.$language);

if($response->successful()) {
return $response->object()->CompleteStatus;
} else {
abort(500, 'PostNL API Error');
}
}
}

0 comments on commit d3752be

Please sign in to comment.