line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Payjp; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
5695
|
use strict; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
240
|
|
4
|
9
|
|
|
9
|
|
51
|
use warnings; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
235
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
155098
|
use LWP::UserAgent; |
|
9
|
|
|
|
|
524834
|
|
|
9
|
|
|
|
|
338
|
|
7
|
9
|
|
|
9
|
|
7662
|
use LWP::Protocol::https; |
|
9
|
|
|
|
|
1062734
|
|
|
9
|
|
|
|
|
385
|
|
8
|
9
|
|
|
9
|
|
7885
|
use HTTP::Request::Common; |
|
9
|
|
|
|
|
25603
|
|
|
9
|
|
|
|
|
660
|
|
9
|
9
|
|
|
9
|
|
9580
|
use JSON; |
|
9
|
|
|
|
|
128229
|
|
|
9
|
|
|
|
|
58
|
|
10
|
|
|
|
|
|
|
|
11
|
9
|
|
|
9
|
|
7016
|
use Net::Payjp::Account; |
|
9
|
|
|
|
|
44
|
|
|
9
|
|
|
|
|
297
|
|
12
|
9
|
|
|
9
|
|
4773
|
use Net::Payjp::Charge; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
287
|
|
13
|
9
|
|
|
9
|
|
4659
|
use Net::Payjp::Customer; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
286
|
|
14
|
9
|
|
|
9
|
|
4589
|
use Net::Payjp::Plan; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
297
|
|
15
|
9
|
|
|
9
|
|
4701
|
use Net::Payjp::Subscription; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
313
|
|
16
|
9
|
|
|
9
|
|
5183
|
use Net::Payjp::Token; |
|
9
|
|
|
|
|
38
|
|
|
9
|
|
|
|
|
324
|
|
17
|
9
|
|
|
9
|
|
4791
|
use Net::Payjp::Transfer; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
352
|
|
18
|
9
|
|
|
9
|
|
4717
|
use Net::Payjp::Event; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
327
|
|
19
|
9
|
|
|
9
|
|
4639
|
use Net::Payjp::Object; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
13734
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ABSTRACT: API client for pay.jp |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Create charge |
26
|
|
|
|
|
|
|
my $payjp = Net::Payjp->new(api_key => $API_KEY); |
27
|
|
|
|
|
|
|
my $card = { |
28
|
|
|
|
|
|
|
number => '4242424242424242', |
29
|
|
|
|
|
|
|
exp_month => '02', |
30
|
|
|
|
|
|
|
exp_year => '2020', |
31
|
|
|
|
|
|
|
address_zip => '2020014' |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
my $res = $payjp->charge->create( |
34
|
|
|
|
|
|
|
card => $card, |
35
|
|
|
|
|
|
|
amount => 3500, |
36
|
|
|
|
|
|
|
currency => 'jpy', |
37
|
|
|
|
|
|
|
description => 'test charge', |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
if(my $e = $res->error){ |
40
|
|
|
|
|
|
|
print "Error; |
41
|
|
|
|
|
|
|
print $e->{message}."\n"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
# Id of charge. |
44
|
|
|
|
|
|
|
print $res->id; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Retrieve a charge |
47
|
|
|
|
|
|
|
$payjp->id($res->id); # Set id of charge |
48
|
|
|
|
|
|
|
$res = $payjp->charge->retrieve; # or $payjp->charge->retrieve($res->id); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This module is a wrapper around the Pay.jp HTTP API.Methods are generally named after the object name and the acquisition method. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This method returns json objects for responses from the API. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 new Method |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This creates a new Payjp api object. The following parameters are accepted: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=over |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item api_key |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This is required. You get this from your Payjp Account settings. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=back |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
our $VERSION = '0.1.4'; |
71
|
|
|
|
|
|
|
our $API_BASE = 'https://api.pay.jp'; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub new{ |
74
|
54
|
|
|
54
|
0
|
212
|
my $self = shift; |
75
|
54
|
|
|
|
|
172
|
bless{__PACKAGE__->_init(@_)},$self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _init{ |
79
|
54
|
|
|
54
|
|
81
|
my $self = shift; |
80
|
54
|
|
|
|
|
173
|
my %p = @_; |
81
|
|
|
|
|
|
|
return( |
82
|
|
|
|
|
|
|
api_key => $p{api_key}, |
83
|
|
|
|
|
|
|
id => $p{id}, |
84
|
|
|
|
|
|
|
cus_id => $p{cus_id}, |
85
|
54
|
|
|
|
|
563
|
version => $VERSION, |
86
|
|
|
|
|
|
|
api_base => $API_BASE, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub api_key{ |
91
|
47
|
|
|
47
|
1
|
73
|
my $self = shift; |
92
|
47
|
50
|
|
|
|
153
|
$self->{api_key} = shift if @_; |
93
|
47
|
|
|
|
|
207
|
return $self->{api_key}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub version{ |
97
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
98
|
2
|
50
|
|
|
|
9
|
$self->{version} = shift if @_; |
99
|
2
|
|
|
|
|
62
|
return $self->{version}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub api_base{ |
103
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
104
|
1
|
50
|
|
|
|
6
|
$self->{api_base} = shift if @_; |
105
|
1
|
|
|
|
|
16
|
return $self->{api_base}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub id{ |
109
|
49
|
|
|
49
|
0
|
72
|
my $self = shift; |
110
|
49
|
100
|
|
|
|
230
|
$self->{id} = shift if @_; |
111
|
49
|
|
|
|
|
216
|
return $self->{id}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub cus_id{ |
115
|
5
|
|
|
5
|
0
|
10
|
my $self = shift; |
116
|
5
|
100
|
|
|
|
32
|
$self->{cus_id} = shift if @_; |
117
|
5
|
|
|
|
|
56
|
return $self->{cus_id}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 Charge Methods |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 create |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Create a new charge |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $card = { |
129
|
|
|
|
|
|
|
number => '4242424242424242', |
130
|
|
|
|
|
|
|
exp_month => '02', |
131
|
|
|
|
|
|
|
exp_year => '2020', |
132
|
|
|
|
|
|
|
address_zip => '2020014' |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
$payjp->charge->create( |
135
|
|
|
|
|
|
|
card => $card, |
136
|
|
|
|
|
|
|
amount => 3500, |
137
|
|
|
|
|
|
|
currency => 'jpy', |
138
|
|
|
|
|
|
|
description => 'yakiimo', |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 retrieve |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Retrieve a charge |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$payjp->charge->retrieve('ch_fa990a4c10672a93053a774730b0a'); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 save |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Update a charge |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$payjp->id('ch_fa990a4c10672a93053a774730b0a'); |
156
|
|
|
|
|
|
|
$payjp->charge->save(description => 'update description.'); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 refund |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Refund a charge |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$payjp->id('ch_fa990a4c10672a93053a774730b0a'); |
165
|
|
|
|
|
|
|
$payjp->charge->refund(amount => 1000, refund_reason => 'test.'); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 capture |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Capture a charge |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$payjp->id('ch_fa990a4c10672a93053a774730b0a'); |
174
|
|
|
|
|
|
|
$payjp->charge->capture(amount => 2000); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 all |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Returns the charge list |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
$payjp->charge->all("limit" => 2, "offset" => 1); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 Customer Methods |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 create |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Create a cumtomer |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
$payjp->customer->create( |
193
|
|
|
|
|
|
|
"description" => "test", |
194
|
|
|
|
|
|
|
); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 retrieve |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Retrieve a customer |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
L |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
$payjp->customer->retrieve('cus_121673955bd7aa144de5a8f6c262'); |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 save |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Update a customer |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
$payjp->id('cus_121673955bd7aa144de5a8f6c262'); |
211
|
|
|
|
|
|
|
$payjp->customer->save(email => 'test@test.jp'); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 delete |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Delete a customer |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
L |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
$payjp->id('cus_121673955bd7aa144de5a8f6c262'); |
220
|
|
|
|
|
|
|
$payjp->customer->delete; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head2 all |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Returns the customer list |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
L |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
$res = $payjp->customer->all(limit => 2, offset => 1); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub charge{ |
233
|
7
|
|
|
7
|
0
|
46
|
my $self = shift; |
234
|
7
|
|
|
|
|
19
|
my $class = Net::Payjp::Charge->new(api_key => $self->api_key, id => $self->id); |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 Cutomer card Methods |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Returns a customer's card object |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
my $card = $payjp->customer->card('cus_4df4b5ed720933f4fb9e28857517'); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 create |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Create a customer's card |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
L |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
$card->create( |
250
|
|
|
|
|
|
|
number => '4242424242424242', |
251
|
|
|
|
|
|
|
exp_year => '2020', |
252
|
|
|
|
|
|
|
exp_month => '02' |
253
|
|
|
|
|
|
|
); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head2 retrieve |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Retrieve a customer's card |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
L |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
$card->retrieve('car_f7d9fa98594dc7c2e42bfcd641ff'); |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head2 save |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Update a customer's card |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
L |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
$card->id('car_f7d9fa98594dc7c2e42bfcd641ff'); |
270
|
|
|
|
|
|
|
$card->save(exp_year => "2026", exp_month => "05", name => 'test'); |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head2 delete |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Delete a customer's card |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
L |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
$card->id('car_f7d9fa98594dc7c2e42bfcd641ff'); |
279
|
|
|
|
|
|
|
$card->delete; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head2 all |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
Returns the customer's card list |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
L |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
$card->all(limit => 2, offset => 0); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=head1 Customer subscription Methods |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
Returns a customer's subscription object |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
my $subscription = $payjp->customer->subscription('sub_567a1e44562932ec1a7682d746e0'); |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head2 retrieve |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Retrieve a customer's subscription |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
L |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
$subscription->retrieve('sub_567a1e44562932ec1a7682d746e0'); |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head2 all |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
Returns the customer's subscription list |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
L |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
$subscription->all(limit => 1, offset => 0); |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=cut |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
sub customer{ |
314
|
10
|
|
|
10
|
0
|
95
|
my $self = shift; |
315
|
10
|
|
|
|
|
37
|
my $class = Net::Payjp::Customer->new(api_key => $self->api_key, id => $self->id); |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=head1 Plan Methods |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=head2 create |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Create a plan |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
L |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
$payjp->plan->create( |
327
|
|
|
|
|
|
|
amount => 500, |
328
|
|
|
|
|
|
|
currency => "jpy", |
329
|
|
|
|
|
|
|
interval => "month", |
330
|
|
|
|
|
|
|
trial_days => 30, |
331
|
|
|
|
|
|
|
name => 'test_plan' |
332
|
|
|
|
|
|
|
); |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=head2 retrieve |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
Retrieve a plan |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
L |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
$payjp->plan->retrieve('pln_45dd3268a18b2837d52861716260'); |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=head2 save |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
Update a plan |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
L |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
$payjp->id('pln_45dd3268a18b2837d52861716260'); |
349
|
|
|
|
|
|
|
$payjp->plan->save(name => 'NewPlan'); |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head2 delete |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
Delete a plan |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
L |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
$payjp->id('pln_45dd3268a18b2837d52861716260'); |
358
|
|
|
|
|
|
|
$payjp->plan->delete; |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=head2 all |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
Returns the plan list |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
L |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
$payjp->plan->all("limit" => 5, "offset" => 0); |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
=cut |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
sub plan{ |
371
|
6
|
|
|
6
|
0
|
46
|
my $self = shift; |
372
|
6
|
|
|
|
|
17
|
my $class = Net::Payjp::Plan->new(api_key => $self->api_key, id => $self->id); |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
=head1 Subscription Methods |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=head2 create |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
Create a subscription |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
L |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
$payjp->subscription->create( |
384
|
|
|
|
|
|
|
customer => 'cus_4df4b5ed720933f4fb9e28857517', |
385
|
|
|
|
|
|
|
plan => 'pln_9589006d14aad86aafeceac06b60' |
386
|
|
|
|
|
|
|
); |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
=head2 retrieve |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
Retrieve a subscription |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
L |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
$payjp->subscription->retrieve('sub_567a1e44562932ec1a7682d746e0'); |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=head2 save |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
Update a subscription |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
L |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
$payjp->id('sub_567a1e44562932ec1a7682d746e0'); |
403
|
|
|
|
|
|
|
$payjp->subscription->save(trial_end => 1473911903); |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
=head2 pause |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
Pause a subscription |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
L |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
$payjp->id('sub_567a1e44562932ec1a7682d746e0'); |
412
|
|
|
|
|
|
|
$payjp->subscription->pause; |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
=head2 resume |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
Resume a subscription |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
L |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
$payjp->id('sub_567a1e44562932ec1a7682d746e0'); |
421
|
|
|
|
|
|
|
$payjp->subscription->resume; |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
=head2 cancel |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
Cancel a subscription |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
L |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
$payjp->id('sub_567a1e44562932ec1a7682d746e0'); |
430
|
|
|
|
|
|
|
$payjp->subscription->cancel; |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=head2 delete |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
Delete a subscription |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
L |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
$payjp->id('sub_567a1e44562932ec1a7682d746e0'); |
439
|
|
|
|
|
|
|
$payjp->subscription->delete; |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
=head2 all |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
Returns the subscription list |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
L |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
$payjp->subscription->all(limit => 3, offset => 0); |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
=cut |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
sub subscription{ |
452
|
9
|
|
|
9
|
0
|
57
|
my $self = shift; |
453
|
9
|
|
|
|
|
23
|
my $class = Net::Payjp::Subscription->new(api_key => $self->api_key, id => $self->id); |
454
|
|
|
|
|
|
|
} |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
=head1 Token Methods |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=head2 create |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
Create a token |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
L |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
my $card = { |
465
|
|
|
|
|
|
|
number => '4242424242424242', |
466
|
|
|
|
|
|
|
cvc => "1234", |
467
|
|
|
|
|
|
|
exp_month => "02", |
468
|
|
|
|
|
|
|
exp_year =>"2020" |
469
|
|
|
|
|
|
|
}; |
470
|
|
|
|
|
|
|
$payjp->token->create( |
471
|
|
|
|
|
|
|
card => $card, |
472
|
|
|
|
|
|
|
); |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
=head2 retrieve |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
Retrieve a token |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
L |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
$payjp->token->retrieve('tok_eff34b780cbebd61e87f09ecc9c6'); |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
=cut |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
sub token{ |
485
|
3
|
|
|
3
|
0
|
85
|
my $self = shift; |
486
|
3
|
|
|
|
|
9
|
my $class = Net::Payjp::Token->new(api_key => $self->api_key, id => $self->id); |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
=head1 Transfer Methods |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
=head2 retrieve |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
Retrieve a transfer |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
L |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
$payjp->transfer->retrieve('tr_8f0c0fe2c9f8a47f9d18f03959ba1'); |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
=head2 all |
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
Returns the transfer list |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
L |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
$payjp->transfer->all("limit" => 3, offset => 0); |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
=head2 charges |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
Returns the charge list |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
L |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
$payjp->transfer->charges( |
514
|
|
|
|
|
|
|
limit => 3, |
515
|
|
|
|
|
|
|
offset => 0 |
516
|
|
|
|
|
|
|
); |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=cut |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
sub transfer{ |
521
|
4
|
|
|
4
|
0
|
43
|
my $self = shift; |
522
|
4
|
|
|
|
|
11
|
my $class = Net::Payjp::Transfer->new(api_key => $self->api_key, id => $self->id); |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
=head1 Event Methods |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
=head2 retrieve |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
Retrieve a event |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
L |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
$res = $payjp->event->retrieve('evnt_2f7436fe0017098bc8d22221d1e'); |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
=head2 all |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
Returns the event list |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
L |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
$payjp->event->all(limit => 10, offset => 0); |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
=cut |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
sub event{ |
546
|
3
|
|
|
3
|
0
|
38
|
my $self = shift; |
547
|
3
|
|
|
|
|
10
|
my $class = Net::Payjp::Event->new(api_key => $self->api_key, id => $self->id); |
548
|
|
|
|
|
|
|
} |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
=head1 Account Methods |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
=head2 retrieve |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
Retrieve a account |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
L |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
$payjp->account->retrieve; |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=cut |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
sub account{ |
563
|
2
|
|
|
2
|
0
|
8
|
my $self = shift; |
564
|
2
|
|
|
|
|
6
|
my $class = Net::Payjp::Account->new(api_key => $self->api_key); |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
sub _request{ |
568
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
569
|
1
|
|
|
|
|
5
|
my %p = @_; |
570
|
|
|
|
|
|
|
|
571
|
1
|
|
|
|
|
4
|
my $api_url = $p{url}; |
572
|
1
|
|
50
|
|
|
5
|
my $method = $p{method} || 'GET'; |
573
|
|
|
|
|
|
|
|
574
|
1
|
|
|
|
|
3
|
my $req; |
575
|
1
|
50
|
|
|
|
7
|
if($method eq 'GET'){ |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
576
|
0
|
0
|
|
|
|
0
|
if($p{param}){ |
577
|
0
|
|
|
|
|
0
|
my @param; |
578
|
0
|
|
|
|
|
0
|
foreach my $k(keys %{$p{param}}){ |
|
0
|
|
|
|
|
0
|
|
579
|
0
|
|
|
|
|
0
|
push(@param, "$k=".$p{param}->{$k}); |
580
|
|
|
|
|
|
|
} |
581
|
0
|
|
|
|
|
0
|
$req = GET("$api_url?".join("&", @param)); |
582
|
|
|
|
|
|
|
} |
583
|
|
|
|
|
|
|
else{ |
584
|
0
|
|
|
|
|
0
|
$req = GET($api_url); |
585
|
|
|
|
|
|
|
} |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
elsif($method eq 'POST'){ |
588
|
1
|
50
|
|
|
|
5
|
if(ref $p{param} eq 'HASH'){ |
589
|
1
|
|
|
|
|
9
|
$req = POST($api_url, $self->_api_param(param => $p{param})); |
590
|
|
|
|
|
|
|
} |
591
|
|
|
|
|
|
|
else{ |
592
|
0
|
|
|
|
|
0
|
$req = new HTTP::Request POST => $api_url; |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
} |
595
|
|
|
|
|
|
|
elsif($method eq 'DELETE'){ |
596
|
0
|
|
|
|
|
0
|
$req = new HTTP::Request(DELETE => $api_url); |
597
|
|
|
|
|
|
|
} |
598
|
|
|
|
|
|
|
|
599
|
1
|
|
|
|
|
19910
|
$req->authorization_basic($self->api_key, ''); |
600
|
|
|
|
|
|
|
|
601
|
1
|
|
|
|
|
5047
|
my $ua = LWP::UserAgent->new(); |
602
|
1
|
|
|
|
|
4238
|
$ua->timeout(30); |
603
|
1
|
|
|
|
|
36
|
my $client = { |
604
|
|
|
|
|
|
|
'bindings_version' => $self->version, |
605
|
|
|
|
|
|
|
'lang' => 'perl', |
606
|
|
|
|
|
|
|
'lang_version' => $], |
607
|
|
|
|
|
|
|
'publisher' => 'payjp', |
608
|
|
|
|
|
|
|
'uname' => $^O |
609
|
|
|
|
|
|
|
}; |
610
|
1
|
|
|
|
|
5
|
$ua->default_header( |
611
|
|
|
|
|
|
|
'User-Agent' => 'Payjp/v1 PerlBindings/'.$self->version, |
612
|
|
|
|
|
|
|
'X-Payjp-Client-User-Agent' => JSON->new->encode($client), |
613
|
|
|
|
|
|
|
); |
614
|
|
|
|
|
|
|
|
615
|
1
|
|
|
|
|
131
|
my $res = $ua->request($req); |
616
|
1
|
50
|
|
|
|
1524815
|
if($res->code == 200){ |
|
|
50
|
|
|
|
|
|
617
|
0
|
|
|
|
|
0
|
my $obj = $self->_to_object(JSON->new->decode($res->content)); |
618
|
0
|
0
|
|
|
|
0
|
$self->id($obj->id) if $obj->id; |
619
|
0
|
|
|
|
|
0
|
return $obj; |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
elsif($res->code =~ /^4/){ |
622
|
1
|
|
|
|
|
76
|
return $self->_to_object(JSON->new->decode($res->content)); |
623
|
|
|
|
|
|
|
} |
624
|
|
|
|
|
|
|
else{ |
625
|
0
|
0
|
|
|
|
0
|
if($res->content =~ /status_code/){ |
626
|
0
|
|
|
|
|
0
|
return $self->_to_object(JSON->new->decode($res->content)); |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
else{ |
629
|
0
|
|
|
|
|
0
|
return $self->_to_object( |
630
|
|
|
|
|
|
|
{ |
631
|
|
|
|
|
|
|
error => { |
632
|
|
|
|
|
|
|
message => $res->message, |
633
|
|
|
|
|
|
|
status_code => $res->code, |
634
|
|
|
|
|
|
|
} |
635
|
|
|
|
|
|
|
} |
636
|
|
|
|
|
|
|
); |
637
|
|
|
|
|
|
|
} |
638
|
|
|
|
|
|
|
} |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
sub _to_object{ |
642
|
45
|
|
|
45
|
|
2402
|
my $self = shift; |
643
|
45
|
|
|
|
|
72
|
my $hash = shift; |
644
|
|
|
|
|
|
|
|
645
|
45
|
|
|
|
|
333
|
return Net::Payjp::Object->new(%$hash); |
646
|
|
|
|
|
|
|
} |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
sub _api_param{ |
649
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
650
|
1
|
|
|
|
|
4
|
my %p = @_; |
651
|
1
|
|
|
|
|
3
|
my $param = $p{param}; |
652
|
|
|
|
|
|
|
|
653
|
1
|
|
|
|
|
2
|
my $req_param; |
654
|
1
|
|
|
|
|
2
|
foreach my $k(keys(%{$param})){ |
|
1
|
|
|
|
|
5
|
|
655
|
3
|
50
|
|
|
|
9
|
if(ref($param->{$k}) eq 'HASH'){ |
656
|
0
|
|
|
|
|
0
|
foreach(keys(%{$param->{$k}})){ |
|
0
|
|
|
|
|
0
|
|
657
|
0
|
|
|
|
|
0
|
$req_param->{$k.'['.$_.']'} = $param->{$k}->{$_}; |
658
|
|
|
|
|
|
|
} |
659
|
|
|
|
|
|
|
} |
660
|
|
|
|
|
|
|
else{ |
661
|
3
|
|
|
|
|
9
|
$req_param->{$k} = $param->{$k}; |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
} |
664
|
1
|
|
|
|
|
9
|
return $req_param; |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
1; |