emvqrcode 1.0.0 emvqrcode: ^1.0.0 copied to clipboard
a flutter package for decode and encode emv QR code
import 'package:emvqrcode/emvqrcode.dart';
void main(List<String> args) {
/**
* generate emv QR code
*/
final emv = EMVQR();
emv.setPayloadFormatIndicator("00");
emv.setPointOfInitiationMethod("12");
/// merchant account information
final mAccountInfo = MerchantAccountInformation();
mAccountInfo.setGloballyUniqueIdentifier("IT");
mAccountInfo.addPaymentNetworkSpecific(id: "01", value: "abc");
mAccountInfo.addPaymentNetworkSpecific(id: "02", value: "def");
emv.addMerchantAccountInformation(id: "03", value: mAccountInfo);
final mAccountInfo2 = MerchantAccountInformation();
mAccountInfo2.setGloballyUniqueIdentifier("IT");
mAccountInfo2.addPaymentNetworkSpecific(id: "01", value: "abc");
mAccountInfo2.addPaymentNetworkSpecific(id: "02", value: "def");
emv.addMerchantAccountInformation(id: "04", value: mAccountInfo2);
final additionalData = AdditionalDataFieldTemplate();
additionalData.setBillNumber("0qwea");
additionalData.setMerchantTaxID("tax id");
additionalData.setMerchantChannel("cha");
additionalData.addRfuForEMVCo(id: "12", value: "00");
additionalData.addRfuForEMVCo(id: "13", value: "13");
additionalData.addPaymentSystemSpecific(id: "50", value: "123");
additionalData.addPaymentSystemSpecific(id: "51", value: "123");
emv.setAdditionalDataFieldTemplate(additionalData);
final mInfoLang = MerchantInformationLanguageTemplate();
mInfoLang.setLanguagePreferencer("LA");
mInfoLang.setMerchantCity("Vientaine");
mInfoLang.setMerchantName("MW");
mInfoLang.addRfuForEMVCo(id: "03", value: "asfg");
mInfoLang.addRfuForEMVCo(id: "04", value: "asfg");
emv.setMerchantInformationLanguageTemplate(mInfoLang);
emv.addRfuForEMVCo(id: "65", value: "bbc");
emv.addRfuForEMVCo(id: "66", value: "bbb");
final unreserved1 = UnreservedTemplate();
unreserved1.setGloballyUniqueIdentifier("abs");
unreserved1.addContextSpecificData(id: "01", value: "qw12");
unreserved1.addContextSpecificData(id: "02", value: "qw12");
emv.addUnreservedTemplate(id: "89", value: unreserved1);
// encode data
final emvEncode = EMVMPM.encode(emv);
print("result -------> ${emvEncode.toJson()}");
// result -------> {emvqr: 00020001021203200002IT0103abc0203def04200002IT0103abc0203def625201050qwea1006tax id1103cha1202001302135003123510312364410002LA0102MW0209Vientaine0304asfg0404asfg6503bbc6603bbb89230003abs0104qw120204qw126304735A, error: null}
/**
* decode emv qr code
*/
// final emvqrcode =
// "00020001021203200002IT0103abc0203def04200002IT0103abc0203def625201050qwea1006tax id1103cha1202001302135003123510312364410002LA0102MW0209Vientaine0304asfg0404asfg6503bbc6603bbb89230003abs0104qw120204qw126304735A";
// final emvDecode = EMVMPM.decode(emvqrcode);
// print("result -------> ${emvDecode.toJson()}");
/**
* decode wrong emv qr code
*
* check crc checksum qr code
*/
String emvQrcode =
"00020101021138670016A00526628466257701082771041802030010324ZPOSUALNJBWWVYSEIRIESGFE6304D1B9";
final emvdecode = EMVMPM.decode(emvQrcode);
print("result ------> ${emvdecode.toJson()}");
//result ------> {emvqr: null, error: {type: EmvErrorType.verifyqrErr, message: The emv data was wrong}}
/**
* decode not emv qr code
*/
String notEmvQrcode = "https://laoitdev.com";
final emvDecode = EMVMPM.decode(notEmvQrcode);
print("result ------> ${emvDecode.toJson()}");
//result ------> {emvqr: null, error: {type: EmvErrorType.verifyqrErr, message: The emv data was wrong}}
}