"All-in-one Rust library for PromptPay & EMVCo QR Codes"
No external dependencies & Cross-platform. You can use it anywhere!
This is a Rust port of maythiwat/promptparse
- Parse — PromptPay & EMVCo QR Code data strings into structs
- Generate — QR Code data from pre-made templates (PromptPay AnyID, PromptPay Bill Payment, TrueMoney, etc.)
- Manipulate — any values from parsed QR Code data and encode back into QR Code data
- Validate — checksum and data structure for known QR Code formats (Slip Verify API Mini QR)
Add this to your Cargo.toml:
[dependencies]
promptparse = "1.0.1"use promptparse::parse;
fn main() {
// Example data
let ppqr = parse("000201010211...", false, true).unwrap();
// Get Value of Tag ID '00'
let value = ppqr.get_tag_value("00", None).unwrap(); // Returns "01"
}use promptparse::{encode, tag, with_crc_tag};
fn main() {
// Example data
let data = vec![
tag("00", "01"),
tag("01", "11"),
// ...
];
// Set CRC Tag ID '63'
let result = with_crc_tag(&encode(&data), "63", true); // Returns "000201010211..."
}use promptparse::generate::{bill_payment, BillPaymentConfig};
fn main() {
let config = BillPaymentConfig {
biller_id: "1xxxxxxxxxxxx".to_string(),
amount: Some(300.0),
ref1: "INV12345".to_string(),
ref2: None,
ref3: None,
};
let payload = bill_payment(config).unwrap();
// TODO: Create QR Code from payload
}use promptparse::generate::{any_id, AnyIdConfig, ProxyType};
fn main() {
let config = AnyIdConfig {
proxy_type: ProxyType::Msisdn,
target: "0812223333".to_string(),
amount: Some(100.0),
};
let payload = any_id(config).unwrap();
// TODO: Create QR Code from payload
}use promptparse::generate::{true_money, TrueMoneyConfig};
fn main() {
let config = TrueMoneyConfig {
mobile_no: "08xxxxxxxx".to_string(),
amount: Some(10.0),
message: Some("Hello World!".to_string()),
};
let payload = true_money(config);
// TODO: Create QR Code from payload
}use promptparse::validate;
fn main() {
let data = validate::slip_verify("00550006000001...").unwrap();
println!("Sending Bank: {}", data.sending_bank);
println!("Transaction Ref: {}", data.trans_ref);
// TODO: Inquiry transaction from Bank Open API
}use promptparse::parse_barcode;
fn main() {
let bot_barcode = parse_barcode("|310109999999901\r...").unwrap();
let payload = bot_barcode.to_qr_tag30().unwrap();
// TODO: Create QR Code from payload
}The library uses Result<T, PromptParseError> for operations that can fail:
use promptparse::{parse, PromptParseError};
fn main() {
match parse("invalid_data", true, true) {
Some(qr) => {
println!("Parsed successfully: {:?}", qr);
}
None => {
println!("Failed to parse QR code");
}
}
}This Rust implementation is a faithful port of the excellent promptparse TypeScript/JavaScript library by Maythiwat Chomchuen. The original library has been thoroughly tested and is widely used in the Thai payment ecosystem.
All credit for the original design, implementation, and testing goes to the original author. This port aims to bring the same reliability and functionality to Rust developers.
- maythiwat/promptparse - Original TypeScript/JavaScript implementation
- phoomin2012/promptparse-php - PHP implementation
This project is MIT licensed (see LICENSE), maintaining the same license as the original work.