Solved

Parsing Credit card data to form fields and showing what type of card.

Posted on 2011-03-02
13
607 Views
Last Modified: 2012-05-11
Hey experts, I am working on an internal solution that would allow my org to process credit cards through a magtek card swipper (21040102). After several hour of surching I have been able to capture the data howerver it is in a string.
example:
%B1111111111111111^lname/fname           ^120800000000000000000000000000?;1111111111111111=1208000000000000000?
--end Ex---
I have the following script:
<script language="javascript1.2">
function
swipedCreditCard() {
 
    ccField = document.getElementById('ccNum');
    expirField = document.getElementById('ccExpir');
    cvvField = document.getElementById('ccCvv');
    fname = document.getElementById('fname');
    lname = document.getElementById('lname');
 
    if( ccField.value.length <= 0 ) {
        return true;
    }
 
    if ( ccField.value.substr(0,1) == "B" ) {
        var containsCaret = ccField.value.search('^');
        if( containsCaret  < 0 ) {
            expirField.focus();
        }
        else {
            var pieces = ccField.value.split('^');
            if( pieces.length >= 3 ) {
                var cardNumber = pieces[0];
                var name = pieces[1];
                var exp = pieces[2];
 
                ccField.value = cardNumber.substr(1,(cardNumber.length-1));
                expirField.value = exp.substr(2,2) + exp.substr(0,2);
 
                namepieces = name.split('/');
                var l = namepieces[0];
                var f = namepieces[1];
 
                fname.value = f;
                lname.value = l;
 
                cvvField.focus();
            }
        }
    }
    else {
        var containsEqual = ccField.value.search('=');
        if( containsEqual < 0 ) {
            expirField.focus();
        }
        else {
            var pieces = ccField.value.split('=');
            if( pieces.length <= 2 ) {
                var cardNumber = pieces[0];
                var exp = pieces[1];
 
                ccField.value = cardNumber;
                expirField.value = exp.substr(2,2) + exp.substr(0,2);
 
                cvvField.focus();
            }
        }
    }
    return true;
}
</script>

However, it will not parse the data sent from the swipper. it will using onbur on the  ccField put all the information and submit the form.

My ultimate question is two fold:
how to get it to parse correctly (each data into the correct field) show the correct card type (visa Maste.....) and how to have it not submit automatically (although It will be used in the future).

any if all help provided will be greatly appreciated.
thanks in advance.
0
Comment
Question by:jriver12
  • 7
  • 6
13 Comments
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
One option is to take the submit, parse it using simple coldfusion list functions and then present the data on the form.. ready to be submitted by the user.

That is, even though the card automatically submits, it doesn't have to be the submit that processes the card, it could be the submit that accepts and loads the card info onto the page.

The CF commands may be something like this

 <cfset form.ccnumber =  listgetAt(string,2,"^?;")>

0
 

Author Comment

by:jriver12
Comment Utility
My altimate goal is to present the user a form
5 fields
first name
lastname
ccnum
ccvs
ccexp
with a message on the screen saying please swipe.  once the user does that then i would like the form to capture the data in the correct fields, know what type of card it is and submit straight to the processor.

right now we already do this but the user must input all data, now if we have card present then all we would have to do is swipe.

thanks for the insight looking forward to your comments.
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility

Present the form as you do now,

If the card is swiped, you said it automatically submits the form.

Instead of trying to process it through javascript and fill form fields, take all the information put it into ONE form field and then handle it all in the form-action.

Coldfusion can easily parse the values and submit them to the processor, if there is an error, then you can present the data back to the user in the correct form fields
0
 

Author Comment

by:jriver12
Comment Utility
@gdemaria:
thanks.
I mis explained.
the current way we do it is manual. (fill the form in and hit submit)

the above script is the one that is automatically submitting the for, but failing to parse and populate.

I am going to try what you have said in your previous post to include you previous suggestion.  Give me a bit to attempt and get back to you.

thanks again.
0
 

Author Comment

by:jriver12
Comment Utility
@gdemaria,

thanks for your patience.  I have tested your suggestion and although it would parse it would not give me the functionality of knowing which type of card it was.

I have done some digging and found this:
http://www.webmasterkb.com/Uwe/Forum.aspx/cold-fusion/19310/Magnetic-Gift-Card-Swipe-CF-Form

have been testing it however, I am receiving an object expected error on ln 196 "if (!My_CF_checkcreditcard(card1))

for the life of me I cannot figure out how to and why the error exist.  i have also tried using the examples in the url above as a test and receive the same error.

Can you assist in finding the cause.

thanks again.
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
> I have tested your suggestion and although it would parse it would not give me the functionality of knowing which type of card it was.


