| 1 | package WWW::PayPal::API::Plans; | ||||||||||||
| 2 | |||||||||||||
| 3 | # ABSTRACT: PayPal Billing Plans API (v1) | ||||||||||||
| 4 | |||||||||||||
| 5 | 3 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use WWW::PayPal::Plan; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 3 | our $VERSION = '0.003'; | |||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | 3 | has client => ( | |||||||||||
| 14 | is => 'ro', | ||||||||||||
| 15 | required => 1, | ||||||||||||
| 16 | weak_ref => 1, | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | has openapi_operations => ( | ||||||||||||
| 20 | is => 'lazy', | ||||||||||||
| 21 | 0 | ▶ | builder => sub { | ||||||||||
|
Subroutine
_build_openapi_operations: not called CC=1 SCAR=1.2
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||||||||||||
| 22 | return { | ||||||||||||
| 23 | 0 | 'billing.plans.create' => { method => 'POST', path => '/v1/billing/plans' }, | |||||||||||
| 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 | 3 | ); | |||||||||||
| 32 | |||||||||||||
| 33 | 3 | with 'WWW::PayPal::Role::OpenAPI'; | |||||||||||
| 34 | |||||||||||||
| 35 | 1 | ▶ | sub _wrap { | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 36 | 1 | my ($self, $data) = @_; | |||||||||||
| 37 | 1 | return WWW::PayPal::Plan->new(client => $self->client, data => $data); | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 1 | ▶ | sub create { | ||||||||||
|
Subroutine
create: called CC=9 SCAR=24.1
Pod
documented
| |||||||||||||
| 41 | 1 | my ($self, %args) = @_; | |||||||||||
| 42 | 1 | ▶ | croak 'product_id required' unless $args{product_id}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 1 | ▶ | croak 'name required' unless $args{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 1 | ▶ | croak 'billing_cycles required' unless ref $args{billing_cycles} eq 'ARRAY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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}
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"}
| |||||||||||||
| 52 | payment_failure_threshold => 3, | ||||||||||||
| 53 | }, | ||||||||||||
| 54 | ); | ||||||||||||
| 55 | 1 | ▶ | $body{description} = $args{description} if defined $args{description}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 1 | ▶ | $body{status} = $args{status} if defined $args{status}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 1 | ▶ | $body{taxes} = $args{taxes} if $args{taxes}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 1 | ▶ | $body{quantity_supported} = $args{quantity_supported} if defined $args{quantity_supported}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | |||||||||||||
| 60 | 1 | my $data = $self->call_operation('billing.plans.create', body => \%body); | |||||||||||
| 61 | 1 | return $self->_wrap($data); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | |||||||||||||
| 65 | 1 | ▶ | sub create_monthly { | ||||||||||
|
Subroutine
create_monthly: called CC=7 SCAR=20.8
Pod
documented
| |||||||||||||
| 66 | 1 | my ($self, %args) = @_; | |||||||||||
| 67 | 1 | ▶ | croak 'product_id required' unless $args{product_id}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | 1 | ▶ | croak 'name required' unless $args{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 1 | ▶ | croak 'price required' unless defined $args{price}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 1 | ▶ | my $currency = $args{currency} || 'EUR'; | ||||||||||
|
Condition50%1/2
$args{'currency'} || 'EUR'
MC/DC0%0/1
$args{'currency'} || 'EUR'
$args{'currency'}
Truth table50%1/2
A
A= $args{'currency'}
| |||||||||||||
| 71 | |||||||||||||
| 72 | 1 | my @cycles; | |||||||||||
| 73 | 1 | ▶ | if ($args{trial_days}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
MC/DC0%0/1
$args{"total_cycles"} // 0
$args{"total_cycles"}
Truth table50%1/2
A
A= $args{"total_cycles"}
| |||||||||||||
| 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 | 0 | ▶ | sub get { | ||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 104 | 0 | my ($self, $id) = @_; | |||||||||||
| 105 | 0 | ▶ | croak 'plan id required' unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 0 | return $self->_wrap($self->call_operation('billing.plans.get', path => { id => $id })); | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | |||||||||||||
| 110 | 0 | ▶ | sub list { | ||||||||||
|
Subroutine
list: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 111 | 0 | my ($self, %args) = @_; | |||||||||||
| 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
| |||||||||||||
| 115 | } | ||||||||||||
| 116 | 0 | ▶ | my $data = $self->call_operation('billing.plans.list', | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 117 | (%query ? (query => \%query) : ())); | ||||||||||||
| 118 | 0 | ▶ | return [ map { $self->_wrap($_) } @{ $data->{plans} || [] } ]; | ||||||||||
|
Condition0%0/2
$data->{'plans'} || []
MC/DC0%0/1
$data->{'plans'} || []
$data->{'plans'}
Truth table0%0/2
A
A= $data->{'plans'}
| |||||||||||||
| 119 | } | ||||||||||||
| 120 | |||||||||||||
| 121 | |||||||||||||
| 122 | 0 | ▶ | sub activate { | ||||||||||
|
Subroutine
activate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 123 | 0 | my ($self, $id) = @_; | |||||||||||
| 124 | 0 | ▶ | croak 'plan id required' unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 125 | 0 | return $self->call_operation('billing.plans.activate', path => { id => $id }, body => ''); | |||||||||||
| 126 | } | ||||||||||||
| 127 | |||||||||||||
| 128 | 0 | ▶ | sub deactivate { | ||||||||||
|
Subroutine
deactivate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 129 | 0 | my ($self, $id) = @_; | |||||||||||
| 130 | 0 | ▶ | croak 'plan id required' unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 131 | 0 | return $self->call_operation('billing.plans.deactivate', path => { id => $id }, body => ''); | |||||||||||
| 132 | } | ||||||||||||
| 133 | |||||||||||||
| 134 | |||||||||||||
| 135 | 3 | 1; | |||||||||||
| 136 | |||||||||||||
| 137 | __END__ | ||||||||||||