In this article, we’re going to cover how to easily parse credit card data from a magnetic stripe reader using JavaScript.
This is particularly useful when you want to put your website on a kiosk and automatically populate the credit card fields when the customer swipes their card.
By automatically populating the credit card payment fields, you reduce the potential for user error and speed up the checkout process.
The following fields are contained in the track data on most credit cards and can be easily parsed from the credit card data using JavaScript when the customer swipes their credit card.
- Cardholder’s Name
- Card Number
- Expiration Date
All you need to get started is KioskSimple and an unencrypted Magtek USB HID credit card reader like the Magtek Dynamag.
The solution outlined in this article doesn’t require any code changes to your website. This is especially beneficial if you’re using a 3rd part POS which you can’t modify.
The reason no code changes are required to your website is because KioskSimple makes it possible to “inject” a JavaScript file, which we’ll explain in a moment.
Parse credit card data in KioskSimple
The first step is to download and install the free demo of KioskSimple.
Customize the script to your payment form
Next, we need to download the credit card reader JavaScript code example and customize the credit card script to work with your payment form.
You’ll need to make some minor changes in order to make the script reference the credit card fields on your payment form.
This example JavaScript file “listens” for the card swiped event, then parses the credit card track data and automatically populates the appropriate fields on the payment form.
In the OnCardSwiped function you’ll need to change all the GetElementByID calls to reference the ids of your payment fields.
For example, your credit card number field might look like the following:
<input id="ccNum" maxlength="50" type="text" />
So you would need to change the field id in your JavaScript file from this:
document.getElementById("CardNumber")
to this:
document.getElementById("ccNum")
If you have any questions please feel free to contact us and we’ll be glad to help.
Configure KioskSimple to inject your credit card script:
- Copy the file CreditCardScript.js from the code example you downloaded to the folder “C:\ProgramData\RedSwimmer\KioskSimple”
- Start the KioskSimple configuration app.
- Select the BROWSER left menu
- Select JAVASCRIPT
- Under JavaScript Injection URL enter the path of the credit card script “file:///C:/ProgramData/RedSwimmer/KioskSimple/CreditCardScript.js”. You can also drag the JavaScript file into a browser like Chrome to get the local file path.
- Save your settings
Configure KioskSimple to run your website:
- Select the BROWSER left menu
- Select BROWSER SETTINGS
- Under Start-up Web Page enter the URL of your website to run in kiosk mode
- Save your settings
Install the Magtek Credit Card Reader Plugin
- Select the PLUGIN STORE left menu
- Select the Available plugins tab
- Download the Magtek Credit Card Reader Plugin
- You’ll be prompted to restart the configuration app after which the new CARD READERS menu item will appear
Configure the Magtek Credit Card Reader Plugins
- Select CARD READERS from the left menu
- Select the Magtek credit card reader and press CONFIGURE
- Enable the device and press DETECT to confirm it’s properly configured. The device must be attached to a USB port and configured in HID mode (not keyboard emulation mode). If the device is not detected it’s probably not in HID Mode. You can use this app from Magtek to reconfigure the card reader to HID Mode
- Save your settings and close the KioskSimple configuration app
Start KioskSimple in Test Mode
If you swipe your credit card on your payment page the following fields should be automatically populated…
- Cardholder’s Name
- Card Number
- Card Expiration
If they’re not then you probably either didn’t modify the JavaScript example correctly, or didn’t inject it. As a sanity check try adding some alerts() to confirm the script is running.
Got Questions?
Please contact us if you need help customizing the script to match your payment form.
We’re dedicated to making your next kiosk project a success and are happy to hold your hand through the hardware integration.