File Coverage

blib/lib/WebService/PayPal/PaymentsAdvanced/Response/FromSilentPOST.pm
Criterion Covered Total %
statement 43 43 100.0
branch 4 4 100.0
condition 5 6 83.3
subroutine 15 15 100.0
pod 0 1 0.0
total 67 69 97.1


line stmt bran cond sub pod time code
1             package WebService::PayPal::PaymentsAdvanced::Response::FromSilentPOST;
2              
3 6     6   106779 use Moo;
  6         10947  
  6         42  
4              
5 6     6   3560 use namespace::autoclean;
  6         11802  
  6         51  
6              
7             our $VERSION = '0.000027';
8              
9 6     6   3762 use Const::Fast qw( const );
  6         6984  
  6         52  
10 6     6   1275 use List::AllUtils qw( any );
  6         11184  
  6         362  
11 6     6   545 use MooX::HandlesVia;
  6         10004  
  6         44  
12 6     6   1140 use MooX::StrictConstructor;
  6         4899  
  6         42  
13 6     6   34184 use Net::Works::Address ();
  6         154779  
  6         180  
14 6     6   3579 use Net::Works::Network ();
  6         274808  
  6         323  
15 6     6   678 use Types::Common::String qw( NonEmptyStr );
  6         128223  
  6         87  
16 6     6   3429 use Types::Standard qw( ArrayRef Bool );
  6         18  
  6         45  
17 6     6   5801 use Type::Utils qw( class_type );
  6         4221  
  6         52  
18 6     6   6264 use WebService::PayPal::PaymentsAdvanced::Error::IPVerification;
  6         21  
  6         2134  
19              
20             extends 'WebService::PayPal::PaymentsAdvanced::Response';
21              
22             sub BUILD {
23 34     34 0 81 my $self = shift;
24              
25 34 100       181 my $ip_str = $self->_has_ip_address ? $self->_ip_address->as_string : q{};
26              
27             return
28 34 100 66     515 if !$self->_has_ip_address
      100        
29             || $self->_has_ip_address && $self->_ip_address_is_verified;
30              
31 1         122 WebService::PayPal::PaymentsAdvanced::Error::IPVerification->throw(
32             message => $ip_str . ' is not a verified PayPal address',
33             ip_address => $ip_str,
34             params => $self->params,
35             );
36             }
37              
38             {
39             my $Address
40             = class_type( { class => 'Net::Works::Address' } )
41             ->plus_coercions( NonEmptyStr,
42             sub { Net::Works::Address->new_from_string( string => $_ ) },
43             );
44              
45             has _ip_address => (
46             is => 'ro',
47             isa => $Address,
48             init_arg => 'ip_address',
49             required => 0,
50             coerce => 1,
51             predicate => '_has_ip_address',
52             );
53             }
54              
55             has _ip_address_is_verified => (
56             is => 'ro',
57             isa => Bool,
58             lazy => 1,
59             init_arg => undef,
60             builder => '_build_ip_address_is_verified',
61             );
62              
63             with(
64             'WebService::PayPal::PaymentsAdvanced::Role::HasTender',
65             'WebService::PayPal::PaymentsAdvanced::Role::HasTokens',
66             'WebService::PayPal::PaymentsAdvanced::Role::HasTransactionTime',
67             );
68              
69             # Payments Advanced IPs listed at
70             # https://www.paypal.com/us/selfhelp/article/what-are-the-ip-addresses-for-payflow-servers-ts1465/1
71             const my @ALLOWED_NETWORKS =>
72             map { Net::Works::Network->new_from_string( string => $_ ) }
73             ( '66.211.170.66/32', '173.0.81.0/24' );
74              
75             sub _build_ip_address_is_verified {
76 2     2   23 my $self = shift;
77              
78 2     4   13 return any { $_->contains( $self->_ip_address ) } @ALLOWED_NETWORKS;
  4         324  
79             }
80              
81             1;
82              
83             =pod
84              
85             =encoding UTF-8
86              
87             =head1 NAME
88              
89             WebService::PayPal::PaymentsAdvanced::Response::FromSilentPOST - Response object generated via Silent POST params
90              
91             =head1 VERSION
92              
93             version 0.000027
94              
95             =head1 DESCRIPTION
96              
97             This module provides an interface for extracting returned params from an
98             L<HTTP::Response> object. You won't need to this module directly if you are
99             using L<PayPal::PaymentsAdvanced/get_response_from_silent_post>.
100              
101             This module inherits from L<WebService::PayPal::PaymentsAdvanced::Response> and
102             includes the methods provided by
103             L<WebService::PayPal::PaymentsAdvanced::Role::HasTender>,
104             L<WebService::PayPal::PaymentsAdvanced::Role::HasTokens> and
105             L<WebService::PayPal::PaymentsAdvanced::Role::HasTransactionTime>.
106              
107             =head1 OBJECT INSTANTIATION
108              
109             The following parameters can be supplied to C<new()> when creating a new object.
110              
111             =head2 Required Parameters
112              
113             =head3 params
114              
115             Returns a C<HashRef> of parameters which have been returned from PayPal via a
116             redirect or a silent POST.
117              
118             =head2 Optional Parameters
119              
120             =head3 ip_address
121              
122             This is the IP address from which the PayPal params have been returned. If
123             you provide an IP address, it will be validated against a list of known valid
124             IP addresses which have been provided by PayPal. You are encouraged to
125             provide an IP in order to prevent spoofing.
126              
127             This module will throw a
128             L<WebService::PayPal::PaymentsAdvanced::Error::IPVerification> exception if
129             the provided IP address cannot be validated.
130              
131             =head1 SUPPORT
132              
133             Bugs may be submitted through L<https://github.com/maxmind/webservice-paypal-paymentsadvanced/issues>.
134              
135             =head1 AUTHOR
136              
137             Olaf Alders <olaf@wundercounter.com>
138              
139             =head1 COPYRIGHT AND LICENSE
140              
141             This software is copyright (c) 2021 by MaxMind, Inc.
142              
143             This is free software; you can redistribute it and/or modify it under
144             the same terms as the Perl 5 programming language system itself.
145              
146             =cut
147              
148             __END__
149             # ABSTRACT: Response object generated via Silent POST params
150