Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: throw relevant error when no pdfs are received #516

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use BadMethodCallException;
use Closure;
use GuzzleHttp\Exception\BadResponseException;
use InvalidArgumentException;
use MyParcelNL\Sdk\src\Adapter\ConsignmentAdapter;
use MyParcelNL\Sdk\src\Concerns\HasUserAgent;
Expand Down Expand Up @@ -467,7 +468,20 @@ public function setPdfOfLabels($positions = self::DEFAULT_A4_POSITION): self
)
->sendRequest('GET', MyParcelRequest::REQUEST_TYPE_RETRIEVE_LABEL);

$this->label_pdf = $request->getResult();
/**
* When account needs to pay upfront, an array is returned with payment information,
* instead of the actual pdf’s. It will throw an unintelligible error when not handled here.
*/
$result = $request->getResult();

if (!is_string($result) || !preg_match('/^%PDF-1./', $result)) {
if (is_array($result) && isset($result['data']['payment_instructions'])) {
throw new ApiException('Received payment link instead of pdf. Check your MyParcel account status.');
}
throw new ApiException('Did not receive expected pdf response. Please contact MyParcel.');
}

$this->label_pdf = $result;
}

$this->setLatestData();
Expand Down