| Crates.io | qris-gen |
| lib.rs | qris-gen |
| version | 0.1.0 |
| created_at | 2026-01-20 10:25:59.827274+00 |
| updated_at | 2026-01-20 10:25:59.827274+00 |
| description | A Rust library for generating dynamic QRIS (Quick Response Code Indonesian Standard) with custom amounts and QR code image generation |
| homepage | https://github.com/ardipc/qris-gen |
| repository | https://github.com/ardipc/qris-gen |
| max_upload_size | |
| id | 2056281 |
| size | 59,251 |
A Rust library for generating dynamic QRIS (Quick Response Code Indonesian Standard) with custom amounts and QR code image generation.
Add this to your Cargo.toml:
[dependencies]
qris-gen = "0.1.0"
Or use cargo add:
cargo add qris-gen
use qris_gen::{Qris, generate_qr_base64};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Your static QRIS code
let static_qr = "00020101021126610014COM.GO-JEK.WWW01189360091430525747800210G0525747800303UMI51440014ID.CO.QRIS.WWW0215ID10264726320860303UMI5204549953033605802ID5920Titip Biyung, Grosir6008SURABAYA61056024562070703A016304091D";
// Generate dynamic QRIS with custom amount
let dynamic_qr = Qris::from_static(static_qr)?
.set_dynamic()
.amount(50000)? // Set amount to Rp 50.000
.build();
println!("Dynamic QRIS: {}", dynamic_qr);
Ok(())
}
use qris_gen::{Qris, generate_qr_base64, generate_qr_base64_with_size};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let static_qr = "00020101021126610014COM.GO-JEK.WWW...";
let dynamic_qr = Qris::from_static(static_qr)?
.set_dynamic()
.amount(100000)?
.build();
// Generate QR code with default size
let qr_base64 = generate_qr_base64(&dynamic_qr)?;
println!("QR Code Base64: {}", qr_base64);
// Generate QR code with custom size (512x512)
let qr_base64_large = generate_qr_base64_with_size(&dynamic_qr, 512)?;
// Use in HTML
// <img src="data:image/png;base64,{qr_base64_large}" />
Ok(())
}
use qris_gen::{Qris, generate_qr_base64_with_size, QrisError};
fn create_payment_qr(
static_qris: &str,
amount: u64
) -> Result<String, QrisError> {
// Convert to dynamic QRIS with amount
let dynamic_qris = Qris::from_static(static_qris)?
.set_dynamic()
.amount(amount)?
.build();
// Generate QR code image as base64
let qr_image = generate_qr_base64_with_size(&dynamic_qris, 512)?;
Ok(qr_image)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let static_qr = "00020101021126610014COM.GO-JEK.WWW...";
// Create payment QR for Rp 75.000
let payment_qr = create_payment_qr(static_qr, 75000)?;
println!("Payment QR Code generated successfully!");
println!("Base64 length: {} characters", payment_qr.len());
Ok(())
}
QrisMain struct for handling QRIS operations.
from_static(qr: &str) -> Result<Self, QrisError> - Parse a static QRIS stringset_dynamic(self) -> Self - Convert to dynamic QRISamount(self, amount: u64) -> Result<Self, QrisError> - Set transaction amountbuild(self) -> String - Build the final QRIS string with CRC checksumgenerate_qr_base64(data: &str) -> Result<String, QrisError> - Generate QR code with default sizegenerate_qr_base64_with_size(data: &str, size: u32) -> Result<String, QrisError> - Generate QR code with custom sizeuse qris_gen::QrisError;
match Qris::from_static(invalid_qr) {
Ok(qris) => println!("Valid QRIS"),
Err(QrisError::InvalidFormat) => println!("Invalid QRIS format"),
Err(QrisError::MissingTag(tag)) => println!("Missing tag: {}", tag),
Err(QrisError::InvalidAmount) => println!("Invalid amount (must be > 0)"),
Err(e) => println!("Error: {}", e),
}
This library implements the QRIS (Quick Response Code Indonesian Standard) specification:
crc - For CRC-16 checksum calculationqrcode - For QR code generationimage - For image processingbase64 - For base64 encodingthiserror - For error handlingCheck the examples/ directory for more usage examples:
cargo run --example basic
cargo run --example with_image
Run tests with:
cargo test
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
This library is for educational and development purposes. Make sure to comply with all relevant regulations and standards when implementing payment systems.
Made with ❤️ for Indonesian developers