Documentation Index Fetch the complete documentation index at: https://persian-tools.usestrict.dev/llms.txt
Use this file to discover all available pages before exploring further.
Bill Validation
Parse and validate Iranian utility bills (قبض) including electricity, water, gas, and telecommunication bills.
Basic Usage
import { Bill } from "@persian-tools/persian-tools" ;
const bill = new Bill ({
billId: "1234567890123" ,
paymentId: "1234567890123" ,
});
const result = bill . getResult ();
console . log ( result );
// {
// isValid: true,
// billType: 'برق',
// amount: 50000,
// ...
// }
API Reference
Constructor
Bill identifier (شناسه قبض)
Payment identifier (شناسه پرداخت)
Methods
getResult()
Get parsed bill information.
Whether the bill is valid
Type of bill (برق, آب, گاز, تلفن)
getBarcode()
Get the barcode representation of the bill.
Examples
Bill Payment Processing
import { Bill } from "@persian-tools/persian-tools" ;
const processBillPayment = ( billId : string , paymentId : string ) => {
const bill = new Bill ({ billId , paymentId });
const result = bill . getResult ();
if ( ! result . isValid ) {
throw new Error ( "اطلاعات قبض نامعتبر است" );
}
return {
type: result . billType ,
amount: result . amount ,
barcode: bill . getBarcode (),
};
};
Bill Validator
import { Bill } from "@persian-tools/persian-tools" ;
const validateBill = ( billData : { billId : string ; paymentId : string }) => {
try {
const bill = new Bill ( billData );
const result = bill . getResult ();
return {
isValid: result . isValid ,
info:
result . isValid ?
{
type: result . billType ,
amount: result . amount ,
}
: null ,
};
} catch ( error ) {
return { isValid: false , error: "خطا در پردازش قبض" };
}
};
Use Cases
Process utility bill payments: const payBill = ( billId : string , paymentId : string ) => {
const bill = new Bill ({ billId , paymentId });
const result = bill . getResult ();
if ( result . isValid ) {
// Process payment
}
};
Scan and validate bills: const scanBill = ( barcode : string ) => {
// Parse barcode to get billId and paymentId
const bill = new Bill ({ billId , paymentId });
return bill . getResult ();
};
Type Definition
interface BillConstructor {
billId : string ;
paymentId : string ;
}
interface BillResult {
isValid : boolean ;
billType ?: string ;
amount ?: number ;
}
class Bill {
constructor ( options : BillConstructor );
getResult () : BillResult ;
getBarcode () : string ;
}