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   3587 use Moo::Role;
  6         17  
  6         43  
4              
5 6     6   2084 use namespace::autoclean;
  6         35  
  6         42  
6              
7             our $VERSION = '0.000027';
8              
9 6     6   593 use Types::Common::String qw( NonEmptyStr SimpleStr );
  6         25  
  6         87  
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   344 my $self = shift;
38              
39 1         7 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         20 return $card_types{ $self->params->{CARDTYPE} };
48             }
49              
50             sub _build_card_expiration {
51 1     1   350 my $self = shift;
52              
53             # Will be in MMYY
54 1         5 my $date = $self->params->{EXPDATE};
55              
56             # This breaks in about 75 years.
57 1         20 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   5050 my $self = shift;
62              
63 12         48 my $acct = $self->params->{ACCT};
64              
65 12 100       52 if ( $acct !~ /^[0-9]{4}$/ ) {
66 6         60 die 'credit_last_four_digits must be 4 digits';
67             }
68              
69 6         121 return $acct;
70             }
71              
72             1;
73              
74             =pod
75              
76             =encoding UTF-8
77              
78             =head1 NAME
79              
80             WebService::PayPal::PaymentsAdvanced::Role::HasCreditCard - Role which provides methods specifically for credit card transactions
81              
82             =head1 VERSION
83              
84             version 0.000027
85              
86             =head2 card_type
87              
88             A human readable credit card type. One of:
89              
90             VISA
91             MasterCard
92             Discover
93             American Express
94             Diner's Club
95             JCB
96              
97             =head2 card_expiration
98              
99             The month and year of the credit card expiration.
100              
101             =head2 card_last_four_digits
102              
103             The last four digits of the credit card.
104              
105             =head2 reference_transaction_id
106              
107             The id you will use in order to use this as a reference transaction (C<pnref>).
108              
109             =head1 SUPPORT
110              
111             Bugs may be submitted through L<https://github.com/maxmind/webservice-paypal-paymentsadvanced/issues>.
112              
113             =head1 AUTHOR
114              
115             Olaf Alders <olaf@wundercounter.com>
116              
117             =head1 COPYRIGHT AND LICENSE
118              
119             This software is copyright (c) 2021 by MaxMind, Inc.
120              
121             This is free software; you can redistribute it and/or modify it under
122             the same terms as the Perl 5 programming language system itself.
123              
124             =cut
125              
126             __END__
127             # ABSTRACT: Role which provides methods specifically for credit card transactions
128