[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 627
  • Last Modified:

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

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
jriver12
Asked:
jriver12
  • 7
  • 6
1 Solution
 
gdemariaCommented:
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
 
jriver12Author Commented:
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
 
gdemariaCommented:

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jriver12Author Commented:
@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
 
jriver12Author Commented:
@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
 
gdemariaCommented:
> 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
 
jriver12Author Commented:
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
 
gdemariaCommented:
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
 
gdemariaCommented:
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
 
jriver12Author Commented:
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
 
gdemariaCommented:
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
 
jriver12Author Commented:
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
 
jriver12Author Commented:
gdemaria:
hey thanks for all the help we got it working.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now