Business/CyberSource/RequestPart/Card.pm

filter: Statementstmt 96.5% 83 / 86 Branchbran 53.5% 15 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.0% 19 / 20 Podpod n/a totaltotal 87.3% 117 / 134 CC 16 SCAR 17.9
CC
16
Cov
86%
_build_card_type_code
17.7
_compare_date_against_expiration
4.0
__ANON__
3.1
CRAP 6.0
« Business/CyberSource/Request.pm ↑ Summary Business/CyberSource/Request/FollowOnCredit.pm »
1 package Business::CyberSource::RequestPart::Card;
2 7 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 our $VERSION = '0.010007'; # VERSION
8  
9 7 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 extends 'Business::CyberSource::MessagePart';
11 7 with 'MooseX::RemoteHelper::CompositeSerialization';
12  
13 7 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶use MooseX::Types::CyberSource qw( CvIndicator CardTypeCode );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use MooseX::Types::Common::String qw( NonEmptySimpleStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 use MooseX::Types::CreditCard 0.002 qw(
18 CardNumber
19 CardSecurityCode
20 CardExpiration
21 7 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 7 ▶use Module::Runtime qw( use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 7 our @CARP_NOT = ( __PACKAGE__, qw( Class::MOP::Method::Wrapped ) );
26  
27 sub _build_type {
28 10 ▶ my $self = shift;
Subroutine _build_type: called CC=2 SCAR=7.0
29  
30 10 use_module('Business::CreditCard');
31 10 my $ct = Business::CreditCard::cardtype( $self->account_number );
32  
33 10 ▶ die ## no critic ( ErrorHandling::RequireCarping )
Branch: 1 branch
BranchTrueFalseTotal
if $ct =~ /not a credit card/imsx 0 10 10
34 use_module('Business::CyberSource::Exception::NotACreditCard')->new
35 if $ct =~ /not a credit card/ixms
36 ;
37  
38 10 $ct =~ s/[\s]card//xms;
39  
40 10 return uc $ct;
41 }
42  
43 sub _build_expired {
44 3 ▶ my $self = shift;
Subroutine _build_expired: called CC=1 SCAR=0.0
45 3 use_module('DateTime');
46  
47 3 return $self->_compare_date_against_expiration( DateTime->now );
48 }
49  
50 sub _compare_date_against_expiration {
51 15 ▶ my ( $self, $date ) = @_;
Subroutine _compare_date_against_expiration: called CC=4 SCAR=13.9
52  
53 15 my $exp = $self->expiration->clone;
54 # add 2 days so that we allow for a 24 hour period where
55 # the card could be expired at UTC but not the issuer
56 15 $exp->add( days => 1 );
57  
58 15 use_module('DateTime');
59 15 my $cmp = DateTime->compare( $date, $exp );
60  
61 15 ▶ if ( $cmp == -1 ) { # current date is before than the expiration date
Branch: 3 branches
BranchTrueFalseTotal
if ($cmp == -1) { } 3 12 15
elsif ($cmp == 0) { } 3 9 12
elsif ($cmp == 1) { } 9 0 9
62 3 return 0;
63 }
64 elsif ( $cmp == 0 ) { # expiration equal to current date
65 3 return 0;
66 }
67 elsif ( $cmp == 1 ) { # current date is past the expiration date
68 9 return 1;
69 }
70 0 return; # da F*? should never hit this
71 }
72  
73 sub _build_card_type_code {
74 9 ▶ my $self = shift;
Subroutine _build_card_type_code: called CC=9 SCAR=28.8
75  
76 9 ▶ my $code
Branch: 7 branches
BranchTrueFalseTotal
$self->type =~ /visa /imsx ? : 5 4 9
$self->type =~ /mastercard /imsx ? : 2 2 4
$self->type =~ /discover /imsx ? : 2 0 2
$self->type =~ /jcb /imsx ? : 0 0 0
$self->type =~ /enroute /imsx ? : 0 0 0
$self->type =~ /laser /imsx ? : 0 0 0
$self->type =~ /american\ express/imsx ? : 0 0 0
77 = $self->type =~ /visa /ixms ? '001'
78 : $self->type =~ /mastercard /ixms ? '002'
79 : $self->type =~ /discover /ixms ? '004'
80 : $self->type =~ /jcb /ixms ? '007'
81 : $self->type =~ /enroute /ixms ? '014'
82 : $self->type =~ /laser /ixms ? '035'
83 : $self->type =~ /american\ express/ixms ? '003'
84 : undef
85 ;
86  
87 9 my $exception_ns = 'Business::CyberSource::Exception::';
88 9 ▶ die ## no critic ( ErrorHandling::RequireCarping )
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 9 9
89 use_module( $exception_ns . 'UnableToDetectCardTypeCode')
90 ->new( type => $self->type) unless $code;
91  
92 9 return $code;
93 }
94  
95 has account_number => (
96 isa => CardNumber,
97 remote_name => 'accountNumber',
98 alias => [ qw( credit_card_number card_number ) ],
99 required => 1,
100 is => 'ro',
101 coerce => 1,
102 10 ▶ trigger => sub { shift->type },
Subroutine __ANON__: called CC=1 SCAR=0.0
103 7 );
104  
105 7 has type => (
106 isa => 'Str',
107 lazy => 1,
108 is => 'ro',
109 builder => '_build_type',
110 );
111  
112 7 has expiration => (
113 isa => CardExpiration,
114 required => 1,
115 is => 'ro',
116 coerce => 1,
117 handles => [ qw( month year ) ],
118 );
119  
120 7 has is_expired => (
121 isa => 'Bool',
122 builder => '_build_expired',
123 lazy => 1,
124 is => 'ro',
125 );
126  
127 7 has security_code => (
128 isa => CardSecurityCode,
129 remote_name => 'cvNumber',
130 alias => [ qw( cvn cvv cvv2 cvc2 cid ) ],
131 predicate => 'has_security_code',
132 traits => [ 'SetOnce' ],
133 is => 'rw',
134 );
135  
136 7 has holder => (
137 isa => NonEmptySimpleStr,
138 remote_name => 'fullName',
139 alias => [ qw( name full_name card_holder ) ],
140 predicate => 'has_holder',
141 traits => [ 'SetOnce' ],
142 is => 'rw',
143 );
144  
145 7 has card_type_code => (
146 isa => CardTypeCode,
147 remote_name => 'cardType',
148 lazy => 1,
149 is => 'ro',
150 builder => '_build_card_type_code',
151 );
152  
153 has cv_indicator => (
154 isa => CvIndicator,
155 remote_name => 'cvIndicator',
156 lazy => 1,
157 predicate => 'has_cv_indicator',
158 traits => [ 'SetOnce' ],
159 is => 'rw',
160 9 ▶ default => sub { $_[0]->has_security_code ? 1 : 0 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->has_security_code ? : 7 2 9
161 7 );
162  
163 has _expiration_month => (
164 remote_name => 'expirationMonth',
165 isa => 'Int',
166 is => 'ro',
167 lazy => 1,
168 reader => undef,
169 writer => undef,
170 init_arg => undef,
171 9 ▶ default => sub { $_[0]->expiration->month },
Subroutine __ANON__: called CC=1 SCAR=0.0
172 7 );
173  
174 has _expiration_year => (
175 remote_name => 'expirationYear',
176 isa => 'Int',
177 is => 'ro',
178 lazy => 1,
179 reader => undef,
180 writer => undef,
181 init_arg => undef,
182 9 ▶ default => sub { $_[0]->expiration->year },
Subroutine __ANON__: called CC=1 SCAR=0.0
183 7 );
184  
185 7 my @deprecated = ( qw(
186 credit_card_number
187 card_number
188 cvn cvv cvv2
189 cvc2 cid name
190 full_name
191 card_holder
192 ));
193  
194 around BUILDARGS => sub {
195 10 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.3
196 10 my $self = shift;
197  
198 10 my $args = $self->$orig( @_ );
199  
200 10 foreach my $attr (@deprecated ) {
201 100 ▶ if ( exists $args->{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{$attr}) 0 100 100
202 0 warnings::warnif('deprecated', # this is due to Moose::Exception conflict
203 "$attr deprecated check the perldoc for the actual attribute"
204 );
205 }
206 }
207  
208 10 return $args;
209 7 };
210  
211 7 foreach my $attr ( @deprecated ) {
212 my $deprecated = sub {
213 0 ▶ warnings::warnif('deprecated', # this is due to Moose::Exception conflict
Subroutine __ANON__: not called CC=1 SCAR=6.9
214 "$attr deprecated check the perldoc for the actual attribute"
215 );
216 70 };
217  
218 70 before( $attr, $deprecated );
219 }
220 7 __PACKAGE__->meta->make_immutable;
221 7 1;
222 # ABSTRACT: Credit Card Helper Class
223  
224 __END__
225  
226 =pod
227  
228 =encoding UTF-8
229  
230 =head1 NAME
231  
232 Business::CyberSource::RequestPart::Card - Credit Card Helper Class
233  
234 =head1 VERSION
235  
236 version 0.010007
237  
238 =head1 EXTENDS
239  
240 L<Business::CyberSource::MessagePart>
241  
242 =head1 ATTRIBUTES
243  
244 =head2 account_number
245  
246 This is the Credit Card Number
247  
248 =head2 expiration
249  
250 my $card = Business::CyberSource::RequestPart::Card->new({
251 account_number => '4111111111111111',
252 expiration => {
253 year => '2025',
254 month => '04',
255 },
256 });
257  
258 A DateTime object, you should construct it by passing a hashref with keys for
259 month, and year, it will actually contain the last day of that month/year. You
260 can pass a L<DateTime> object, as long as it was built using the
261 L<last_day_of_month|DateTime/"DateTime-last_day_of_month-...-"> factory method.
262  
263 =head2 security_code
264  
265 The 3 digit security number on the back of the card.
266  
267 =head2 holder
268  
269 The full name of the card holder as printed on the card.
270  
271 =head2 is_expired
272  
273 Boolean, returns true if the card is older than
274 L<expiration date|/"expiration"> plus one day. This is done to compensate for
275 unknown issuer time zones as we can't be sure that all issuers shut cards of on
276 the first of every month UTC. In fact I have been told that some issuers will
277 allow renewed cards to be run with expired dates. Use this at your discretion.
278  
279 =head2 cv_indicator
280  
281 Boolean, true if the L<security code|/"security_code"> was passed.
282  
283 =head2 type
284  
285 The card issuer, e.g. VISA, MasterCard. it is generated from the card number.
286  
287 =head2 card_type_code
288  
289 Type of card to authorize. This should be auto detected, but if it's not you
290 can specify the value manually.
291  
292 Possible values:
293  
294 =over
295  
296 =item 001: Visa
297  
298 =item 002: MasterCard, Eurocard*
299  
300 European regional brand of MasterCard
301  
302 =item 003: American Express
303  
304 =item 004: Discover
305  
306 =item 005: Diners Club
307  
308 see Discover Acquisitions and Alliances.
309  
310 =item 006: Carte Blanche*
311  
312 =item 007: JCB*
313  
314 =item 014: EnRoute*
315  
316 =item 021: JAL*
317  
318 =item 024: Maestro (UK Domestic)*
319  
320 =item 031: Delta*
321  
322 use this value only for Global Collect. For other processors, use
323 001 for all Visa card types.
324  
325 =item 033: Visa Electron*
326  
327 =item 034: Dankort*
328  
329 =item 035: Laser*
330  
331 =item 036: Carte Bleue*
332  
333 =item 037: Carta Si*
334  
335 =item 039: Encoded account number*
336  
337 =item 040: UATP*
338  
339 =item 042: Maestro (International)*
340  
341 =item 043: Santander card*
342  
343 before setting up your system to work with Santander
344 cards, contact the CyberSource UK Support Group.
345  
346 =back
347  
348 =head1 BUGS
349  
350 Please report any bugs or feature requests on the bugtracker website
351 https://github.com/xenoterracide/business-cybersource/issues
352  
353 When submitting a bug or request, please include a test-file or a
354 patch to an existing test-file that illustrates the bug or desired
355 feature.
356  
357 =head1 AUTHOR
358  
359 Caleb Cushing <xenoterracide@gmail.com>
360  
361 =head1 COPYRIGHT AND LICENSE
362  
363 This software is Copyright (c) 2016 by Caleb Cushing <xenoterracide@gmail.com>.
364  
365 This is free software, licensed under:
366  
367 The Artistic License 2.0 (GPL Compatible)
368  
369 =cut
« Business/CyberSource/Request.pm ↑ Summary Business/CyberSource/Request/FollowOnCredit.pm »