zatbridge_zatca 0.2.0
zatbridge_zatca: ^0.2.0 copied to clipboard
ZATCA Phase 1 QR generation and Phase 2 offline signing for simplified-subtype (B2C) documents. Produces compliant QR payloads entirely on-device.
example/zatbridge_zatca_example.dart
import 'package:zatbridge_zatca/zatbridge_zatca.dart';
/// Generate the QR payload for a Phase 1 invoice without enrollment or network
/// access. Pass the result to the QR renderer used by the host POS application.
String phase1QrPayload() => generatePhase1QrCodeTlv(
Phase1QrCodeInput(
sellerName: 'Example Store',
vatRegistration: '300000000000003',
invoiceTimestamp: DateTime.now(),
invoiceTotal: '115.00',
vatTotal: '15.00',
),
);
/// Enroll once while online using a short-lived code supplied by the vendor
/// administrator. Never hardcode the code in the application.
Future<void> enrollDevice(String enrollmentCode) async {
final zatbridge = await ZatBridge.open(baseUrl: 'https://api.zatbridge.com');
try {
await zatbridge.enroll(
code: enrollmentCode,
appFingerprint: 'your-stable-app-installation-fingerprint',
appVersion: 'your-pos-app/1.0.0',
);
} finally {
await zatbridge.close();
}
}
/// Issue a simplified invoice offline. The returned TLV payload is ready to
/// render as a QR code with the QR widget or renderer used by the host app.
Future<IssueResult> issueSale() async {
final zatbridge = await ZatBridge.open(baseUrl: 'https://api.zatbridge.com');
try {
final issuedAt = DateTime.now().toUtc();
return await zatbridge.issueSimplified(
InvoiceRequest.deviceSimplified(
documentKind: DocumentKind.invoice,
invoiceNumber: 'POS-2026-000001',
issueDate: issuedAt,
issueTime: issuedAt,
lines: const [
InvoiceLine(
id: '1',
name: 'Retail item',
quantity: '1.00',
lineAmount: '100.00',
taxAmount: '15.00',
priceAmount: '100.00',
),
],
taxableAmount: '100.00',
taxPercent: '15.00',
taxTotal: '15.00',
payableAmount: '115.00',
),
);
} finally {
await zatbridge.close();
}
}