virtual_merchant 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/virtual_merchant/credit_card.rb +8 -8
- metadata +1 -1
@@ -15,25 +15,25 @@ class VMCreditCard
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def from_swipe(swipe)
|
18
|
-
self.track2 =
|
19
|
-
self.
|
20
|
-
self.expiration =
|
21
|
-
self.name_on_card =
|
18
|
+
self.track2 = extract_track_2(swipe)
|
19
|
+
self.number = extract_card_number(swipe)
|
20
|
+
self.expiration = extract_expiration(swipe)
|
21
|
+
self.name_on_card = extract_name(swipe)
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def extract_card_number(swipe)
|
25
25
|
card_number = swipe[2.. swipe.index('^')-1]
|
26
26
|
card_number = card_number.split(' ').join('')
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def extract_expiration(swipe)
|
30
30
|
secondCarrot = swipe.index("^", swipe.index("^")+1)
|
31
31
|
card_expiration_year = swipe[secondCarrot+1..secondCarrot+2]
|
32
32
|
card_expiration_month = swipe[(secondCarrot + 3)..(secondCarrot + 4)]
|
33
33
|
card_expiration = card_expiration_month.to_s + card_expiration_year.to_s
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def extract_name(swipe)
|
37
37
|
secondCarrot = swipe.index("^", swipe.index("^")+1)
|
38
38
|
if swipe.index('/')
|
39
39
|
first_name_on_card = swipe[swipe.index('/')+1..secondCarrot-1]
|
@@ -50,7 +50,7 @@ class VMCreditCard
|
|
50
50
|
name_on_card = first_name_on_card + " " + last_name_on_card
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
53
|
+
def extract_track_2(swipe)
|
54
54
|
# Magtek reader: Track 2 starts with a semi-colon and goes to the end
|
55
55
|
# I think that is standard for all readers, but not positive. -LQ
|
56
56
|
track2 = swipe.slice(swipe.index(";"), swipe.length)
|