PHP code example of simplefatoora / laravel
1. Go to this page and download the library: Download simplefatoora/laravel library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
simplefatoora / laravel example snippets
use SimpleFatoora\Laravel\SimpleFatooraClient;
final class ShowBusinessProfile
{
public function __invoke(SimpleFatooraClient $simpleFatoora): array
{
$result = $simpleFatoora->profile()->get();
return $result->response;
}
}
use SimpleFatoora\Laravel\Facades\SimpleFatoora;
$profile = SimpleFatoora::profile()->get()->response;
$liveProfile = $simpleFatoora->forLive()->profile()->get();
$sandboxProfile = $simpleFatoora->forSandbox()->profile()->get();
use Illuminate\Support\Str;
use SimpleFatoora\Laravel\Data\RegistrationData;
$journeyId = (string) Str::uuid();
$registration = new RegistrationData(
email: '[email protected] ',
password: $password,
passwordConfirmation: $password,
companyName: 'Example Company',
acceptedTerms: true,
firstName: 'Example',
lastName: 'Developer',
);
$intent = $simpleFatoora->account()
->createRegistrationIntent($registration, $journeyId)
->response;
$registrationIntent = $intent['registration_intent'];
$simpleFatoora->account()->sendEmailOtp('[email protected] ');
$verified = $simpleFatoora->account()->verifyEmailOtp('[email protected] ', $emailOtp)->response;
$account = $simpleFatoora->account()->completeRegistration($registrationIntent)->response;
$keyResult = $simpleFatoora->account()
->retrieveApiKeys('[email protected] ', $password);
$keys = $keyResult->raw;
$validation = $simpleFatoora->account()->validateApiKey($candidateKey)->raw;
$simpleFatoora->account()->resetPassword($resetUuid, $newPassword, $newPassword);
use SimpleFatoora\Laravel\Data\ProfileUpdateData;
$profile = $simpleFatoora->profile()->get()->response;
$updated = $simpleFatoora->profile()->update(new ProfileUpdateData(
companyName: 'Example Company',
address: 'Riyadh',
companyVatNumber: '300000000000003',
))->response;
$logo = $simpleFatoora->profile()->uploadLogo(storage_path('app/company-logo.png'));
use SimpleFatoora\Laravel\Data\ClientCreateData;
use SimpleFatoora\Laravel\Data\ClientUpdateData;
use SimpleFatoora\Laravel\Data\ListOptions;
$categories = $simpleFatoora->clients()->categories()->response;
$created = $simpleFatoora->clients()->create(new ClientCreateData(
name: 'Example Customer',
mobileNumber: '500000000',
countryCode: '+966',
email: '[email protected] ',
address: 'Riyadh',
))->response;
$clientId = $created['user_id'];
$simpleFatoora->clients()->update(new ClientUpdateData(
id: $clientId,
address: 'Jeddah',
));
$client = $simpleFatoora->clients()->find($clientId)->response;
$clients = $simpleFatoora->clients()->list(new ListOptions(page: 1, perPage: 20, searchKey: 'Example'))->response;
$simpleFatoora->clients()->delete($clientId);
use SimpleFatoora\Laravel\Data\ListOptions;
$matches = $simpleFatoora->products()->search('Consulting', limit: 20)->response;
$products = $simpleFatoora->products()->list(new ListOptions(limit: 20))->response;
use SimpleFatoora\Laravel\Data\InvoiceData;
use SimpleFatoora\Laravel\Data\InvoiceLine;
use SimpleFatoora\Laravel\Enums\DocumentType;
$document = new InvoiceData(
type: DocumentType::SimplifiedInvoice,
clientType: 2,
clientName: 'Example Customer',
clientAddress: 'Riyadh',
clientEmail: '[email protected] ',
referenceNumber: 'ORDER-1001',
lines: [
new InvoiceLine(
description: 'Consulting',
unitPrice: 100,
quantity: 1,
vatPercentProduct: 15,
discountPercent: 0,
),
],
);
$created = $simpleFatoora->documents()->create($document)->response;
$documentId = $created['id'];
$saved = $simpleFatoora->documents()->find($documentId)->response;
DocumentType::SimplifiedInvoice; // 0
DocumentType::StandardInvoice; // 1
DocumentType::PurchaseInvoice; // 2
DocumentType::CreditNote; // 3
DocumentType::DebitNote; // 4
$creditNote = $simpleFatoora->documents()->create(new InvoiceData(
type: DocumentType::CreditNote,
parentInvoiceNumber: $saved['invoice_number'],
documentReason: 'Returned items',
lines: [
new InvoiceLine('Returned item', 100, 1, vatPercentProduct: 15),
],
))->response;
use SimpleFatoora\Laravel\Data\InvoiceListOptions;
$documents = $simpleFatoora->documents()->list(new InvoiceListOptions(
page: 1,
perPage: 50,
searchKey: 'ORDER-1001',
$pdf = $simpleFatoora->documents()->downloadPdf(
$documentId,
storage_path("app/invoices/{$documentId}.pdf"),
);
$xml = $simpleFatoora->documents()->downloadXml(
$documentId,
storage_path("app/invoices/{$documentId}.xml"),
);
use SimpleFatoora\Laravel\Data\ArchiveRequest;
use SimpleFatoora\Laravel\Enums\ArchiveFormat;
$archive = $simpleFatoora->documents()->exportArchive(
new ArchiveRequest(
format: ArchiveFormat::Xml,
startDate: '2026-01-01',
endDate: '2026-01-31',
types: [DocumentType::SimplifiedInvoice, DocumentType::StandardInvoice],
),
storage_path('app/invoices/january-2026.zip'),
);
use SimpleFatoora\Laravel\Data\QuotationData;
use SimpleFatoora\Laravel\Data\QuotationListOptions;
$quotationPayload = [
'document_kind' => 'quotation',
'client_type' => 2,
'client_name' => 'Example Customer',
'client_address' => 'Riyadh',
'invoice_detail' => [
['description' => 'Consulting', 'unit_price' => 100, 'quantity' => 1, 'vat_percent' => 15],
],
];
$createdQuotation = $simpleFatoora->quotations()
->create(new QuotationData($quotationPayload))
->response;
$quotationId = $createdQuotation['id'];
$quotation = $simpleFatoora->quotations()->find($quotationId)->response;
$quotations = $simpleFatoora->quotations()->list(new QuotationListOptions(page: 1, perPage: 20))->response;
$simpleFatoora->quotations()->update(new QuotationData(
quotation: $quotationPayload,
id: $quotationId,
));
$simpleFatoora->quotations()->downloadPdf(
$quotationId,
storage_path("app/quotations/{$quotationId}.pdf"),
);
$invoice = $simpleFatoora->quotations()->convert($quotationId, $document)->response;
$simpleFatoora->quotations()->delete($quotationId);
use SimpleFatoora\Laravel\Data\DateRange;
$sales = $simpleFatoora->reports()
->sales(new DateRange('2026-01-01', '2026-01-31'))
->response;
$vatReturn = $simpleFatoora->reports()
->vatReturn(new DateRange('2026-01-01', '2026-03-31'))
->response;
$status = $simpleFatoora->zatcaPhase2()->status()->response;
use SimpleFatoora\Laravel\Data\ZatcaBusinessData;
$business = new ZatcaBusinessData(
companyName: 'Example Company',
organizationName: 'Example Company',
organizationIdentifier: '300000000000003',
organizationUnitName: 'Riyadh Branch',
companyRegistrationNumber: '1010000000',
companyVatNumber: '300000000000003',
industryBusinessCategory: 'Retail',
streetName: 'Example Street',
buildingNumber: '1234',
district: 'Example District',
city: 'Riyadh',
postalCode: '12345',
countryName: 'SA',
);
$simpleFatoora->zatcaPhase2()->saveDraft($business);
$simpleFatoora->zatcaPhase2()->generateCsr($business);
$simpleFatoora->zatcaPhase2()->submitOtp($zatcaOtp);
$simpleFatoora->zatcaPhase2()->retryCompliance();
$simpleFatoora->zatcaPhase2()->refreshStatus();
$simpleFatoora->zatcaPhase2()->renew();
use SimpleFatoora\Laravel\Exceptions\AuthenticationException;
use SimpleFatoora\Laravel\Exceptions\NetworkException;
use SimpleFatoora\Laravel\Exceptions\RateLimitException;
use SimpleFatoora\Laravel\Exceptions\ServerException;
use SimpleFatoora\Laravel\Exceptions\SimpleFatooraException;
use SimpleFatoora\Laravel\Exceptions\ValidationException;
try {
$result = $simpleFatoora->documents()->create($document);
} catch (ValidationException $exception) {
report($exception);
} catch (AuthenticationException $exception) {
report($exception);
} catch (RateLimitException $exception) {
$retryAfter = $exception->retryAfterSeconds;
} catch (NetworkException|ServerException $exception) {
report($exception);
} catch (SimpleFatooraException $exception) {
report($exception);
}
bash
php artisan vendor:publish --tag=simplefatoora-config
bash
php tools/compare-openapi.php resources/openapi.json /path/to/current-openapi.json