PaymentsAdvanced/Role/HasCreditCard.pm

filter: Statementstmt 96.3% 26 / 27 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 94.4% 34 / 36 CC 2 SCAR 3.2
CC
2
Cov
97%
__ANON__
2.0
_build_card_last_four_digits
2.0
BEGIN
1.0
CRAP 1.4
« PaymentsAdvanced/Mocker.pm ↑ Summary PaymentsAdvanced/Mocker/PayflowLink.pm »
1 package WebService::PayPal::PaymentsAdvanced::Role::HasCreditCard;
2  
3 6 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.000028';
8  
9 6 ▶use Types::Common::String qw( NonEmptyStr SimpleStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 has card_type => (
12 is => 'lazy',
13 isa => NonEmptyStr,
14 init_arg => undef,
15 );
16  
17 6 has card_expiration => (
18 is => 'lazy',
19 isa => NonEmptyStr,
20 init_arg => undef,
21 );
22  
23 6 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 0 ▶ default => sub { shift->pnref },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 6 );
35  
36 1 ▶sub _build_card_type {
Subroutine _build_card_type: called CC=1 SCAR=0.0
37 1 my $self = shift;
38  
39 1 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 return $card_types{ $self->params->{CARDTYPE} };
48 }
49  
50 1 ▶sub _build_card_expiration {
Subroutine _build_card_expiration: called CC=1 SCAR=0.0
51 1 my $self = shift;
52  
53 # Will be in MMYY
54 1 my $date = $self->params->{EXPDATE};
55  
56 # This breaks in about 75 years.
57 1 return sprintf( '20%s-%s', substr( $date, 2, 2 ), substr( $date, 0, 2 ) );
58 }
59  
60 12 ▶sub _build_card_last_four_digits {
Subroutine _build_card_last_four_digits: called CC=2 SCAR=6.9
61 12 my $self = shift;
62  
63 12 my $acct = $self->params->{ACCT};
64  
65 12 ▶ if ( $acct !~ /^[0-9]{4}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($acct =~ /^[0-9]{4}$/) 6 6 12
66 6 die 'credit_last_four_digits must be 4 digits';
67 }
68  
69 6 return $acct;
70 }
71  
72 6 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.000028
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) 2022 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__
« PaymentsAdvanced/Mocker.pm ↑ Summary PaymentsAdvanced/Mocker/PayflowLink.pm »