Where does that information come from?   Is the type of card not included in that string of information?   I assumed it was... if not how do you know what type of card it is?

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:jriver12
Comment Utility
Unfortunately it is not on the cards I have tested with, so I have had to result to usign the information within the data sequence numbers (account numbers within the string)  each type (Visa, Mastercard, etc) start with a specific number and range, and also a specific amount of characters.
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
oh, ok...

I pulled the part of the code that does that and put it into some simple coldfusion for you...

The first part is the list of card types, the length of the card number and the range of their digits

Then it just loops through these card types to match the card number..

<cfset form.credCardNumber = "">  <!---- put credit card number in this field ----->


<cfset cardRanges = arrayNew()> <cfset ct = 1>
<cfset cardRanges[ct] = "AX,15,34000000,34999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "AX,15,37000000,37999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,14,30000000,30999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,14,36000000,36999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,14,38000000,38999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,14,39000000,39009999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,15,20140000,20149999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,15,21490000,21499999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,30880000,30949999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,30960000,31029999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,31120000,31209999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,31580000,31599999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,33370000,33499999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,35280000,35899999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "MC,16,50000000,55999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "NS,16,60110000,60119999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "NS,16,65000000,65999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "NS,16,62212600,62292599,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "VS,13,40000000,49999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "VS,16,40000000,49999999,true"> <cfset ct = ct + 1>

<cfset theCardNumber = rereplace(form.credCardNumber,"[^[:digit:]]*","","all")>
<cfset theCardLen = len(theCardNumber)>
<cfset theCardType = "">
<cfloop index="ct" from="1" to="#arrayLen(cardRanges)#">
   <cfif theCardLen eq listGetAt(cardRanges[ct],2)>
      <cfif theCardNumber gte listGetAt(cardRanges[ct],3) and theCardNumber lte listGetAt(cardRanges[ct],4)>
         <cfset theCardType = listGetAt(cardRanges[ct],1)>
         <cfbreak>
      </cfif>
   </cfif>
</cfloop>

The card type is...
<cfoutput>#theCardType#</cfoutput>

Open in new window

0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
Comment Utility
small change to the CFIF statement, add left() to only compare 8 digits of the card..
<cfset form.credCardNumber = "">  <!---- put credit card number in this field ----->


<cfset cardRanges = arrayNew()> <cfset ct = 1>
<cfset cardRanges[ct] = "AX,15,34000000,34999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "AX,15,37000000,37999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,14,30000000,30999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,14,36000000,36999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,14,38000000,38999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,14,39000000,39009999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,15,20140000,20149999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "DC,15,21490000,21499999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,30880000,30949999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,30960000,31029999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,31120000,31209999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,31580000,31599999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,33370000,33499999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "JC,16,35280000,35899999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "MC,16,50000000,55999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "NS,16,60110000,60119999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "NS,16,65000000,65999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "NS,16,62212600,62292599,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "VS,13,40000000,49999999,true"> <cfset ct = ct + 1>
<cfset cardRanges[ct] = "VS,16,40000000,49999999,true"> <cfset ct = ct + 1>

<cfset theCardNumber = rereplace(form.credCardNumber,"[^[:digit:]]*","","all")>
<cfset theCardLen    = len(theCardNumber)>
<cfset theCardType   = "">
<cfloop index="ct" from="1" to="#arrayLen(cardRanges)#">
   <cfif theCardLen eq listGetAt(cardRanges[ct],2)>
      <cfif left(theCardNumber,8) gte listGetAt(cardRanges[ct],3) 
        and left(theCardNumber,8) lte listGetAt(cardRanges[ct],4)>
         <cfset theCardType = listGetAt(cardRanges[ct],1)>
         <cfbreak>
      </cfif>
   </cfif>
</cfloop>

The card type is...
<cfoutput>#theCardType#</cfoutput>

Open in new window

0
 

Author Comment

by:jriver12
Comment Utility
I am going to be out of the net for a few days and will probably not be able to get to this for a few days, would you prefer that I close this out or keep it open?  I would hate for you to be waiting on the reward due to my scheduling.

thanks.
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
If you think you have the answer you need, feel free to close, you can always open a new question about a related issue.

However, if you feel you don't have the answer yet, feel free to leave open, no worries.
0
 

Author Comment

by:jriver12
Comment Utility
Thank, I cant say either way since I have not actively tried to incorporate since your last response (posting).  I will leave open just incase I run into something.

thanks again for all your help.
0
 

Author Comment

by:jriver12
Comment Utility
gdemaria:
hey thanks for all the help we got it working.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now