+ Tap the scan button to lauch the barcode scanner and scan the barcode on a + driver's license. +
++ Note: The license data should be encoded as per the AAMVA + specification and stored in a PDF417 barcode in order for the parser to be + able to parse it. +
+{aamvaResult}+ + +
{error}+ + diff --git a/DriverLicenseParser/force-app/main/default/lwc/parserDemo/parserDemo.js b/DriverLicenseParser/force-app/main/default/lwc/parserDemo/parserDemo.js new file mode 100644 index 0000000..4acbb9f --- /dev/null +++ b/DriverLicenseParser/force-app/main/default/lwc/parserDemo/parserDemo.js @@ -0,0 +1,35 @@ +import { LightningElement } from "lwc"; +import { getBarcodeScanner } from "lightning/mobileCapabilities"; +import { AAMVAParser } from "c/aamvaParser"; + +export default class ParserDemo extends LightningElement { + aamvaResult; + error; + + scanBarcode() { + // reset the states before starting to scan + this.aamvaResult = undefined; + this.error = undefined; + + const myScanner = getBarcodeScanner(); + + if (myScanner && myScanner.isAvailable()) { + // AAMVA data is only stored in PDF417 barcodes + let scanningOptions = { barcodeTypes: ["pdf417"] }; + myScanner + .beginCapture(scanningOptions) + .then((barcode) => { + const result = AAMVAParser.parseBarcode(barcode.value); + this.aamvaResult = JSON.stringify(result, null, 2); + }) + .catch((error) => { + this.error = JSON.stringify(error, null, 2); + }) + .finally(() => { + myScanner.endCapture(); + }); + } else { + this.error = "Problem initiating scanner. Are you using a mobile device?"; + } + } +} diff --git a/DriverLicenseParser/force-app/main/default/lwc/parserDemo/parserDemo.js-meta.xml b/DriverLicenseParser/force-app/main/default/lwc/parserDemo/parserDemo.js-meta.xml new file mode 100644 index 0000000..8768d76 --- /dev/null +++ b/DriverLicenseParser/force-app/main/default/lwc/parserDemo/parserDemo.js-meta.xml @@ -0,0 +1,17 @@ + +