| 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.010008'; # 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( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | CardNumber | ||||||||||||||||||||||||||||||||||
| 19 | CardSecurityCode | ||||||||||||||||||||||||||||||||||
| 20 | CardExpiration | ||||||||||||||||||||||||||||||||||
| 21 | 7 | ); | |||||||||||||||||||||||||||||||||
| 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 | 10 | ▶ | sub _build_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_type: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 28 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | sub _build_expired { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_expired: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 44 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 45 | 3 | use_module('DateTime'); | |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 3 | return $self->_compare_date_against_expiration( DateTime->now ); | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 15 | ▶ | sub _compare_date_against_expiration { | ||||||||||||||||||||||||||||||||
|
Subroutine
_compare_date_against_expiration: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 51 | 15 | my ( $self, $date ) = @_; | |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 | 9 | ▶ | sub _build_card_type_code { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_card_type_code: called CC=9 SCAR=28.8
| |||||||||||||||||||||||||||||||||||
| 74 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 9 | ▶ | my $code | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 | 10 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||
| 195 | 10 | my $orig = shift; | |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | my $deprecated = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 213 | 0 | warnings::warnif('deprecated', # this is due to Moose::Exception conflict | |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||