File Coverage

blib/lib/WebService/PayPal/PaymentsAdvanced/Role/HasCreditCard.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 28 28 100.0


line stmt bran cond sub pod time code
1             package WebService::PayPal::PaymentsAdvanced::Role::HasCreditCard;
2              
3 6     6   3427 use Moo::Role;
  6         28  
  6         41  
4              
5 6     6   1986 use namespace::autoclean;
  6         24  
  6         44  
6              
7             our $VERSION = '0.000026';
8              
9 6     6   554 use Types::Common::String qw( NonEmptyStr SimpleStr );
  6         16  
  6         56  
10              
11             has card_type => (
12             is => 'lazy',
13             isa => NonEmptyStr,
14             init_arg => undef,
15             );
16              
17             has card_expiration => (
18             is => 'lazy',
19             isa => NonEmptyStr,
20             init_arg => undef,
21             );
22              
23             has card_last_four_digits => (
24             is => 'lazy',
25             isa => SimpleStr,
26             init_arg => undef,
27             );
28              
29             has reference_transaction_id => (
30             is => 'lazy',
31             isa => NonEmptyStr,
32             init_arg => undef,
33             default => sub { shift->pnref },
34             );
35              
36             sub _build_card_type {
37 1     1   413 my $self = shift;
38              
39 1         11 my %card_types = (
40             0 => 'VISA',
41             1 => 'MasterCard',
42             2 => 'Discover',
43             3 => 'American Express',
44             4 => q{Diner's Club},
45             5 => 'JCB',
46             );
47 1         22 return $card_types{ $self->params->{CARDTYPE} };
48             }
49              
50             sub _build_card_expiration {
51 1     1   410 my $self = shift;
52              
53             # Will be in MMYY
54 1         6 my $date = $self->params->{EXPDATE};
55              
56             # This breaks in about 75 years.
57 1         25 return sprintf( '20%s-%s', substr( $date, 2, 2 ), substr( $date, 0, 2 ) );
58             }
59              
60             sub _build_card_last_four_digits {
61 12     12   4811 my $self = shift;
62              
63 12         44 my $acct = $self->params->{ACCT};
64              
65 12 100       56 if ( $acct !~ /^[0-9]{4}$/ ) {
66 6         57 die 'credit_last_four_digits must be 4 digits';
67             }
68              
69 6         102 return $acct;
70             }
71              
72             1;
73              
74             =pod
75              
76             =head1 NAME
77              
78             WebService::PayPal::PaymentsAdvanced::Role::HasCreditCard - Role which provides methods specifically for credit card transactions
79              
80             =head1 VERSION
81              
82             version 0.000026
83              
84             =head2 card_type
85              
86             A human readable credit card type. One of:
87              
88             VISA
89             MasterCard
90             Discover
91             American Express
92             Diner's Club
93             JCB
94              
95             =head2 card_expiration
96              
97             The month and year of the credit card expiration.
98              
99             =head2 card_last_four_digits
100              
101             The last four digits of the credit card.
102              
103             =head2 reference_transaction_id
104              
105             The id you will use in order to use this as a reference transaction (C<pnref>).
106              
107             =head1 AUTHOR
108              
109             Olaf Alders <olaf@wundercounter.com>
110              
111             =head1 COPYRIGHT AND LICENSE
112              
113             This software is copyright (c) 2020 by MaxMind, Inc.
114              
115             This is free software; you can redistribute it and/or modify it under
116             the same terms as the Perl 5 programming language system itself.
117              
118             =cut
119              
120             __END__
121             # ABSTRACT: Role which provides methods specifically for credit card transactions
122