| 1 | package WWW::PayPal::API::Subscriptions; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | # ABSTRACT: PayPal Billing Subscriptions 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::Subscription; | ||||||||||||||||||||
|
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 | 1 | ▶ | builder => sub { | ||||||||||||||||||||
|
Subroutine
_build_openapi_operations: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||
| 22 | return { | ||||||||||||||||||||||
| 23 | 0 | 'billing.subscriptions.create' => { method => 'POST', path => '/v1/billing/subscriptions' }, | |||||||||||||||||||||
| 24 | 'billing.subscriptions.get' => { method => 'GET', path => '/v1/billing/subscriptions/{id}' }, | ||||||||||||||||||||||
| 25 | 'billing.subscriptions.patch' => { method => 'PATCH', path => '/v1/billing/subscriptions/{id}' }, | ||||||||||||||||||||||
| 26 | 'billing.subscriptions.revise' => { method => 'POST', path => '/v1/billing/subscriptions/{id}/revise' }, | ||||||||||||||||||||||
| 27 | 'billing.subscriptions.suspend' => { method => 'POST', path => '/v1/billing/subscriptions/{id}/suspend' }, | ||||||||||||||||||||||
| 28 | 'billing.subscriptions.activate' => { method => 'POST', path => '/v1/billing/subscriptions/{id}/activate' }, | ||||||||||||||||||||||
| 29 | 'billing.subscriptions.cancel' => { method => 'POST', path => '/v1/billing/subscriptions/{id}/cancel' }, | ||||||||||||||||||||||
| 30 | 'billing.subscriptions.capture' => { method => 'POST', path => '/v1/billing/subscriptions/{id}/capture' }, | ||||||||||||||||||||||
| 31 | 'billing.subscriptions.transactions' => { method => 'GET', path => '/v1/billing/subscriptions/{id}/transactions' }, | ||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||
| 34 | 3 | ); | |||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | 3 | with 'WWW::PayPal::Role::OpenAPI'; | |||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | 0 | ▶ | sub _wrap { | ||||||||||||||||||||
|
Subroutine
_wrap: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 39 | 0 | my ($self, $data) = @_; | |||||||||||||||||||||
| 40 | 0 | return WWW::PayPal::Subscription->new(client => $self->client, data => $data); | |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | 0 | ▶ | sub create { | ||||||||||||||||||||
|
Subroutine
create: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||
| 44 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||
| 45 | 0 | ▶ | croak 'plan_id required' unless $args{plan_id}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | 0 | my %body = ( plan_id => $args{plan_id} ); | |||||||||||||||||||||
| 48 | 0 | ▶ | $body{subscriber} = $args{subscriber} if $args{subscriber}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 49 | 0 | ▶ | $body{quantity} = $args{quantity} if defined $args{quantity}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 50 | 0 | ▶ | $body{custom_id} = $args{custom_id} if defined $args{custom_id}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 51 | 0 | ▶ | $body{start_time} = $args{start_time} if defined $args{start_time}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 52 | 0 | ▶ | $body{shipping_amount} = $args{shipping_amount} if $args{shipping_amount}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | 0 | my %ctx; | |||||||||||||||||||||
| 55 | 0 | ▶ | $ctx{return_url} = $args{return_url} if $args{return_url}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 56 | 0 | ▶ | $ctx{cancel_url} = $args{cancel_url} if $args{cancel_url}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 57 | 0 | ▶ | $ctx{brand_name} = $args{brand_name} if $args{brand_name}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 58 | 0 | ▶ | $ctx{locale} = $args{locale} if $args{locale}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | 0 | ▶ | $ctx{user_action} = $args{user_action} // 'SUBSCRIBE_NOW'; | ||||||||||||||||||||
|
Condition0%0/2
$args{"user_action"} // "SUBSCRIBE_NOW"
MC/DC0%0/1
$args{"user_action"} // "SUBSCRIBE_NOW"
$args{"user_action"}
Truth table0%0/2
A
A= $args{"user_action"}
| |||||||||||||||||||||||
| 60 | $ctx{shipping_preference} = $args{shipping_preference} | ||||||||||||||||||||||
| 61 | 0 | ▶ | if $args{shipping_preference}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 62 | 0 | ▶ | $body{application_context} = \%ctx if %ctx; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | 0 | my $data = $self->call_operation('billing.subscriptions.create', body => \%body); | |||||||||||||||||||||
| 65 | 0 | return $self->_wrap($data); | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | 0 | ▶ | sub get { | ||||||||||||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 70 | 0 | my ($self, $id) = @_; | |||||||||||||||||||||
| 71 | 0 | ▶ | croak 'subscription id required' unless $id; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 72 | 0 | return $self->_wrap($self->call_operation('billing.subscriptions.get', path => { id => $id })); | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | 0 | ▶ | sub _action_with_reason { | ||||||||||||||||||||
|
Subroutine
_action_with_reason: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||
| 77 | 0 | my ($self, $op, $id, %args) = @_; | |||||||||||||||||||||
| 78 | 0 | ▶ | croak 'subscription id required' unless $id; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 79 | 0 | ▶ | my $reason = $args{reason} // 'not specified'; | ||||||||||||||||||||
|
Condition0%0/2
$args{"reason"} // "not specified"
MC/DC0%0/1
$args{"reason"} // "not specified"
$args{"reason"}
Truth table0%0/2
A
A= $args{"reason"}
| |||||||||||||||||||||||
| 80 | 0 | return $self->call_operation($op, | |||||||||||||||||||||
| 81 | path => { id => $id }, | ||||||||||||||||||||||
| 82 | body => { reason => $reason }, | ||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | 0 | ▶ | sub suspend { my $s = shift; $s->_action_with_reason('billing.subscriptions.suspend', @_) } | ||||||||||||||||||||
|
Subroutine
suspend: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 87 | 0 | ▶ | sub activate { my $s = shift; $s->_action_with_reason('billing.subscriptions.activate', @_) } | ||||||||||||||||||||
|
Subroutine
activate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 88 | 0 | ▶ | sub cancel { my $s = shift; $s->_action_with_reason('billing.subscriptions.cancel', @_) } | ||||||||||||||||||||
|
Subroutine
cancel: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | 0 | ▶ | sub capture { | ||||||||||||||||||||
|
Subroutine
capture: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||
| 92 | 0 | my ($self, $id, %args) = @_; | |||||||||||||||||||||
| 93 | 0 | ▶ | croak 'subscription id required' unless $id; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 94 | 0 | ▶ | croak 'amount required' unless $args{amount}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 95 | my $body = { | ||||||||||||||||||||||
| 96 | note => $args{note} // 'Outstanding balance', | ||||||||||||||||||||||
| 97 | capture_type => $args{capture_type} // 'OUTSTANDING_BALANCE', | ||||||||||||||||||||||
| 98 | amount => $args{amount}, | ||||||||||||||||||||||
| 99 | 0 | ▶ | }; | ||||||||||||||||||||
|
Condition0%0/4
$args{"note"} // "Outstanding balance"
$args{"capture_type"} // "OUTSTANDING_BALANCE"
MC/DC0%0/1
$args{"note"} // "Outstanding balance"
$args{"note"}
MC/DC0%0/1
$args{"capture_type"} // "OUTSTANDING_BALANCE"
$args{"capture_type"}
Truth table0%0/2
A
A= $args{"note"}
Truth table0%0/2
A
A= $args{"capture_type"}
| |||||||||||||||||||||||
| 100 | 0 | return $self->call_operation('billing.subscriptions.capture', | |||||||||||||||||||||
| 101 | path => { id => $id }, | ||||||||||||||||||||||
| 102 | body => $body, | ||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | 0 | ▶ | sub transactions { | ||||||||||||||||||||
|
Subroutine
transactions: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||
| 108 | 0 | my ($self, $id, %args) = @_; | |||||||||||||||||||||
| 109 | 0 | ▶ | croak 'subscription id required' unless $id; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 110 | 0 | ▶ | croak 'start_time required' unless $args{start_time}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 111 | 0 | ▶ | croak 'end_time required' unless $args{end_time}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 112 | return $self->call_operation('billing.subscriptions.transactions', | ||||||||||||||||||||||
| 113 | path => { id => $id }, | ||||||||||||||||||||||
| 114 | query => { | ||||||||||||||||||||||
| 115 | start_time => $args{start_time}, | ||||||||||||||||||||||
| 116 | end_time => $args{end_time}, | ||||||||||||||||||||||
| 117 | }, | ||||||||||||||||||||||
| 118 | 0 | ); | |||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||
| 120 | |||||||||||||||||||||||
| 121 | |||||||||||||||||||||||
| 122 | 3 | 1; | |||||||||||||||||||||
| 123 | |||||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||||