Payjp.pm

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