Skip to content

Instantly share code, notes, and snippets.

@mkazlauskas
Last active January 29, 2018 17:01
Show Gist options
  • Save mkazlauskas/02bd1fbf8c0915736b643ae83ec174ed to your computer and use it in GitHub Desktop.
Save mkazlauskas/02bd1fbf8c0915736b643ae83ec174ed to your computer and use it in GitHub Desktop.
API example
function scanOnce() {
// Make sure running in Zamok and this specific API is available
var autofill = window.Zamok && window.Zamok.API && window.Zamok.API.Autofill;
if (!autofill) return Promise.reject("Either not in Zamok or 'zamok-api-autofill' solution is not enabled");
// Enable and wait for a single scan. Returns parsed data.
return autofill.scan();
}
scanOnce()
.then(data => console.log('Card scan successful', data)) // Do something with parsed data object
// Data should look like:
// {firstNameDL: "John", lastNameDL: "Smith", ...}
.catch(e => console.warn('Failed to scan card', e); // Handle scan failure (e.g. retry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment