Skip to content

Instantly share code, notes, and snippets.

@burnto
Created April 4, 2012 18:47
Show Gist options
  • Save burnto/2304664 to your computer and use it in GitHub Desktop.
Save burnto/2304664 to your computer and use it in GitHub Desktop.
Sample code using card.io PhoneGap plugin
<h1>Scan Example</h1>
<p><button id='scanBtn'>Scan now</button></p>
<script type="text/javascript">
function onDeviceReady() {
var onCardIOComplete = function(response) {
console.log("card.io scan result: " + response.card_number);
// response fields include card_type, redacted_card_number,
// card_number, expiry_month, expiry_year, cvv, zip
};
var onCardIOCancel = function() {
console.log("card.io scan cancelled");
};
var onCardIOCheck = function (canScan) {
console.log("card.io canScan? " + canScan);
var scanBtn = document.getElementById("scanBtn");
if (!canScan) {
scanBtn.innerHTML = "Manual entry";
}
scanBtn.onclick = function (e) {
window.plugins.card_io.scan(
"YOUR_APP_TOKEN_HERE",
{}, // set card.io options like collect_expiry, collect_cvv,
// collect_zip, shows_first_use_alert,
// disable_manual_entry_buttons
onCardIOComplete,
onCardIOCancel);
}
};
window.plugins.card_io.canScan(onCardIOCheck);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment