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   46 use Moo;
  6         16  
  6         55  
4              
5 6     6   1941 use namespace::autoclean;
  6         16  
  6         50  
6              
7             our $VERSION = '0.000026';
8              
9 6     6   3735 use Const::Fast qw( const );
  6         6931  
  6         42  
10 6     6   614 use List::AllUtils qw( any );
  6         18  
  6         299  
11 6     6   42 use MooX::HandlesVia;
  6         16  
  6         42  
12 6     6   601 use MooX::StrictConstructor;
  6         20  
  6         43  
13 6     6   7813 use Net::Works::Address ();
  6         148847  
  6         166  
14 6     6   3337 use Net::Works::Network ();
  6         276298  
  6         269  
15 6     6   52 use Types::Common::String qw( NonEmptyStr );
  6         17  
  6         83  
16 6     6   3467 use Types::Standard qw( ArrayRef Bool );
  6         21  
  6         47  
17 6     6   5264 use Type::Utils qw( class_type );
  6         20  
  6         55  
18 6     6   6098 use WebService::PayPal::PaymentsAdvanced::Error::IPVerification;
  6         25  
  6         2027  
19              
20             extends 'WebService::PayPal::PaymentsAdvanced::Response';
21              
22             sub BUILD {
23 33     33 0 75 my $self = shift;
24              
25 33 100       180 my $ip_str = $self->_has_ip_address ? $self->_ip_address->as_string : q{};
26              
27             return
28 33 100 66     493 if !$self->_has_ip_address
      100        
29             || $self->_has_ip_address && $self->_ip_address_is_verified;
30              
31 1         118 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   22 my $self = shift;
77              
78 2     4   14 return any { $_->contains( $self->_ip_address ) } @ALLOWED_NETWORKS;
  4         322  
79             }
80              
81             1;
82              
83             =pod
84              
85             =head1 NAME
86              
87             WebService::PayPal::PaymentsAdvanced::Response::FromSilentPOST - Response object generated via Silent POST params
88              
89             =head1 VERSION
90              
91             version 0.000026
92              
93             =head1 DESCRIPTION
94              
95             This module provides an interface for extracting returned params from an
96             L<HTTP::Response> object. You won't need to this module directly if you are
97             using L<PayPal::PaymentsAdvanced/get_response_from_silent_post>.
98              
99             This module inherits from L<WebService::PayPal::PaymentsAdvanced::Response> and
100             includes the methods provided by
101             L<WebService::PayPal::PaymentsAdvanced::Role::HasTender>,
102             L<WebService::PayPal::PaymentsAdvanced::Role::HasTokens> and
103             L<WebService::PayPal::PaymentsAdvanced::Role::HasTransactionTime>.
104              
105             =head1 OBJECT INSTANTIATION
106              
107             The following parameters can be supplied to C<new()> when creating a new object.
108              
109             =head2 Required Parameters
110              
111             =head3 params
112              
113             Returns a C<HashRef> of parameters which have been returned from PayPal via a
114             redirect or a silent POST.
115              
116             =head2 Optional Parameters
117              
118             =head3 ip_address
119              
120             This is the IP address from which the PayPal params have been returned. If
121             you provide an IP address, it will be validated against a list of known valid
122             IP addresses which have been provided by PayPal. You are encouraged to
123             provide an IP in order to prevent spoofing.
124              
125             This module will throw a
126             L<WebService::PayPal::PaymentsAdvanced::Error::IPVerification> exception if
127             the provided IP address cannot be validated.
128              
129             =head1 AUTHOR
130              
131             Olaf Alders <olaf@wundercounter.com>
132              
133             =head1 COPYRIGHT AND LICENSE
134              
135             This software is copyright (c) 2020 by MaxMind, Inc.
136              
137             This is free software; you can redistribute it and/or modify it under
138             the same terms as the Perl 5 programming language system itself.
139              
140             =cut
141              
142             __END__
143             # ABSTRACT: Response object generated via Silent POST params
144