line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Card::Magnetic; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
3619
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
156
|
|
4
|
6
|
|
|
6
|
|
19
|
use warnings; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
3187
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Magnetic Stripe parser |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
5
|
|
|
5
|
1
|
2320
|
my ( $class ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
|
|
11
|
my $self = { stripe => undef }; |
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
|
|
12
|
return bless $self, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub stripe{ |
18
|
5
|
|
|
5
|
1
|
14
|
my ( $self , $stripe ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
5
|
50
|
|
|
|
16
|
return $self->{ stripe } if ! $stripe; |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
22
|
$self->{ stripe } = $stripe; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub parse{ |
26
|
5
|
|
|
5
|
1
|
15
|
my ( $self ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
8
|
my $stripe = $self->{ stripe }; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#track1 |
31
|
5
|
100
|
|
|
|
27
|
if ( $stripe =~ /^%[\w|\^]+\?\n/ ){ |
32
|
3
|
|
|
|
|
7
|
my $track1 = $&; |
33
|
3
|
|
|
|
|
8
|
$stripe = $` . $'; |
34
|
3
|
|
|
|
|
6
|
$self->{ track1 }{ track } = $track1; |
35
|
3
|
|
|
|
|
7
|
chomp $track1; |
36
|
3
|
50
|
|
|
|
20
|
if( $track1 =~ /^%(\w)(\d+)\^(\w+)\^(\d{4})(\d{3})(\d{5})(\d{3})/ ) { |
37
|
|
|
|
|
|
|
$self->{ track1 } = { |
38
|
3
|
|
|
|
|
28
|
FORMAT_CODE => $1, |
39
|
|
|
|
|
|
|
PAN => $2, |
40
|
|
|
|
|
|
|
NAME => $3, |
41
|
|
|
|
|
|
|
EXPIRATION_DATE => $4, |
42
|
|
|
|
|
|
|
SERVICE_CODE => $5, |
43
|
|
|
|
|
|
|
PVV => $6, |
44
|
|
|
|
|
|
|
CVV => $7, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
3
|
|
|
|
|
9
|
$self->{ tracks }[0] = $track1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
#track2 |
50
|
5
|
100
|
100
|
|
|
50
|
if( $stripe =~ /\;[\w\^]+\?\n/ and ( length $& < 39 ) ){ # stripe... |
51
|
3
|
|
|
|
|
4
|
my $track2 = $&; |
52
|
3
|
|
|
|
|
6
|
$stripe = $` . $'; |
53
|
3
|
|
|
|
|
6
|
$self->{ track2 }{ track } = $track2; |
54
|
3
|
|
|
|
|
4
|
chomp $track2; |
55
|
3
|
50
|
|
|
|
15
|
if( $track2 =~ /(\d+)\^(\d{4})(\d{3})(\d{5})(\d{3})/ ) { |
56
|
|
|
|
|
|
|
$self->{ track2 } = { |
57
|
3
|
|
|
|
|
15
|
PAN => $1, |
58
|
|
|
|
|
|
|
EXPIRATION_DATE => $2, |
59
|
|
|
|
|
|
|
SERVICE_CODE => $3, |
60
|
|
|
|
|
|
|
PVV => $4, |
61
|
|
|
|
|
|
|
CVV => $5, |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
3
|
|
|
|
|
8
|
$self->{ tracks }[1] = $track2; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
#track3 |
67
|
5
|
100
|
|
|
|
23
|
if( $stripe =~ /\;[\w\^]+\?\n/ ){ |
68
|
3
|
|
|
|
|
5
|
my $track3 = $&; |
69
|
3
|
|
|
|
|
5
|
$stripe = $` . $'; |
70
|
3
|
|
|
|
|
10
|
$self->{ track3 }{ track } = $track3; |
71
|
3
|
|
|
|
|
8
|
chomp $track3; |
72
|
3
|
50
|
|
|
|
20
|
if( $track3 =~ / |
73
|
|
|
|
|
|
|
(?\d{2}) |
74
|
|
|
|
|
|
|
(?\d+)\^ |
75
|
|
|
|
|
|
|
(?\d{3}) |
76
|
|
|
|
|
|
|
(?\d{3}) |
77
|
|
|
|
|
|
|
(?\d{4}) |
78
|
|
|
|
|
|
|
(?\d{4}) |
79
|
|
|
|
|
|
|
(?\d{4}) |
80
|
|
|
|
|
|
|
(?\d{2}) |
81
|
|
|
|
|
|
|
(?\d{1}) |
82
|
|
|
|
|
|
|
(?\d{6}) |
83
|
|
|
|
|
|
|
(?\d{1}) |
84
|
|
|
|
|
|
|
(?\d{2}) |
85
|
|
|
|
|
|
|
(?\d{2}) |
86
|
|
|
|
|
|
|
(?\d{2}) |
87
|
|
|
|
|
|
|
(?\d{4}) |
88
|
|
|
|
|
|
|
(?\d{1}) |
89
|
|
|
|
|
|
|
(?\d{9}) |
90
|
|
|
|
|
|
|
(?\d{1}) |
91
|
|
|
|
|
|
|
(?\d{6}) |
92
|
|
|
|
|
|
|
/x){ |
93
|
|
|
|
|
|
|
$self->{ track3 } = { |
94
|
6
|
|
|
6
|
|
2735
|
FORMAT_CODE => $+{fc}, |
|
6
|
|
|
|
|
2270
|
|
|
6
|
|
|
|
|
1424
|
|
95
|
|
|
|
|
|
|
PAN => $+{pan}, |
96
|
|
|
|
|
|
|
COUNTRY_CODE => $+{cc}, |
97
|
|
|
|
|
|
|
CURRENCY_CODE => $+{cur}, |
98
|
|
|
|
|
|
|
AMOUNTAUTH => $+{amountauth}, |
99
|
|
|
|
|
|
|
AMOUNTREMAINING => $+{amountremaining}, |
100
|
|
|
|
|
|
|
CYCLE_BEGIN => $+{cyclebegin}, |
101
|
|
|
|
|
|
|
CYCLE_LENGHT => $+{cyclelenght}, |
102
|
|
|
|
|
|
|
RETRY_COUNT => $+{retrycount}, |
103
|
|
|
|
|
|
|
PINCP => $+{pincp}, |
104
|
|
|
|
|
|
|
INTERCHANGE => $+{interchange}, |
105
|
|
|
|
|
|
|
PANSR => $+{pansr}, |
106
|
|
|
|
|
|
|
SAN1 => $+{san1}, |
107
|
|
|
|
|
|
|
SAN2 => $+{san2}, |
108
|
|
|
|
|
|
|
EXPIRATION_DATE => $+{expirationdate}, |
109
|
|
|
|
|
|
|
CARD_SEQUENCE => $+{cardsequence}, |
110
|
|
|
|
|
|
|
CARD_SECURITY => $+{cardsecurity}, |
111
|
|
|
|
|
|
|
RELAY_MARKER => $+{relaymarker}, |
112
|
|
|
|
|
|
|
CRYPTO_CHECK => $+{cryptocheck}, |
113
|
3
|
|
|
|
|
117
|
}; |
114
|
|
|
|
|
|
|
} |
115
|
3
|
|
|
|
|
17
|
$self->{ tracks }[2] = $track3; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub track1 { |
120
|
1
|
|
|
1
|
1
|
401
|
my ( $self ) = @_; |
121
|
1
|
50
|
|
|
|
8
|
return defined $self->{ tracks }[ 0 ]? $self->{ tracks }[ 0 ] : undef; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub track2 { |
125
|
1
|
|
|
1
|
1
|
2
|
my ( $self ) = @_; |
126
|
1
|
50
|
|
|
|
5
|
return defined $self->{ tracks }[ 1 ]? $self->{ tracks }[ 1 ] : undef; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub track3 { |
130
|
1
|
|
|
1
|
1
|
1
|
my ( $self ) = @_; |
131
|
1
|
50
|
|
|
|
5
|
return defined $self->{ tracks }[ 2 ]? $self->{ tracks }[ 2 ] : undef; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |