PayPal/API/Orders.pm

filter: Statementstmt 36.7% 18 / 49 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 5 / 10 Podpod 100% 4 / 4 totaltotal 26.7% 27 / 101 CC 17 SCAR 43.2
CC
17
Cov
22%
create
156.0
capture
12.0
authorize
12.0
CRAP 75.5
« PayPal/API/Subscriptions.pm ↑ Summary PayPal/API/Products.pm »
1 package WWW::PayPal::API::Orders;
2  
3 # ABSTRACT: PayPal Checkout / Orders v2 API
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::Order;
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.001';
11  
12  
13 2 has client => (
14 is => 'ro',
15 required => 1,
16 weak_ref => 1,
17 );
18  
19  
20 has openapi_operations => (
21 is => 'lazy',
22 builder => sub {
23 # Pre-computed from paypal-rest-api-specifications
24 # (openapi/checkout_orders_v2.json). Regenerate manually when the
25 # spec changes.
26 return {
27 1 ▶ 'orders.create' => { method => 'POST', path => '/v2/checkout/orders' },
Subroutine _build_openapi_operations: called CC=1 SCAR=0.0
28 'orders.get' => { method => 'GET', path => '/v2/checkout/orders/{id}' },
29 'orders.patch' => { method => 'PATCH', path => '/v2/checkout/orders/{id}' },
30 'orders.confirm' => { method => 'POST', path => '/v2/checkout/orders/{id}/confirm-payment-source' },
31 'orders.authorize' => { method => 'POST', path => '/v2/checkout/orders/{id}/authorize' },
32 'orders.capture' => { method => 'POST', path => '/v2/checkout/orders/{id}/capture' },
33 };
34 },
35 2 );
36  
37  
38 2 with 'WWW::PayPal::Role::OpenAPI';
39  
40 sub _wrap {
41 0 ▶ my ($self, $data) = @_;
Subroutine _wrap: not called CC=1 SCAR=6.9
42 0 return WWW::PayPal::Order->new(client => $self->client, data => $data);
43 }
44  
45 sub create {
46 0 ▶ my ($self, %args) = @_;
Subroutine create: not called CC=12 SCAR=50.5
Pod documented
47  
48 0 ▶ croak 'intent required' unless $args{intent};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"intent"} 0 0 0
49 croak 'purchase_units required'
50 0 ▶ unless ref $args{purchase_units} eq 'ARRAY' && @{$args{purchase_units}};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"purchase_units"} eq "ARRAY" and @{$args{"purchase_units"};} 0 0 0
Condition0%0/3
ref $args{"purchase_units"} eq "ARRAY" and @{$args{"purchase_units"};}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $args{"purchase_units"} eq "ARRAY" and @{$args{"purchase_units"};}
ref $args{"purchase_units"} eq "ARRAY" @{$args{"purchase_units"};}
Truth table0%0/3
A and B
A= ref $args{"purchase_units"} eq "ARRAY"B= @{$args{"purchase_units"};}
ABresult
0X0
100
111
51  
52 my $body = {
53 intent => $args{intent},
54 purchase_units => $args{purchase_units},
55 0 };
56  
57 # Application context: return/cancel URLs and branding
58 0 my %ctx;
59 0 ▶ $ctx{return_url} = $args{return_url} if $args{return_url};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"return_url"} 0 0 0
60 0 ▶ $ctx{cancel_url} = $args{cancel_url} if $args{cancel_url};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"cancel_url"} 0 0 0
61 0 ▶ $ctx{brand_name} = $args{brand_name} if $args{brand_name};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"brand_name"} 0 0 0
62 0 ▶ $ctx{locale} = $args{locale} if $args{locale};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"locale"} 0 0 0
63 0 ▶ $ctx{user_action} = $args{user_action} // 'PAY_NOW';
Condition0%0/2
$args{"user_action"} // "PAY_NOW"
l!l
00
MC/DC0%0/1
$args{"user_action"} // "PAY_NOW"
$args{"user_action"}
Truth table0%0/2
A
A= $args{"user_action"}
Aresult
11
00
64 $ctx{shipping_preference} = $args{shipping_preference}
65 0 ▶ if $args{shipping_preference};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"shipping_preference"} 0 0 0
66 0 ▶ if (%ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (%ctx) 0 0 0
67 # PayPal supports both payment_source.paypal.experience_context (new)
68 # and application_context (legacy). We use application_context for
69 # broad compatibility.
70 0 $body->{application_context} = \%ctx;
71 }
72  
73 0 ▶ $body->{payer} = $args{payer} if $args{payer};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"payer"} 0 0 0
74  
75 0 my $data = $self->call_operation('orders.create', body => $body);
76 0 return $self->_wrap($data);
77 }
78  
79  
80 sub get {
81 0 ▶ my ($self, $id) = @_;
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
82 0 ▶ croak 'order id required' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
83 0 my $data = $self->call_operation('orders.get', path => { id => $id });
84 0 return $self->_wrap($data);
85 }
86  
87  
88 sub capture {
89 0 ▶ my ($self, $id, %args) = @_;
Subroutine capture: not called CC=3 SCAR=24.8
Pod documented
90 0 ▶ croak 'order id required' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
91  
92 my $data = $self->call_operation('orders.capture',
93 path => { id => $id },
94 body => $args{body} || {},
95 0 ▶ );
Condition0%0/2
$args{'body'} || {}
l!l
00
MC/DC0%0/1
$args{'body'} || {}
$args{'body'}
Truth table0%0/2
A
A= $args{'body'}
Aresult
11
00
96 0 return $self->_wrap($data);
97 }
98  
99  
100 sub authorize {
101 0 ▶ my ($self, $id, %args) = @_;
Subroutine authorize: not called CC=3 SCAR=24.8
Pod documented
102 0 ▶ croak 'order id required' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
103 my $data = $self->call_operation('orders.authorize',
104 path => { id => $id },
105 body => $args{body} || {},
106 0 ▶ );
Condition0%0/2
$args{'body'} || {}
l!l
00
MC/DC0%0/1
$args{'body'} || {}
$args{'body'}
Truth table0%0/2
A
A= $args{'body'}
Aresult
11
00
107 0 return $self->_wrap($data);
108 }
109  
110  
111 2 1;
112  
113 __END__
« PayPal/API/Subscriptions.pm ↑ Summary PayPal/API/Products.pm »