Skip to content

Commit 5a22028

Browse files
committed
Workaround for AusPost API sometimes just sending the PDF
1 parent 5ecfdde commit 5a22028

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Auspost.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ public function createOrder($shipment_ids) {
251251
$this->sendPutRequest('orders', $request);
252252
$data = $this->convertResponse($this->getResponse()->data);
253253
$this->closeSocket();
254+
if (!is_array($data)) {
255+
return new Order([
256+
'order_id' => 'None',
257+
'creation_date' => new \DateTime(),
258+
'manifest_pdf' => $data,
259+
]);
260+
}
254261

255262
if (array_key_exists('errors', $data)) {
256263
foreach ($data['errors'] as $error) {
@@ -476,7 +483,7 @@ private function closeSocket() {
476483
private function convertResponse($data) {
477484
$response = json_decode($data, true);
478485
if ($data && is_null($response)) {
479-
throw new \Exception('Could not decode response');
486+
return $data; // Could be an inline pdf
480487
}
481488
return $response;
482489
}

0 commit comments

Comments
 (0)