gst_einvoice 0.1.0
gst_einvoice: ^0.1.0 copied to clipboard
Build and validate India GST e-invoice (INV-01 v1.1) JSON in pure Dart. GSTIN checks, CGST/SGST/IGST math and pre-submission validation.
example/example.dart
// ignore_for_file: avoid_print
import 'dart:convert';
import 'package:gst_einvoice/gst_einvoice.dart';
void main() {
// 1. Check a GSTIN.
final check = Gstin.check('27AAPFU0939F1ZV');
print('GSTIN check: $check');
// 2. Work out GST for one line.
final line = GstCalculator.forLine(
quantity: 10,
unitPrice: 500,
discount: 500,
gstRate: 18,
kind: SupplyKind.intraState,
);
print(line); // taxable 4500, cgst 405, sgst 405, total 5310
// 3. Build an invoice. These GSTINs are made-up test values.
final invoice = EInvoice(
documentNumber: 'INV/2026-27/0001',
documentDate: DateTime(2026, 11, 2),
seller: Party(
gstin: '24AAAAA0000A1Z8',
legalName: 'Sample Traders',
address1: '12 CG Road',
location: 'Ahmedabad',
pincode: 380009,
),
buyer: Party(
gstin: '24BBBBB1111B1ZT',
legalName: 'Demo Electronics',
address1: '5 Ring Road',
location: 'Surat',
pincode: 395003,
),
items: const [
InvoiceItem(
description: 'Wireless Mouse',
hsnCode: '847160',
quantity: 10,
unit: 'NOS',
unitPrice: 500,
discount: 500,
gstRate: 18,
),
],
);
// 4. Check it before sending it anywhere.
final problems = invoice.validate();
print(problems.isEmpty ? 'No problems found.' : problems.join('\n'));
// 5. This JSON is what you send to the IRP (directly or through a GSP).
print(const JsonEncoder.withIndent(' ').convert(invoice.toJson()));
}