1use std::borrow::Cow;
9
10use emv_qrcps::EmvEncoder;
11
12mod json_payload;
13pub mod qr_dinamico;
14pub mod qr_estatico;
15
16#[derive(EmvEncoder, Clone, Debug)]
17pub struct AdditionalData<'a> {
18 #[encoder(id = "05")]
19 txid: Cow<'a, str>,
22}
23
24#[derive(EmvEncoder, Clone, Debug)]
25pub struct MerchantAccountInformation<'a> {
26 #[encoder(id = "00")]
27 pub gui: Cow<'a, str>,
29
30 #[encoder(id = "21")]
31 pub instituicao: Cow<'a, str>,
33
34 #[encoder(id = "22")]
35 pub tipo_conta: Cow<'a, str>,
37
38 #[encoder(id = "23")]
39 pub agencia: Cow<'a, str>,
41
42 #[encoder(id = "24")]
43 pub conta: Cow<'a, str>,
45}
46
47#[derive(EmvEncoder, Clone, Debug)]
48struct PixSchema<'a> {
49 #[encoder(id = "00")]
50 pub format_indicator: Cow<'a, str>,
52
53 #[encoder(id = "01")]
54 pub point_of_initiation_method: Option<Cow<'a, str>>,
56
57 #[encoder(id = "26")]
58 pub merchant_account_information: MerchantAccountInformation<'a>,
59
60 #[encoder(id = "52")]
61 pub merchant_category_code: Cow<'a, str>,
62 #[encoder(id = "53")]
63 pub transaction_currency: Cow<'a, str>,
64 #[encoder(id = "54")]
65 pub transaction_amount: Option<Cow<'a, str>>,
66
67 #[encoder(id = "58")]
68 pub country_code: Cow<'a, str>,
70
71 #[encoder(id = "59")]
72 pub merchant_name: Cow<'a, str>,
74
75 #[encoder(id = "60")]
76 pub merchant_city: Cow<'a, str>,
78
79 #[encoder(id = "61")]
80 pub postal_code: Option<Cow<'a, str>>,
82 }
85
86#[cfg(test)]
87mod tests {
88 use super::*;
89
90 fn sample() -> &'static str {
91 "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.\
92 OUTRO011001234567895204000053039865406123.455802BR5917NOME DO \
93 RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38"
94 }
95
96 #[test]
97 fn t_() {
98 let pix_schema_read = PixSchema::from_str(sample());
99
100 println!("schema: {:#?}", pix_schema_read);
101
102 assert_eq!(pix_schema_read.serialize_with_src(), sample())
103 }
104}