Unofficial Rust SDK for Bakong KHQR
- QR Code Generation (Individual & Merchant accounts)
- QR Code Decoding
- CRC16 Verification
- Bakong API Integration
- Support for KHR and USD currencies
Add to your Cargo.toml:
[dependencies]
bakong-khqr = "0.1.0"use bakong_khqr::{BakongKHQR, IndividualInfo};
let khqr = BakongKHQR::new("your_token");
let info = IndividualInfo::builder()
.bakong_account_id("user@bank")
.merchant_name("Coffee Shop")
.merchant_city("Phnom Penh")
.amount(10000.0)
.build()
.unwrap();
let result = khqr.generate_qr(info).unwrap();
println!("QR: {}", result.qr);
println!("MD5: {}", result.md5);Run the examples:
# QR Generation
cargo run --example generate_qr --features rustls-tls
# QR Verification
cargo run --example verify_qr --features rustls-tls
# QR Decoding
cargo run --example decode_qr --features rustls-tls
# API - Check Account (requires token)
BAKONG_TOKEN=your_token cargo run --example api_check_account --features rustls-tls
# API - Check Transaction (requires token)
BAKONG_TOKEN=your_token cargo run --example api_check_transaction --features rustls-tls// Individual QR
let info = IndividualInfo::builder()
.bakong_account_id("user@bank")
.merchant_name("Shop Name")
.merchant_city("Phnom Penh")
.currency("KHR") // or "USD"
.amount(10000.0) // optional, omit for static QR
.build()
.unwrap();
let result = khqr.generate_qr(info).unwrap();
// Merchant QR
let info = MerchantInfo::builder()
.bakong_account_id("merchant@bank")
.merchant_id("MERCHANT001")
.acquiring_bank("ABA Bank")
.merchant_name("Store Name")
.amount(50.00)
.build()
.unwrap();
let result = khqr.generate_merchant_qr(info).unwrap();use bakong_khqr::{KHQRDecoder, verify_crc};
// Quick verification
let (is_valid, expected, actual) = verify_crc(qr_string);
// Detailed verification
let result = KHQRDecoder::verify(qr_string).unwrap();
if result.is_valid {
println!("Valid QR code");
}use bakong_khqr::KHQRDecoder;
let decoded = KHQRDecoder::decode(qr_string).unwrap();
println!("Merchant: {}", decoded.merchant_name);
println!("Amount: {:?}", decoded.amount);
println!("Currency: {}", decoded.currency);// Check if Bakong account exists
let response = khqr.check_bakong_account("user@bank").await?;
// Check transaction by MD5
let response = khqr.check_transaction_by_md5(md5_hash).await?;
// Generate payment deeplink
let response = khqr.generate_deeplink(
qr_string,
SourceInfo {
app_name: "My App".to_string(),
app_icon_url: None,
app_deep_link_callback: None,
},
).await?;let khqr = BakongKHQR::new("sandbox_token");use bakong_khqr::BakongConfig;
let khqr = BakongKHQR::with_config(
BakongConfig::production("production_token")
);let khqr = BakongKHQR::with_config(
BakongConfig::sandbox("token")
.with_base_url("http://localhost:8080")
);| Environment | URL |
|---|---|
| Sandbox | https://sit-api-bakong.nbc.gov.kh |
| Production | https://api-bakong.nbc.gov.kh |
- A Bakong API token
- Register at https://api-bakong.nbc.gov.kh/ for sandbox access
- Contact Bakong for production access
MIT License - see LICENSE for details.
Contributions welcome! Please open an issue or PR on GitHub