Module bill

Source
Expand description

Iranian Utility Bill tools (bill Cargo feature).

The structure of Bill/Payment IDs and Barcode is based on مستندات طرح هماهنگ پرداخت الکترونیکی قبوض - کمیسیون انفورماتیک بانک‌ها

§Example
§Load from Barcode

A barcode must be 26 characters
if checksum of Bill or Payment ID separately or checksum of them together be invalid Result will return Err::BillError

use rust_persian_tools::bill::{Bill, BillID, PaymentID};
use rust_persian_tools::bill::BillType;
use rust_persian_tools::bill::CurrencyType;
use std::str::FromStr;

// This checks both bill/payment IDs and their relation match (checksum2)
let bill = Bill::from_str("77483178001420000001770160").unwrap();
assert_eq!(bill.get_bill_type(), BillType::Tel);   // Fixed Landline
assert_eq!(bill.get_bill_id(), "7748317800142");
assert_eq!(bill.get_payment_id(), "1770160");
assert_eq!(bill.amount(CurrencyType::Rials), 17000);
§Load from Bill and Payment IDs

Each can be any string with or without leading zeros
if checksum of Bill or Payment ID separately or checksum of them together be invalid Result will return Err::BillError

use rust_persian_tools::bill::{Bill, BillID, PaymentID};
use rust_persian_tools::bill::CurrencyType;
use rust_persian_tools::bill::BillType;
use std::str::FromStr;

let bill_id = BillID::from_str("7748317800142").unwrap();
let payment_id = PaymentID::from_str("1770160").unwrap();
let bill = Bill::new(bill_id, payment_id).unwrap();
assert_eq!(bill.get_bill_type(), BillType::Tel);   // Fixed Landline
assert_eq!(bill.get_bill_id(), "7748317800142");
assert_eq!(bill.get_payment_id(), "1770160");
assert_eq!(bill.amount(CurrencyType::Rials), 17000);
§Generate IDs from scratch

This will calculate checksums automatically

use rust_persian_tools::bill::{Bill, BillID, PaymentID};
use rust_persian_tools::bill::CurrencyType;
use rust_persian_tools::bill::BillType;

let bill_id = BillID::new("77483178", "001", BillType::Tel).unwrap();
let payment_id = PaymentID::new(17, 7, 1, &bill_id).unwrap();  // Thousands are omitted from amount
let bill = Bill::new(bill_id, payment_id).unwrap();
assert_eq!(bill.get_bill_type(), BillType::Tel);   // Fixed Landline
assert_eq!(bill.get_bill_id(), "7748317800142");
assert_eq!(bill.get_payment_id(), "1770160");
assert_eq!(bill.amount(CurrencyType::Rials), 17000);
assert_eq!(bill.amount(CurrencyType::Tomans), 1700);
assert_eq!(bill.to_string(), "77483178001420000001770160");

Structs§

Bill
Container for Both Bill and Payment IDs
You must use this type to extract all information about the bill
BillID
Bill ID Structure based on مستندات طرح هماهنگ پرداخت الکترونیکی قبوض - کمیسیون انفورماتیک بانک‌ها \
PaymentID
Payment Structure based on مستندات طرح هماهنگ پرداخت الکترونیکی قبوض - کمیسیون انفورماتیک بانک‌ها \

Enums§

BillError
BillType
Values Are based on the مستندات طرح هماهنگ پرداخت الکترونیکی قبوض - کمیسیون انفورماتیک بانک‌ها
It is possible to use BillType directly or from integer value:
CurrencyType