Using with Scriptel Scanner and it has multi-character prefix.
JamoCA opened this issue · 7 comments
I'm using a Scriptel MagStripe 1X5 LCD Pad and it supports EasyScript:
http://www.scriptel.com/products/magstripe-1x5-lcd-signature-pad
http://www.scriptel.com/developers/easyscript-api
This is what I had been using for credit cards. (Your example only works with very specific student IDs. Please include more samples.)
^\%B(\d{13,16})\^([A-Z ]+)\/([A-Z ]+)\^(\d{2})(\d{2}).*?$
I modified the regex to detect "!STCARD A " follow by the card code "%B".
var pattern = /^(\!STCARD A \%B|\%B)(\d{13,16})\^([A-Z ]+)\/([A-Z ]+)\^(\d{2})(\d{2}).*?$/;
This regex works when I test parsed scan values using http://regex101.com/, but it resulted in 2 page scrolls (caused by the space characters) and doesn't work due to the current logic to scan for only a single character code (to switch from IDLE to PENDING state) and then scan for a single character to determine whether to continue scanning or not.
I would really prefer to keep using your script in the case that a non-Scriptel magstripe device is used.
(Side note: I'm also using Stripe's payment library to determine if the card # is valid and determine card type. This is a great library to use with cardswipe. https://github.com/stripe/jquery.payment )
I'm having more luck with this regex pattern:
var pattern = /^(\!S|\%B)(\d{13,16})\^([A-Z ]+)\/([A-Z ]+)\^(\d{2})(\d{2}).*?$/;
But still get weird double scroll downs due to the two (2) spaces.
If I understand what's going on, the Scriptel Scanner puts a prefix ahead of the raw card data. Currently the plugin won't act on the !STCARD A and that will just get passed through to your web page. The plugin is picking up starting at the %B.
The plugin is intended just for the "plain" card readers that don't transmit a prefix. If you want your site to work with either kind, right now the plugin doesn't do that. It may be possible to modify it to enter a PREFIX state when it sees a !, and then switch to PENDING when it sees the %. Is the prefix always the same "!STCARD A " sequence, or does it ever change? And if it varies, do you care what it is?
Their prefix is always "!STCARD A". I've spoken with the vendor and there's nothing they can do to configure the reader to not send the prefix/sentinel, but you can include their "scriptel-easyscript.js" library and add the following code to remove the prefix from the buffer before it is passed to the cardswipe plugin.
scriptel = new ScriptelEasyScript();
scriptel.cardSwipeProtocol.passThrough = true;
scriptel.addSignatureListener(document);
$.cardswipe({});
I'm just curious if other card readers add an extra prefix. (We have a regular "plain" magstripe reader too, but are upgrading to their magstripe/signature pad combo.)
I pushed a new branch called "prefix" just now. This will consume the characters from ! until %. Please try this with your reader. Update your configuration to include the prefix character:
$.cardswipe({ prefixCharacter: '!' });
Note that it's just the single ! character, and not the full !STCARD... string. The actual prefix will get discarded. My ability to test is limited, since I don't have your reader, but this should work with Scriptel and still work with a plain reader, too. The only caveat is that when you specify a prefix character, to actually type it into a form field, you'll have to type it twice in quick succession, just like with %.
I disabled the easyscript API library and tested solely with the cardswipe library and have verified that it works. (I don't expect the "!" character to be used during normal data entry unless it's entered in an staff-entered comment.) Thanks!
Thanks for reporting back. I'll update the readme file, and merge into master.
The only minor issue I'm encountering now is with signatures returning a "%" in the raw buffer data. When parsing, I display a visual cue to indicate invalid cards. Some, but not all, signatures trigger it when a "%" is present. NOTE:This is not an issue with the cardswipe library, but I'm exploring the best way to deal with it.
Current solution: Card = only 1 "%" character, at least 1 separator "^", and at least one "?" sentinel to comply with ISO/IEC 7813 requirements.
function cardParser(rawData) {
if (rawData.indexOf('%',1) | !rawData.indexOf('^') | !rawData.indexOf('?')){
return;
}
...
}