Class: GrabbaMagstripe

GrabbaMagstripe

Access this class via grabba.magstripe

Constructor

new GrabbaMagstripe()

Access Grabba magnetic stripe reading capabilities via grabba.magstripe

Members

preferences :GrabbaMagstripePreferences

Grabba magstripe preference identifiers.
Type:

Methods

isSupported(onSuccess, onError)

Determines if the currently connected Grabba supports magnetic stripe reading functionality.
Parameters:
Name Type Description
onSuccess function Called on success with the following parameters:
{boolean} Boolean indicating if GrabbaMagstripe is supported.
onError function Called on error with the following parameters:
{String} error description.
Example
//Button to check if the connected Grabba supports magnetic stripe reading functionality.
 <button onclick="grabba.magstripe.isSupported(function(supported){
 alert('Grabba magstripe supported is ' + supported);
 },
 function(errorString) {
     alert('on error ' + errorString);
 });">Is magstripe supported?</button>

registerCallback(callback, onError)

Register callbacks for magnetic stripe reader related events.
If no callbacks are passed to this function, all present callbacks will be cleared.
Parameters:
Name Type Description
callback Object An object which implements the following functions:
readEvent : function(magstripeData){}
Called when the magnetic stripe is read.
Returns a String for each track.

rawReadEvent : function(magstripeData){}
Called when a raw magnetic stripe is read.
Returns raw data as an integer array.

The returned object contains properties as follows:
magstripeData.track1 Magnetic stripe track 1
magstripeData.track2 Magnetic stripe track 2
magstripeData.track3 Magnetic stripe track 3
If the track property is: 1. A zero length string - this indicates that the track was not present on the card or the track data was present on the card but failed verification (was not read correctly).
2. A non-zero length array - this is the actual track data which was read correctly with no errors.
onError function Called on error with the following parameters:
{String} error description.
Example
//An example of an implemented Magnetic stripe callback is as follows:
grabba.magstripe.registerCallback(magstripeCallback, onError);
 var rawReadCallback = function(magstripeData) {
     //Handle processing raw magstripe data here
 };

 var magstripeCallback = {
     //Functions may also be declared inline as seen here.
     readEvent: function(magstripeData) {
     alert('Magstripe read event' + '\n' +
     'Track 1: ' + magstripeData.track1 + '\n' +
     'Track 2: ' + magstripeData.track2 + '\n' +
     'Track 3: ' + magstripeData.track3 + '\n');
     },
     //These functions are optional and unimplemented functions will simply not be called.
     //You may create a function separately as seen with rawReadCallback here.
     rawReadEvent: rawReadCallback
     };
 };