File Coverage

blib/lib/WebService/PayPal/PaymentsAdvanced/Response.pm
Criterion Covered Total %
statement 28 29 96.5
branch 3 4 75.0
condition 3 6 50.0
subroutine 9 9 100.0
pod 0 1 0.0
total 43 49 87.7


line stmt bran cond sub pod time code
1             package WebService::PayPal::PaymentsAdvanced::Response;
2              
3 8     8   1562 use Moo;
  8         12908  
  8         49  
4              
5 8     8   4120 use namespace::autoclean;
  8         13450  
  8         69  
6              
7             our $VERSION = '0.000026';
8              
9 8     8   2493 use List::AllUtils qw( any );
  8         21713  
  8         601  
10 8     8   1091 use Types::Common::String qw( NonEmptyStr );
  8         165462  
  8         94  
11 8     8   3995 use Types::Standard qw( ArrayRef Int Maybe );
  8         21  
  8         51  
12 8     8   11115 use WebService::PayPal::PaymentsAdvanced::Error::Authentication;
  8         29  
  8         247  
13 8     8   1034 use WebService::PayPal::PaymentsAdvanced::Error::Generic;
  8         24  
  8         1996  
14              
15             has _nonfatal_result_codes => (
16             init_arg => 'nonfatal_result_codes',
17             is => 'ro',
18             isa => ArrayRef [Int],
19             required => 1,
20             );
21              
22             has pnref => (
23             is => 'lazy',
24             isa => NonEmptyStr,
25             default => sub { shift->params->{PNREF} },
26             );
27              
28             # PPREF is only returned if PayPal was the payment processor.
29             has ppref => (
30             is => 'lazy',
31             isa => Maybe [NonEmptyStr],
32             default => sub { shift->params->{PPREF} },
33             );
34              
35             with(
36             'WebService::PayPal::PaymentsAdvanced::Role::ClassFor',
37             'WebService::PayPal::PaymentsAdvanced::Role::HasParams',
38             'WebService::PayPal::PaymentsAdvanced::Role::HasMessage',
39             );
40              
41             sub BUILD {
42 63     63 0 132655 my $self = shift;
43              
44 63         329 my $result = $self->params->{RESULT};
45              
46             return
47             if Int()->check($result)
48 63 100 66 64   268 && ( any { $result == $_ } @{ $self->_nonfatal_result_codes } );
  64         743  
  63         2180  
49              
50 3 50 33     28 if ( $result && $result == 1 ) {
51 3         16 $self->_class_for('Error::Authentication')->throw(
52             message => 'Authentication error: ' . $self->message,
53             params => $self->params,
54             );
55             }
56              
57 0           $self->_class_for('Error::Generic')->throw(
58             message => $self->message,
59             params => $self->params,
60             );
61             }
62              
63             1;
64              
65             =pod
66              
67             =head1 NAME
68              
69             WebService::PayPal::PaymentsAdvanced::Response - Generic response object
70              
71             =head1 VERSION
72              
73             version 0.000026
74              
75             =head1 SYNOPSIS
76              
77             use WebService::PayPal::PaymentsAdvanced::Response;
78             my $response = WebService::PayPal::PaymentsAdvanced::Response->new(
79             params => $params );
80              
81             =head1 DESCRIPTION
82              
83             This module provides a consistent interface for getting information from a
84             PayPal response, regardless of whether it comes from token creation, a redirect
85             or a silent POST. It will be used as a parent class for other response
86             classes. You should never need to create this object yourself.
87              
88             =head1 METHODS
89              
90             =head2 message
91              
92             The contents of PayPal's RESPMSG parameter.
93              
94             =head2 params
95              
96             A C<HashRef> of parameters which have been returned by PayPal.
97              
98             =head2 pnref
99              
100             The contents of PayPal's PNREF parameter.
101              
102             =head2 ppref
103              
104             The contents of PayPal's PPREF parameter.
105              
106             =head1 SEE ALSO
107              
108             L<WebService::PayPal::PaymentsAdvanced::Response::FromHTTP>,
109             L<WebService::PayPal::PaymentsAdvanced::Response::FromRedirect>,
110             L<WebService::PayPal::PaymentsAdvanced::Response::FromSilentPost>,
111              
112             =head1 AUTHOR
113              
114             Olaf Alders <olaf@wundercounter.com>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2020 by MaxMind, Inc.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             =cut
124              
125             __END__
126             #ABSTRACT: Generic response object
127