34 lines
1.2 KiB
PHP
34 lines
1.2 KiB
PHP
<?php
|
|
|
|
require_once __DIR__.'/../../classes/InpostPack.php';
|
|
require_once __DIR__.'/../../classes/ShipX.php';
|
|
|
|
class inpostshipDispatchModuleFrontController extends ModuleFrontController
|
|
{
|
|
|
|
public function initContent()
|
|
{
|
|
parent::initContent();
|
|
$id_pack = $_REQUEST['id_pack'];
|
|
if ($id_pack > 0) {
|
|
$inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'));
|
|
$pack = InpostPack::getInpostShipByIdPack((int)$id_pack);
|
|
$inpost = $inpostapi->printDispatchPdf((int)$pack['dispatch_id']);
|
|
$inp = json_decode($inpost);
|
|
if (isset($inp->status)) {
|
|
die($inp->message.' '.$inp->details);
|
|
} else {
|
|
$file_name = 'dispatch_order-' . $pack['reference_number'];
|
|
$file = __DIR__ . '/../../files/' . $file_name . '.pdf';
|
|
file_put_contents($file, $inpost);
|
|
header('Content-Type: application/pdf');
|
|
header("Content-Disposition: attachment; filename=\"$file_name.pdf\"");
|
|
exit($inpost);
|
|
}
|
|
} else {
|
|
die('Brak id paczki');
|
|
}
|
|
}
|
|
|
|
}
|