Last active
May 30, 2018 16:26
-
-
Save michoelchaikin/49effbd84a39313ad00e to your computer and use it in GitHub Desktop.
Accept credit cards by swiping in NetSuite using USB credit card reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Accept credit cards by swiping in NetSuite using USB credit card reader | |
* (http://www.ebay.com.au/sch/i.html?_nkw=Magnetic+Stripe+Swiper) | |
* | |
* To deploy: | |
* | |
* 1) Upload this file to File Cabinet | |
* 2) In your custom Sales Order form, add the script file (no need to associate with any events) | |
* 3) Add an 'Inline HTML' custom field to the form with default value: | |
* <a href="javascript:swipe_cc();">Swipe Credit Card</a> | |
* | |
* Version Date Author Remarks | |
* 1.00 15 May 2015 michoel | |
* | |
*/ | |
function swipe_cc() { | |
var card_data = window.prompt("Scan Card"); | |
// See http://en.wikipedia.org/wiki/ISO/IEC_7813 | |
var track1_regex = new RegExp("^%B([\\d]{1,19})\\^(.{2,26})\\^([\\d]{0,4}|\\^)([\\d]{0,3}|\\^).+"); | |
var track2_regex = new RegExp(";([\\d]{1,19})\\=(\\d{4}|\\=)"); | |
var track1_match = track1_regex.exec(card_data); | |
var track2_match = track2_regex.exec(card_data); | |
var number, name, expiry; | |
if(track1_match) { | |
number = track1_match[1]; | |
name = track1_match[2]; | |
expiry = track1_match[3]; | |
} else if (track2_match) { | |
number = track2_match[1]; | |
name = ""; | |
expiry = track2_match[2]; | |
} else { | |
window.alert('Could not read credit card data!'); | |
return; | |
} | |
expiry = expiry.substr(2, 2) + "/" + '20' + expiry.substr(0, 2); | |
nlapiSetFieldValue('ccName', name); | |
nlapiSetFieldValue('ccNumber', number); | |
nlapiSetFieldValue('ccExpireDate', expiry); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a specific place or way to upload this? My custom field isn't doing anything. I uploaded the JS file to the SupiteScripts folder.