EmvCoQr

Struct EmvCoQr 

Source
pub struct EmvCoQr { /* private fields */ }

Implementations§

Source§

impl EmvCoQr

Source

pub fn new(payload: String, tags: Vec<TlvTag>) -> Self

Source

pub fn get_tag(&self, tag_id: &str, sub_tag_id: Option<&str>) -> Option<&TlvTag>

Source

pub fn get_tag_value( &self, tag_id: &str, sub_tag_id: Option<&str>, ) -> Option<&str>

Examples found in repository?
examples/basic_usage.rs (line 20)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    println!("PromptParse Rust Library Examples\n");
12
13    // Example 1: Parse QR Code
14    println!("1. Parsing QR Code:");
15    let qr_payload =
16        "00020101021229370016A0000006770101110113006680111111153037645802TH540520.15630442BE";
17    if let Some(qr) = parse(qr_payload, true, true) {
18        println!("   Parsed successfully!");
19        println!("   Tag count: {}", qr.get_tags().len());
20        if let Some(amount) = qr.get_tag_value("54", None) {
21            println!("   Amount: {amount}");
22        }
23    }
24
25    // Example 2: Generate PromptPay AnyID QR
26    println!("\n2. Generating PromptPay AnyID QR:");
27    let any_id_config = AnyIdConfig {
28        proxy_type: ProxyType::Msisdn,
29        target: "0812223333".to_string(),
30        amount: Some(100.50),
31    };
32    let any_id_qr = any_id(any_id_config)?;
33    println!("   Generated QR: {any_id_qr}");
34
35    // Example 3: Generate Bill Payment QR
36    println!("\n3. Generating Bill Payment QR:");
37    let bill_config = BillPaymentConfig {
38        biller_id: "1234567890123".to_string(),
39        amount: Some(500.0),
40        ref1: "CUSTOMER001".to_string(),
41        ref2: Some("INV001".to_string()),
42        ref3: None,
43    };
44    let bill_qr = bill_payment(bill_config)?;
45    println!("   Generated QR: {bill_qr}");
46
47    // Example 4: Generate TrueMoney QR
48    println!("\n4. Generating TrueMoney QR:");
49    let true_money_config = TrueMoneyConfig {
50        mobile_no: "0801111111".to_string(),
51        amount: Some(25.0),
52        message: Some("Coffee money".to_string()),
53    };
54    let true_money_qr = true_money(true_money_config);
55    println!("   Generated QR: {true_money_qr}");
56
57    // Example 5: Generate Slip Verify QR
58    println!("\n5. Generating Slip Verify QR:");
59    let slip_config = SlipVerifyConfig {
60        sending_bank: "014".to_string(),
61        trans_ref: "REF123456789".to_string(),
62    };
63    let slip_qr = slip_verify(slip_config);
64    println!("   Generated QR: {slip_qr}");
65
66    // Example 6: Generate BOT Barcode
67    println!("\n6. Generating BOT Barcode:");
68    let bot_config = BotBarcodeConfig {
69        biller_id: "099999999999990".to_string(),
70        ref1: "111222333444".to_string(),
71        ref2: Some("REF2".to_string()),
72        amount: Some(150.0),
73    };
74    let bot_code = bot_barcode(bot_config);
75    println!("   Generated Barcode: {bot_code}");
76
77    // Example 7: Parse and convert BOT Barcode
78    println!("\n7. Parsing and converting BOT Barcode:");
79    let barcode_payload = "|099999999999990\r111222333444\r\r0";
80    if let Some(barcode) = parse_barcode(barcode_payload) {
81        println!("   Parsed barcode successfully!");
82        println!("   Biller ID: {}", barcode.biller_id);
83        println!("   Ref1: {}", barcode.ref1);
84
85        if let Ok(qr_equivalent) = barcode.to_qr_tag30() {
86            println!("   Converted to QR: {qr_equivalent}");
87        }
88    }
89
90    // Example 8: Validate Slip Verify QR
91    println!("\n8. Validating Slip Verify QR:");
92    let slip_payload = "004100060000010103014022000111222233344ABCD125102TH910417DF";
93    if let Some(slip_data) = validate::slip_verify(slip_payload) {
94        println!("   Valid slip verify QR!");
95        println!("   Bank: {}", slip_data.sending_bank);
96        println!("   Transaction Ref: {}", slip_data.trans_ref);
97    }
98
99    println!("\nAll examples completed successfully!");
100    Ok(())
101}
Source

