File Coverage

blib/lib/WebService/PayPal/PaymentsAdvanced/Response/FromSilentPOST.pm
Criterion Covered Total %
statement 40 40 100.0
branch 4 4 100.0
condition 5 6 83.3
subroutine 14 14 100.0
pod 0 1 0.0
total 63 65 96.9


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