| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::PayPal::NVP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
274858
|
use Moo; |
|
|
5
|
|
|
|
|
80168
|
|
|
|
5
|
|
|
|
|
30
|
|
|
4
|
5
|
|
|
5
|
|
13341
|
use DateTime; |
|
|
5
|
|
|
|
|
706729
|
|
|
|
5
|
|
|
|
|
249
|
|
|
5
|
5
|
|
|
5
|
|
6043
|
use LWP::UserAgent (); |
|
|
5
|
|
|
|
|
227519
|
|
|
|
5
|
|
|
|
|
162
|
|
|
6
|
5
|
|
|
5
|
|
3200
|
use MooX::Types::MooseLike::Base qw( InstanceOf ); |
|
|
5
|
|
|
|
|
33068
|
|
|
|
5
|
|
|
|
|
467
|
|
|
7
|
5
|
|
|
5
|
|
45
|
use URI::Escape qw/uri_escape uri_escape_utf8 uri_unescape/; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
286
|
|
|
8
|
5
|
|
|
5
|
|
2760
|
use WebService::PayPal::NVP::Response; |
|
|
5
|
|
|
|
|
19
|
|
|
|
5
|
|
|
|
|
2707
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'errors' => ( |
|
13
|
|
|
|
|
|
|
is => 'rw', |
|
14
|
|
|
|
|
|
|
isa => sub { |
|
15
|
|
|
|
|
|
|
die "errors expects an array reference!\n" |
|
16
|
|
|
|
|
|
|
unless ref $_[0] eq 'ARRAY'; |
|
17
|
|
|
|
|
|
|
}, |
|
18
|
|
|
|
|
|
|
default => sub { [] }, |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'ua' => ( |
|
22
|
|
|
|
|
|
|
is => 'ro', |
|
23
|
|
|
|
|
|
|
isa => InstanceOf['LWP::UserAgent'], |
|
24
|
|
|
|
|
|
|
builder => '_build_ua' |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'user' => ( is => 'rw', required => 1 ); |
|
28
|
|
|
|
|
|
|
has 'pwd' => ( is => 'rw', required => 1 ); |
|
29
|
|
|
|
|
|
|
has 'sig' => ( is => 'rw', required => 1 ); |
|
30
|
|
|
|
|
|
|
has 'url' => ( is => 'rw' ); |
|
31
|
|
|
|
|
|
|
has 'branch' => ( is => 'rw', default => sub { 'sandbox' } ); |
|
32
|
|
|
|
|
|
|
has 'api_ver' => ( is => 'rw', default => sub { 51.0 } ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub BUILDARGS { |
|
35
|
1
|
|
|
1
|
0
|
670052
|
my ($class, %args) = @_; |
|
36
|
|
|
|
|
|
|
# detect URL if it's missing |
|
37
|
1
|
50
|
|
|
|
8
|
if (not $args{url}) { |
|
38
|
1
|
50
|
|
|
|
7
|
$args{url} = "https://api-3t.sandbox.paypal.com/nvp" |
|
39
|
|
|
|
|
|
|
if $args{branch} eq 'sandbox'; |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
50
|
|
|
|
10
|
$args{url} = "https://api-3t.paypal.com/nvp" |
|
42
|
|
|
|
|
|
|
if $args{branch} eq 'live'; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
34
|
return \%args; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
sub _build_ua { |
|
48
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $lwp = LWP::UserAgent->new; |
|
51
|
0
|
|
|
|
|
|
$lwp->agent("p-Webservice-PayPal-NVP/${VERSION}"); |
|
52
|
0
|
|
|
|
|
|
return $lwp; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _do_request { |
|
56
|
0
|
|
|
0
|
|
|
my ($self, $args) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new(POST => $self->url); |
|
59
|
0
|
|
|
|
|
|
$req->content_type('application/x-www-form-urlencoded'); |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
0
|
|
|
|
my $authargs = { |
|
|
|
|
0
|
|
|
|
|
|
62
|
|
|
|
|
|
|
user => $self->user, |
|
63
|
|
|
|
|
|
|
pwd => $self->pwd, |
|
64
|
|
|
|
|
|
|
signature => $self->sig, |
|
65
|
|
|
|
|
|
|
version => $args->{version}||$self->api_ver, |
|
66
|
|
|
|
|
|
|
subject => $args->{subject}||'', |
|
67
|
|
|
|
|
|
|
}; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $allargs = { %$authargs, %$args }; |
|
70
|
0
|
|
|
|
|
|
my $content = $self->_build_content( $allargs ); |
|
71
|
0
|
|
|
|
|
|
$req->content($content); |
|
72
|
0
|
|
|
|
|
|
my $res = $self->ua->request($req); |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
unless ($res->code == 200) { |
|
75
|
0
|
|
|
|
|
|
$self->errors(["Failure: " . $res->code . ": " . $res->message]); |
|
76
|
0
|
|
|
|
|
|
return; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $resp = { map { uri_unescape($_) } |
|
|
0
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
map { split '=', $_, 2 } |
|
81
|
|
|
|
|
|
|
split '&', $res->content }; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $res_object = WebService::PayPal::NVP::Response->new( |
|
84
|
|
|
|
|
|
|
branch => $self->branch |
|
85
|
|
|
|
|
|
|
); |
|
86
|
|
|
|
|
|
|
; |
|
87
|
0
|
0
|
|
|
|
|
if ($resp->{ACK} ne 'Success') { |
|
88
|
0
|
|
|
|
|
|
$res_object->errors([]); |
|
89
|
0
|
|
|
|
|
|
my $i = 0; |
|
90
|
0
|
|
|
|
|
|
while(my $err = $resp->{"L_LONGMESSAGE${i}"}) { |
|
91
|
0
|
|
|
|
|
|
push @{$res_object->errors}, |
|
|
0
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$resp->{"L_LONGMESSAGE${i}"}; |
|
93
|
0
|
|
|
|
|
|
$i += 1; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$res_object->success(0); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
else { |
|
99
|
0
|
|
|
|
|
|
$res_object->success(1); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
{ |
|
103
|
5
|
|
|
5
|
|
45
|
no strict 'refs'; |
|
|
5
|
|
|
|
|
5
|
|
|
|
5
|
|
|
|
|
179
|
|
|
|
0
|
|
|
|
|
|
|
|
104
|
5
|
|
|
5
|
|
31
|
no warnings 'redefine'; |
|
|
5
|
|
|
|
|
5
|
|
|
|
5
|
|
|
|
|
2994
|
|
|
105
|
0
|
|
|
|
|
|
foreach my $key (keys %$resp) { |
|
106
|
0
|
|
|
|
|
|
my $val = $resp->{$key}; |
|
107
|
0
|
|
|
|
|
|
my $lc_key = lc $key; |
|
108
|
0
|
0
|
|
|
|
|
if ($lc_key eq 'timestamp') { |
|
109
|
0
|
0
|
|
|
|
|
if ($val =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/) { |
|
110
|
0
|
|
|
|
|
|
my ($day, $month, $year, $hour, $min, $sec) |
|
111
|
|
|
|
|
|
|
= ($3, $2, $1, $4, $5, $6); |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$val = DateTime->new( |
|
114
|
|
|
|
|
|
|
year => $year, |
|
115
|
|
|
|
|
|
|
month => $month, |
|
116
|
|
|
|
|
|
|
day => $day, |
|
117
|
|
|
|
|
|
|
hour => $hour, |
|
118
|
|
|
|
|
|
|
minute => $min, |
|
119
|
|
|
|
|
|
|
second => $sec, |
|
120
|
|
|
|
|
|
|
); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
0
|
|
|
|
|
|
*{"WebService::PayPal::NVP::Response::$lc_key"} = sub { |
|
124
|
0
|
|
|
0
|
|
|
return $val; |
|
125
|
0
|
|
|
|
|
|
}; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
0
|
|
|
|
|
|
return $res_object; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _build_content { |
|
132
|
0
|
|
|
0
|
|
|
my ($self, $args) = @_; |
|
133
|
0
|
|
|
|
|
|
my @args; |
|
134
|
0
|
|
|
|
|
|
for my $key (keys %$args) { |
|
135
|
0
|
0
|
|
|
|
|
$args->{$key} = defined $args->{$key} ? $args->{$key} : ''; |
|
136
|
0
|
|
|
|
|
|
push @args, |
|
137
|
|
|
|
|
|
|
uc(uri_escape($key)) . '=' . uri_escape_utf8($args->{$key}); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
0
|
|
|
|
return (join '&', @args) || ''; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub has_errors { |
|
144
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
145
|
0
|
|
|
|
|
|
return scalar @{$self->errors} > 0; |
|
|
0
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub set_express_checkout { |
|
149
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
150
|
0
|
|
|
|
|
|
$args->{method} = 'SetExpressCheckout'; |
|
151
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub do_express_checkout_payment { |
|
155
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
156
|
0
|
|
|
|
|
|
$args->{method} = 'DoExpressCheckoutPayment'; |
|
157
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub get_express_checkout_details { |
|
161
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
162
|
0
|
|
|
|
|
|
$args->{method} = 'GetExpressCheckoutDetails'; |
|
163
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub do_direct_payment { |
|
167
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
168
|
0
|
|
|
|
|
|
$args->{method} = 'DoDirectPayment'; |
|
169
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub create_recurring_payments_profile { |
|
173
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
174
|
0
|
|
|
|
|
|
$args->{method} = 'CreateRecurringPaymentsProfile'; |
|
175
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub get_recurring_payments_profile_details { |
|
179
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
180
|
0
|
|
|
|
|
|
$args->{method} = 'GetRecurringPaymentsProfileDetails'; |
|
181
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub manage_recurring_payments_profile_status { |
|
185
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
186
|
0
|
|
|
|
|
|
$args->{method} = 'ManageRecurringPaymentsProfileStatus'; |
|
187
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub mass_pay { |
|
191
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
192
|
0
|
|
|
|
|
|
$args->{method} = 'MassPay'; |
|
193
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub refund_transaction { |
|
197
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
|
198
|
0
|
|
|
|
|
|
$args->{method} = 'RefundTransaction'; |
|
199
|
0
|
|
|
|
|
|
$self->_do_request($args); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
1; |
|
203
|
|
|
|
|
|
|
__END__ |