pritset / laravel
Laravel integration for the Pritset DOCX template and PDF generation API.
Requires
- php: ^8.2
- laravel/framework: ^11.0 || ^12.0 || ^13.0
Requires (Dev)
- laravel/pint: ^1.18
- orchestra/testbench: ^9.0 || ^10.0 || ^11.0
- phpstan/phpstan: ^1.12 || ^2.0
- phpunit/phpunit: ^10.5 || ^11.0 || ^12.0
This package is auto-updated.
Last update: 2026-08-21 18:29:05 UTC
README
Official-style Laravel integration for the Pritset DOCX template and PDF generation API.
Requirements
- PHP 8.2 or newer
- Laravel 11, 12, or 13
- A Pritset access token and secret from Pritset settings
Laravel 11 no longer receives upstream security fixes. Compatibility is retained for existing applications, but Laravel 12 or 13 is recommended for new projects.
Installation
composer require pritset/laravel php artisan vendor:publish --tag=pritset-config
Configure the credentials exactly as shown in the Pritset dashboard:
PRITSET_ACCESS_TOKEN=your-access-token PRITSET_SECRET=your-secret
Optional HTTP settings:
PRITSET_BASE_URL=https://api.pritset.com PRITSET_CONNECT_TIMEOUT=10 PRITSET_TIMEOUT=60
The package deliberately does not retry document generation or mutating operations. A timed-out request might still have generated and billed a document.
Direct processing
Fluent facade
use Pritset\Laravel\Facades\Pritset; $document = Pritset::template('customer-invoice') ->data([ 'invoiceNumber' => 'INV-1001', 'customerName' => 'Ada Lovelace', 'total' => '200.00', ]) ->direct(); return $document->download('INV-1001.pdf');
Store the generated PDF through Laravel Storage:
$stored = Pritset::template('customer-invoice') ->data($invoiceData) ->store('invoices/INV-1001.pdf', 's3');
Queue direct generation and storage:
Pritset::template('monthly-report') ->data($reportData) ->queue('reports/2026-08.pdf', 's3');
Queue jobs use one attempt by default because retrying an uncertain generation can create duplicate billable work. Override the package queue configuration only when that trade-off is acceptable.
Dependency injection
use Pritset\Laravel\Services\TemplateProcessor; final class GenerateInvoice { public function __construct(private TemplateProcessor $pritset) {} public function __invoke(array $data) { return $this->pritset->direct('customer-invoice', $data); } }
Document data may be an array, a Laravel Arrayable object, or a JsonSerializable object that normalizes to an array.
Webhook processing
Use your own callback URL:
$job = Pritset::template('monthly-report') ->data($reportData) ->webhook('https://example.com/webhooks/pritset'); $job->id;
Built-in receiver
The receiver is disabled by default. It stores callbacks as {prefix}/{requestId}.pdf and dispatches WebhookDocumentStored.
PRITSET_WEBHOOK_RECEIVER=true PRITSET_WEBHOOK_DISK=s3 PRITSET_WEBHOOK_PREFIX=pritset/webhooks PRITSET_WEBHOOK_MAX_BYTES=26214400
Both disk and prefix are required when the receiver is enabled. After configuration, omit the URL:
$job = Pritset::template('monthly-report') ->data($reportData) ->webhook();
Listen for stored documents:
use Pritset\Laravel\Events\WebhookDocumentStored; Event::listen(WebhookDocumentStored::class, function (WebhookDocumentStored $event) { // $event->requestId, $event->disk, $event->path, $event->sha256 });
Security warning: the current Pritset API does not sign callbacks. The built-in endpoint therefore cannot prove a request originated from Pritset. It is opt-in and should be protected with application middleware, a network allowlist, or a gateway before being used for sensitive documents. Configure extra route middleware in
config/pritset.php.
The receiver supports both the multipart data callback currently sent by Pritset.API and the raw PDF body described in the public documentation. A repeated callback with identical contents is accepted idempotently; a different PDF for an existing request ID is rejected.
Template management
use Pritset\Laravel\Data\SortDirection; use Pritset\Laravel\Data\TemplateListOptions; use Pritset\Laravel\Data\TemplateSort; use Pritset\Laravel\Facades\Pritset; use Pritset\Laravel\Uploads\TemplateUpload; $templates = Pritset::templates()->list(new TemplateListOptions( query: 'invoice', page: 1, perPage: 20, sorts: [new TemplateSort('Name', SortDirection::Ascending)], )); $template = Pritset::templates()->find('template-id'); $created = Pritset::templates()->create( name: 'Monthly invoice', template: resource_path('documents/invoice.docx'), tags: 'invoice,monthly', ); $updated = Pritset::templates()->update( templateId: $created->id, name: 'Monthly invoice 2026', tags: 'invoice,monthly,2026', template: TemplateUpload::fromStorage('s3', 'templates/invoice.docx'), ); $valid = Pritset::templates()->validate( resource_path('documents/invoice.docx'), ['invoiceNumber' => 'INV-1001'], ); $download = Pritset::templates()->download($created->id); return $download->download(); Pritset::templates()->delete($created->id);
TemplateUpload supports fromPath, fromUploadedFile, fromStorage, and fromStream. The client validates lowercase .doc/.docx extensions and the 5,000 KiB API limit before uploading.
The same operations are available by injecting Pritset\Laravel\Services\TemplateManager.
Events
DocumentGeneratedDocumentStoredDocumentGenerationFailedWebhookProcessingRequestedWebhookDocumentStoredTemplateCreatedTemplateUpdatedTemplateDeleted
Error handling
All API exceptions extend PritsetException. Status-specific exceptions include authentication, authorization, validation, not-found, payload-too-large, unsupported-media-type, rate-limit, conflict, and transport exceptions.
use Pritset\Laravel\Exceptions\RateLimitException; use Pritset\Laravel\Exceptions\ValidationException; try { $document = Pritset::template('invoice')->data($data)->direct(); } catch (ValidationException $exception) { report($exception->errors); } catch (RateLimitException $exception) { report($exception->retryAfter); }
Exceptions never add credentials or input document data to their messages.
Testing
Pritset::fake() uses Laravel's HTTP fake, so it covers calls made through the facade and injected package services.
use Pritset\Laravel\Facades\Pritset; $fake = Pritset::fake(); Pritset::template('invoice')->data(['number' => 'INV-1'])->direct(); $fake->assertDirectProcessed('invoice'); $fake->assertWebhookRequested('invoice'); $fake->assertTemplateCreated(); $fake->assertTemplateUpdated('template-id'); $fake->assertTemplateDeleted('template-id'); $fake->assertNothingProcessed();
Pass response overrides when needed:
Pritset::fake([ 'document' => file_get_contents(base_path('tests/Fixtures/invoice.pdf')), 'webhook_id' => 'abcdefabcdefabcdefabcdefabcdefab', ]);
Development
composer install
composer test
composer analyse
composer format-check
Live API tests are intentionally excluded from the normal suite and must never commit or print credentials, document data, or generated documents.
License
MIT. See LICENSE.