line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::PayflowPro::Reporting; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
1
|
|
|
1
|
|
22945
|
$Business::PayflowPro::Reporting::VERSION = '0.01'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Payflow Pro Reporting API |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
11
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
11
|
1
|
|
|
1
|
|
1210
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
50711
|
|
|
1
|
|
|
|
|
29
|
|
12
|
1
|
|
|
1
|
|
1126
|
use XML::Writer; |
|
1
|
|
|
|
|
15064
|
|
|
1
|
|
|
|
|
33
|
|
13
|
1
|
|
|
1
|
|
457
|
use XML::Simple qw/XMLin XMLout/; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use vars qw/$errstr/; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
my $class = shift; |
18
|
|
|
|
|
|
|
my $args = scalar @_ % 2 ? shift : {@_}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# validate |
21
|
|
|
|
|
|
|
defined $args->{user} or do { $errstr = 'user is required'; return }; |
22
|
|
|
|
|
|
|
defined $args->{vendor} or do { $errstr = 'vendor is required'; return }; |
23
|
|
|
|
|
|
|
defined $args->{partner} or do { $errstr = 'partner is required'; return }; |
24
|
|
|
|
|
|
|
defined $args->{password} |
25
|
|
|
|
|
|
|
or do { $errstr = 'password is required'; return }; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if ( $args->{test_mode} ) { |
28
|
|
|
|
|
|
|
$args->{url} = |
29
|
|
|
|
|
|
|
'https://payments-reports.paypal.com/test-reportingengine'; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
|
|
|
|
|
|
$args->{url} = 'https://payments-reports.paypal.com/reportingengine'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
unless ( $args->{ua} ) { |
36
|
|
|
|
|
|
|
my $ua_args = delete $args->{ua_args} || {}; |
37
|
|
|
|
|
|
|
$args->{ua} = LWP::UserAgent->new(%$ua_args); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
bless $args, $class; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub errstr { $errstr } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub runReportRequest { |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
my $args = scalar @_ % 2 ? shift : {@_}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# we use XML::Writer b/c element order is relevant |
50
|
|
|
|
|
|
|
my $xml; |
51
|
|
|
|
|
|
|
my $writer = XML::Writer->new( OUTPUT => \$xml ); |
52
|
|
|
|
|
|
|
$writer->startTag('reportingEngineRequest'); |
53
|
|
|
|
|
|
|
$writer->startTag('authRequest'); |
54
|
|
|
|
|
|
|
foreach my $k ( 'user', 'vendor', 'partner', 'password' ) { |
55
|
|
|
|
|
|
|
$writer->dataElement( $k, $self->{$k} ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
$writer->endTag('authRequest'); |
58
|
|
|
|
|
|
|
$writer->startTag('runReportRequest'); |
59
|
|
|
|
|
|
|
$writer->dataElement( 'reportName', $args->{reportName} ); |
60
|
|
|
|
|
|
|
if ( $args->{reportName} eq 'DailyActivityReport' ) { |
61
|
|
|
|
|
|
|
$writer->startTag('reportParam'); |
62
|
|
|
|
|
|
|
$writer->dataElement( 'paramName', 'report_date' ); |
63
|
|
|
|
|
|
|
$writer->dataElement( 'paramValue', $args->{report_date} ); |
64
|
|
|
|
|
|
|
$writer->endTag('reportParam'); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif ( $args->{reportName} eq 'TransactionSummaryReport' ) { |
67
|
|
|
|
|
|
|
foreach my $k ( 'start_date', 'end_date' ) { |
68
|
|
|
|
|
|
|
$writer->startTag('reportParam'); |
69
|
|
|
|
|
|
|
$writer->dataElement( 'paramName', $k ); |
70
|
|
|
|
|
|
|
$writer->dataElement( 'paramValue', $args->{$k} ); |
71
|
|
|
|
|
|
|
$writer->endTag('reportParam'); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
$writer->dataElement( 'pageSize', $args->{pageSize} || 50 ); |
75
|
|
|
|
|
|
|
$writer->endTag('runReportRequest'); |
76
|
|
|
|
|
|
|
$writer->endTag('reportingEngineRequest'); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$xml = '' . "\n" . $xml; |
79
|
|
|
|
|
|
|
print "\n\n" if $self->{debug}; |
80
|
|
|
|
|
|
|
my $resp = $self->{ua}->post( $self->{url}, Content => $xml ); |
81
|
|
|
|
|
|
|
print "\n\n" if $self->{debug}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $d = XMLin( $resp->content, SuppressEmpty => '' ); |
84
|
|
|
|
|
|
|
if ( exists $d->{runReportResponse}->{reportId} ) { |
85
|
|
|
|
|
|
|
return $d->{runReportResponse}->{reportId}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
|
|
|
|
|
|
$errstr = $d->{runReportResponse}->{statusMsg} |
89
|
|
|
|
|
|
|
|| $d->{baseResponse}->{responseMsg}; |
90
|
|
|
|
|
|
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub getResultsRequest { |
95
|
|
|
|
|
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
my ($reportId) = @_; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $xml = $self->_make_reportId_xml( 'getResultsRequest', $reportId ); |
99
|
|
|
|
|
|
|
my $resp = $self->{ua}->post( $self->{url}, Content => $xml ); |
100
|
|
|
|
|
|
|
print "\n\n" if $self->{debug}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $d = XMLin( $resp->content, SuppressEmpty => '' ); |
103
|
|
|
|
|
|
|
if ( $d->{baseResponse}->{responseCode} == 100 ) { |
104
|
|
|
|
|
|
|
return $d->{getResultsResponse}->{Results}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
|
|
|
|
|
|
$errstr = $d->{getResultsResponse}->{Results}->{statusMsg} |
108
|
|
|
|
|
|
|
|| $d->{baseResponse}->{responseMsg}; |
109
|
|
|
|
|
|
|
return; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub getMetaDataRequest { |
114
|
|
|
|
|
|
|
my $self = shift; |
115
|
|
|
|
|
|
|
my ($reportId) = @_; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $xml = $self->_make_reportId_xml( 'getMetaDataRequest', $reportId ); |
118
|
|
|
|
|
|
|
my $resp = $self->{ua}->post( $self->{url}, Content => $xml ); |
119
|
|
|
|
|
|
|
print "\n\n" if $self->{debug}; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $d = XMLin( $resp->content, SuppressEmpty => '' ); |
122
|
|
|
|
|
|
|
if ( $d->{baseResponse}->{responseCode} == 100 ) { |
123
|
|
|
|
|
|
|
return $d->{getMetaDataResponse}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
|
|
|
|
|
|
$errstr = $d->{baseResponse}->{responseMsg}; |
127
|
|
|
|
|
|
|
return; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _make_reportId_xml { |
132
|
|
|
|
|
|
|
my ( $self, $type, $reportId ) = @_; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# we use XML::Writer b/c element order is relevant |
135
|
|
|
|
|
|
|
my $xml; |
136
|
|
|
|
|
|
|
my $writer = XML::Writer->new( OUTPUT => \$xml ); |
137
|
|
|
|
|
|
|
$writer->startTag('reportingEngineRequest'); |
138
|
|
|
|
|
|
|
$writer->startTag('authRequest'); |
139
|
|
|
|
|
|
|
foreach my $k ( 'user', 'vendor', 'partner', 'password' ) { |
140
|
|
|
|
|
|
|
$writer->dataElement( $k, $self->{$k} ); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
$writer->endTag('authRequest'); |
143
|
|
|
|
|
|
|
$writer->startTag($type); |
144
|
|
|
|
|
|
|
$writer->dataElement( 'reportId', $reportId ); |
145
|
|
|
|
|
|
|
$writer->endTag($type); |
146
|
|
|
|
|
|
|
$writer->endTag('reportingEngineRequest'); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$xml = '' . "\n" . $xml; |
149
|
|
|
|
|
|
|
print "\n\n" if $self->{debug}; |
150
|
|
|
|
|
|
|
return $xml; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub getDataRequest { |
154
|
|
|
|
|
|
|
my $self = shift; |
155
|
|
|
|
|
|
|
my ( $reportId, $pageNum ) = @_; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# we use XML::Writer b/c element order is relevant |
158
|
|
|
|
|
|
|
my $xml; |
159
|
|
|
|
|
|
|
my $writer = XML::Writer->new( OUTPUT => \$xml ); |
160
|
|
|
|
|
|
|
$writer->startTag('reportingEngineRequest'); |
161
|
|
|
|
|
|
|
$writer->startTag('authRequest'); |
162
|
|
|
|
|
|
|
foreach my $k ( 'user', 'vendor', 'partner', 'password' ) { |
163
|
|
|
|
|
|
|
$writer->dataElement( $k, $self->{$k} ); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
$writer->endTag('authRequest'); |
166
|
|
|
|
|
|
|
$writer->startTag('getDataRequest'); |
167
|
|
|
|
|
|
|
$writer->dataElement( 'reportId', $reportId ); |
168
|
|
|
|
|
|
|
$writer->dataElement( 'pageNum', $pageNum || 1 ); |
169
|
|
|
|
|
|
|
$writer->endTag('getDataRequest'); |
170
|
|
|
|
|
|
|
$writer->endTag('reportingEngineRequest'); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
$xml = '' . "\n" . $xml; |
173
|
|
|
|
|
|
|
print "\n\n" if $self->{debug}; |
174
|
|
|
|
|
|
|
my $resp = $self->{ua}->post( $self->{url}, Content => $xml ); |
175
|
|
|
|
|
|
|
print "\n\n" if $self->{debug}; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $d = XMLin( $resp->content, SuppressEmpty => '' ); |
178
|
|
|
|
|
|
|
if ( $d->{baseResponse}->{responseCode} == 100 ) { |
179
|
|
|
|
|
|
|
my $reportDataRow = $d->{getDataResponse}->{reportDataRow}; |
180
|
|
|
|
|
|
|
my @reportDataRow = |
181
|
|
|
|
|
|
|
ref($reportDataRow) eq 'ARRAY' ? @$reportDataRow : ($reportDataRow); |
182
|
|
|
|
|
|
|
return wantarray ? @reportDataRow : \@reportDataRow; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
else { |
185
|
|
|
|
|
|
|
$errstr = $d->{baseResponse}->{responseMsg}; |
186
|
|
|
|
|
|
|
return; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
1; |
191
|
|
|
|
|
|
|
__END__ |