CarlRaymond / jquery.cardswipe

jQuery plugin for magnetic card readers
MIT License
115 stars 49 forks source link

Custom parser is being ignored #33

Closed boutzamat closed 4 years ago

boutzamat commented 4 years ago

I have created a custom parser for ID cards, but the type is always being recognized as a generic card.

The entered value is always something like: %BOUTZAMAT&SOULAIMAN CHARLOTTEAGER 28 2 TH

I have the following parser, created from your example in the docs:

var socialSecurityCard = function (rawData) {
            var pattern = new RegExp("^%B");
            var match = pattern.exec(rawData);
            if (!match) return null;

            // Extract the data
            var cardData = {
                type: "socialcard",
                lastName: "some firstname",
                firstName: "some lastname",
                idNumber: "some id number"
            };

            return cardData;
        }

        var successCallback = function (data) {

            console.log(data.type);

            // Is it a custom card
            if (data.type == "socialSecurityCard")
                return;

            // Is it a payment card?
            if (data.type == "generic")
                return;

            // Copy data fields to form
            $("#idnumber").val(data.idNumber);
            $("#firstname").val(data.firstName);
            $("#firstname").val(data.lastName);
        };

        $.cardswipe({
            firstLineOnly: true,
            success: complete,
            parsers: ["socialSecurityCard", "generic"],
            debug: false
        });

But the debug log always shows "type" of generic.

boutzamat commented 4 years ago

Solved.

The problem: My custom parser was added to the parsers object as a string but it should be a variable.