PayPal/API/Plans.pm

filter: Statementstmt 70.6% 41 / 58 Branchbran 32.3% 11 / 34 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 8 / 12 Podpod 100% 6 / 6 totaltotal 57.9% 69 / 119 CC 22 SCAR 23.6
CC
22
Cov
56%
list
30.0
create
11.1
create_monthly
8.0
CRAP 10.5
« PayPal/API/Payments.pm ↑ Summary PayPal/Role/OpenAPI.pm »
1 package WWW::PayPal::API::Plans;
2  
3 # ABSTRACT: PayPal Billing Plans API (v1)
4  
5 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use WWW::PayPal::Plan;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.002';
11  
12  
13 2 has client => (
14 is => 'ro',
15 required => 1,
16 weak_ref => 1,
17 );
18  
19 has openapi_operations => (
20 is => 'lazy',
21 builder => sub {
22 return {
23 1 ▶ 'billing.plans.create' => { method => 'POST', path => '/v1/billing/plans' },
Subroutine __ANON__: called CC=1 SCAR=0.0
24 'billing.plans.list' => { method => 'GET', path => '/v1/billing/plans' },
25 'billing.plans.get' => { method => 'GET', path => '/v1/billing/plans/{id}' },
26 'billing.plans.patch' => { method => 'PATCH', path => '/v1/billing/plans/{id}' },
27 'billing.plans.activate' => { method => 'POST', path => '/v1/billing/plans/{id}/activate' },
28 'billing.plans.deactivate' => { method => 'POST', path => '/v1/billing/plans/{id}/deactivate' },
29 };
30 },
31 2 );
32  
33 2 with 'WWW::PayPal::Role::OpenAPI';
34  
35 sub _wrap {
36 1 ▶ my ($self, $data) = @_;
Subroutine _wrap: called CC=1 SCAR=0.0
37 1 return WWW::PayPal::Plan->new(client => $self->client, data => $data);
38 }
39  
40 sub create {
41 1 ▶ my ($self, %args) = @_;
Subroutine create: called CC=9 SCAR=24.1
Pod documented
42 1 ▶ croak 'product_id required' unless $args{product_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"product_id"} 0 1 1
43 1 ▶ croak 'name required' unless $args{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"name"} 0 1 1
44 1 ▶ croak 'billing_cycles required' unless ref $args{billing_cycles} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"billing_cycles"} eq "ARRAY" 0 1 1
45  
46 my %body = (
47 product_id => $args{product_id},
48 name => $args{name},
49 billing_cycles => $args{billing_cycles},
50 payment_preferences => $args{payment_preferences} // {
51 1 ▶ auto_bill_outstanding => \1,
Condition50%1/2
$args{"payment_preferences"} // {"auto_bill_outstanding", \1, "payment_failure_threshold", 3}
l!l
01
MC/DC0%0/1
$args{"payment_preferences"} // {"auto_bill_outstanding", \1, "payment_failure_threshold", 3}
$args{"payment_preferences"}
Truth table50%1/2
A
A= $args{"payment_preferences"}
Aresult
11
00
52 payment_failure_threshold => 3,
53 },
54 );
55 1 ▶ $body{description} = $args{description} if defined $args{description};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"description"} 0 1 1
56 1 ▶ $body{status} = $args{status} if defined $args{status};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"status"} 0 1 1
57 1 ▶ $body{taxes} = $args{taxes} if $args{taxes};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"taxes"} 0 1 1
58 1 ▶ $body{quantity_supported} = $args{quantity_supported} if defined $args{quantity_supported};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"quantity_supported"} 0 1 1
59  
60 1 my $data = $self->call_operation('billing.plans.create', body => \%body);
61 1 return $self->_wrap($data);
62 }
63  
64  
65 sub create_monthly {
66 1 ▶ my ($self, %args) = @_;
Subroutine create_monthly: called CC=7 SCAR=20.8
Pod documented
67 1 ▶ croak 'product_id required' unless $args{product_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"product_id"} 0 1 1
68 1 ▶ croak 'name required' unless $args{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"name"} 0 1 1
69 1 ▶ croak 'price required' unless defined $args{price};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"price"} 0 1 1
70 1 ▶ my $currency = $args{currency} || 'EUR';
Condition50%1/2
$args{'currency'} || 'EUR'
l!l
10
MC/DC0%0/1
$args{'currency'} || 'EUR'
$args{'currency'}
Truth table50%1/2
A
A= $args{'currency'}
Aresult
11
00
71  
72 1 my @cycles;
73 1 ▶ if ($args{trial_days}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"trial_days"}) 1 0 1
74 push @cycles, {
75 frequency => { interval_unit => 'DAY', interval_count => 0 + $args{trial_days} },
76 1 tenure_type => 'TRIAL',
77 sequence => 1,
78 total_cycles => 1,
79 pricing_scheme => {
80 fixed_price => { value => '0', currency_code => $currency },
81 },
82 };
83 }
84 push @cycles, {
85 frequency => { interval_unit => 'MONTH', interval_count => 1 },
86 tenure_type => 'REGULAR',
87 sequence => scalar(@cycles) + 1,
88 1 ▶ total_cycles => $args{total_cycles} // 0, # 0 = forever
Condition50%1/2
$args{"total_cycles"} // 0
l!l
01
MC/DC0%0/1
$args{"total_cycles"} // 0
$args{"total_cycles"}
Truth table50%1/2
A
A= $args{"total_cycles"}
Aresult
11
00
89 pricing_scheme => {
90 fixed_price => { value => "$args{price}", currency_code => $currency },
91 },
92 };
93  
94 return $self->create(
95 product_id => $args{product_id},
96 name => $args{name},
97 description => $args{description},
98 1 billing_cycles => \@cycles,
99 );
100 }
101  
102  
103 sub get {
104 0 ▶ my ($self, $id) = @_;
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
105 0 ▶ croak 'plan id required' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
106 0 return $self->_wrap($self->call_operation('billing.plans.get', path => { id => $id }));
107 }
108  
109  
110 sub list {
111 0 ▶ my ($self, %args) = @_;
Subroutine list: not called CC=5 SCAR=34.0
Pod documented
112 0 my %query;
113 0 for my $k (qw(product_id plan_ids page_size page total_required)) {
114 0 ▶ $query{$k} = $args{$k} if defined $args{$k};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{$k} 0 0 0
115 }
116 0 ▶ my $data = $self->call_operation('billing.plans.list',
Branch: 1 branch
BranchTrueFalseTotal
%query ? : 0 0 0
117 (%query ? (query => \%query) : ()));
118 0 ▶ return [ map { $self->_wrap($_) } @{ $data->{plans} || [] } ];
Branch: 1 branch
BranchTrueFalseTotal
$data->{"plans"} or [] 0 0 0
119 }
120  
121  
122 sub activate {
123 0 ▶ my ($self, $id) = @_;
Subroutine activate: not called CC=2 SCAR=17.9
Pod documented
124 0 ▶ croak 'plan id required' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
125 0 return $self->call_operation('billing.plans.activate', path => { id => $id }, body => '');
126 }
127  
128 sub deactivate {
129 0 ▶ my ($self, $id) = @_;
Subroutine deactivate: not called CC=2 SCAR=17.9
Pod documented
130 0 ▶ croak 'plan id required' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
131 0 return $self->call_operation('billing.plans.deactivate', path => { id => $id }, body => '');
132 }
133  
134  
135 2 1;
136  
137 __END__
« PayPal/API/Payments.pm ↑ Summary PayPal/Role/OpenAPI.pm »