API changes for Zapier

This commit is contained in:
Hillel Coren 2016-06-23 12:38:06 +03:00
parent 93c3521952
commit 725522ea21
3 changed files with 19 additions and 10 deletions

View File

@ -215,4 +215,15 @@ class BaseAPIController extends Controller
return $data;
}
protected function fileReponse($name, $data)
{
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($data));
header('Content-disposition: attachment; filename="' . $name . '"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
return $data;
}
}

View File

@ -184,6 +184,10 @@ class InvoiceApiController extends BaseAPIController
->with('client', 'invoice_items', 'invitations')
->first();
if (isset($data['download_invoice']) && boolval($data['download_invoice'])) {
return $this->fileReponse($invoice->getFileName(), $invoice->getPDFString());
}
return $this->itemResponse($invoice);
}
@ -361,14 +365,7 @@ class InvoiceApiController extends BaseAPIController
public function download(InvoiceRequest $request)
{
$invoice = $request->entity();
$pdfString = $invoice->getPDFString();
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($pdfString));
header('Content-disposition: attachment; filename="' . $invoice->getFileName() . '"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
return $pdfString;
return $this->fileReponse($invoice->getFileName(), $invoice->getPDFString());
}
}

View File

@ -29,7 +29,7 @@ class PaymentTransformer extends EntityTransformer
public function __construct($account = null, $serializer = null, $invoice = null)
{
parent::__construct($account, $serializer);
$this->invoice = $invoice;
}
@ -57,6 +57,7 @@ class PaymentTransformer extends EntityTransformer
'is_deleted' => (bool) $payment->is_deleted,
'payment_type_id' => (int) $payment->payment_type_id,
'invoice_id' => (int) ($this->invoice ? $this->invoice->public_id : $payment->invoice->public_id),
'invoice_number' => $this->invoice ? $this->invoice->invoice_number : $payment->invoice->invoice_number,
]);
}
}
}