pub fn get_tags(&self) -> &[TlvTag]

Examples found in repository?
examples/basic_usage.rs (line 19)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    println!("PromptParse Rust Library Examples\n");
12
13    // Example 1: Parse QR Code
14    println!("1. Parsing QR Code:");
15    let qr_payload =
16        "00020101021229370016A0000006770101110113006680111111153037645802TH540520.15630442BE";
17    if let Some(qr) = parse(qr_payload, true, true) {
18        println!("   Parsed successfully!");
19        println!("   Tag count: {}", qr.get_tags().len());
20        if let Some(amount) = qr.get_tag_value("54", None) {
21            println!("   Amount: {amount}");
22        }
23    }
24
25    // Example 2: Generate PromptPay AnyID QR
26    println!("\n2. Generating PromptPay AnyID QR:");
27    let any_id_config = AnyIdConfig {
28        proxy_type: ProxyType::Msisdn,
29        target: "0812223333".to_string(),
30        amount: Some(100.50),
31    };
32    let any_id_qr = any_id(any_id_config)?;
33    println!("   Generated QR: {any_id_qr}");
34
35    // Example 3: Generate Bill Payment QR
36    println!("\n3. Generating Bill Payment QR:");
37    let bill_config = BillPaymentConfig {
38        biller_id: "1234567890123".to_string(),
39        amount: Some(500.0),
40        ref1: "CUSTOMER001".to_string(),
41        ref2: Some("INV001".to_string()),
42        ref3: None,
43    };
44    let bill_qr = bill_payment(bill_config)?;
45    println!("   Generated QR: {bill_qr}");
46
47    // Example 4: Generate TrueMoney QR
48    println!("\n4. Generating TrueMoney QR:");
49    let true_money_config = TrueMoneyConfig {
50        mobile_no: "0801111111".to_string(),
51        amount: Some(25.0),
52        message: Some("Coffee money".to_string()),
53    };
54    let true_money_qr = true_money(true_money_config);
55    println!("   Generated QR: {true_money_qr}");
56
57    // Example 5: Generate Slip Verify QR
58    println!("\n5. Generating Slip Verify QR:");
59    let slip_config = SlipVerifyConfig {
60        sending_bank: "014".to_string(),
61        trans_ref: "REF123456789".to_string(),
62    };
63    let slip_qr = slip_verify(slip_config);
64    println!("   Generated QR: {slip_qr}");
65
66    // Example 6: Generate BOT Barcode
67    println!("\n6. Generating BOT Barcode:");
68    let bot_config = BotBarcodeConfig {
69        biller_id: "099999999999990".to_string(),
70        ref1: "111222333444".to_string(),
71        ref2: Some("REF2".to_string()),
72        amount: Some(150.0),
73    };
74    let bot_code = bot_barcode(bot_config);
75    println!("   Generated Barcode: {bot_code}");
76
77    // Example 7: Parse and convert BOT Barcode
78    println!("\n7. Parsing and converting BOT Barcode:");
79    let barcode_payload = "|099999999999990\r111222333444\r\r0";
80    if let Some(barcode) = parse_barcode(barcode_payload) {
81        println!("   Parsed barcode successfully!");
82        println!("   Biller ID: {}", barcode.biller_id);
83        println!("   Ref1: {}", barcode.ref1);
84
85        if let Ok(qr_equivalent) = barcode.to_qr_tag30() {
86            println!("   Converted to QR: {qr_equivalent}");
87        }
88    }
89
90    // Example 8: Validate Slip Verify QR
91    println!("\n8. Validating Slip Verify QR:");
92    let slip_payload = "004100060000010103014022000111222233344ABCD125102TH910417DF";
93    if let Some(slip_data) = validate::slip_verify(slip_payload) {
94        println!("   Valid slip verify QR!");
95        println!("   Bank: {}", slip_data.sending_bank);
96        println!("   Transaction Ref: {}", slip_data.trans_ref);
97    }
98
99    println!("\nAll examples completed successfully!");
100    Ok(())
101}
Source

pub fn get_payload(&self) -> &str

Source

pub fn validate(&self, crc_tag_id: &str) -> bool

Trait Implementations§

Source§

impl Clone for EmvCoQr

Source§

fn clone(&self) -> EmvCoQr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EmvCoQr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.