PayPal/Order.pm

filter: Statementstmt 80.3% 49 / 61 Branchbran 56.2% 9 / 16 Conditioncond 47.3% 9 / 19 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 78.9% 15 / 19 Podpod 100% 14 / 14 totaltotal 69.2% 97 / 140 CC 18 SCAR 10.1
CC
18
Cov
70%
_capture_node
4.3
link_for
4.1
payer_name
3.3
CRAP 2.7
« PayPal/API/Webhooks.pm ↑ Summary PayPal/Capture.pm »
1 package WWW::PayPal::Order;
2  
3 # ABSTRACT: PayPal Orders v2 order entity
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 namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.003';
10  
11  
12 3 has _client => (
13 is => 'ro',
14 required => 1,
15 weak_ref => 1,
16 init_arg => 'client',
17 );
18  
19 3 has data => (
20 is => 'rw',
21 required => 1,
22 );
23  
24  
25 2 ▶sub id { $_[0]->data->{id} }
Subroutine id: called CC=1 SCAR=0.0
Pod documented
26 1 ▶sub status { $_[0]->data->{status} }
Subroutine status: called CC=1 SCAR=0.0
Pod documented
27 0 ▶sub intent { $_[0]->data->{intent} }
Subroutine intent: not called CC=1 SCAR=6.9
Pod documented
28  
29  
30 1 ▶sub _links {
Subroutine _links: called CC=2 SCAR=7.2
31 1 my ($self) = @_;
32 1 ▶ return $self->data->{links} || [];
Condition50%1/2
$self->data->{'links'} || []
l!l
10
MC/DC0%0/1
$self->data->{'links'} || []
$self->data->{'links'}
Truth table50%1/2
A
A= $self->data->{'links'}
Aresult
11
00
33 }
34  
35 1 ▶sub link_for {
Subroutine link_for: called CC=4 SCAR=14.2
Pod documented
36 1 my ($self, $rel) = @_;
37 1 for my $l (@{ $self->_links }) {
38 2 ▶ return $l->{href} if $l->{rel} && $l->{rel} eq $rel;
Branch: 1 branch
BranchTrueFalseTotal
if $l->{"rel"} and $l->{"rel"} eq $rel 1 1 2
Condition66%2/3
$l->{"rel"} and $l->{"rel"} eq $rel
!ll&&!rl&&r
011
MC/DC50%1/2
$l->{"rel"} and $l->{"rel"} eq $rel
$l->{"rel"} $l->{"rel"} eq $rel
Truth table66%2/3
A and B
A= $l->{"rel"}B= $l->{"rel"} eq $rel
ABresult
0X0
100
111
39 }
40 0 return;
41 }
42  
43  
44 1 ▶sub approve_url {
Subroutine approve_url: called CC=2 SCAR=8.1
Pod documented
45 1 my ($self) = @_;
46 # Modern flows return 'payer-action'; legacy returned 'approve'.
47 1 ▶ return $self->link_for('payer-action') // $self->link_for('approve');
Condition33%1/3
$self->link_for("payer-action") // $self->link_for("approve")
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->link_for("payer-action") // $self->link_for("approve")
$self->link_for("payer-action") $self->link_for("approve")
Truth table33%1/3
A // B
A= $self->link_for("payer-action")B= $self->link_for("approve")
ABresult
1X1
011
000
48 }
49  
50  
51 2 ▶sub _capture_node {
Subroutine _capture_node: called CC=4 SCAR=14.6
52 2 my ($self) = @_;
53 2 ▶ my $pu = $self->data->{purchase_units} || [];
Condition50%1/2
$self->data->{'purchase_units'} || []
l!l
20
MC/DC0%0/1
$self->data->{'purchase_units'} || []
$self->data->{'purchase_units'}
Truth table50%1/2
A
A= $self->data->{'purchase_units'}
Aresult
11
00
54 2 ▶ return unless @$pu;
Branch: 1 branch
BranchTrueFalseTotal
unless @$pu 0 2 2
55 2 ▶ my $captures = $pu->[0]{payments}{captures} || [];
Condition50%1/2
$pu->[0]{'payments'}{'captures'} || []
l!l
20
MC/DC0%0/1
$pu->[0]{'payments'}{'captures'} || []
$pu->[0]{'payments'}{'captures'}
Truth table50%1/2
A
A= $pu->[0]{'payments'}{'captures'}
Aresult
11
00
56 2 return $captures->[0];
57 }
58  
59 1 ▶sub capture_id {
Subroutine capture_id: called CC=2 SCAR=7.1
Pod documented
60 1 my ($self) = @_;
61 1 ▶ my $c = $self->_capture_node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $c = $self->_capture_node or return 1 0 1
62 1 return $c->{id};
63 }
64  
65  
66 1 ▶sub fee_in_cent {
Subroutine fee_in_cent: called CC=3 SCAR=11.4
Pod documented
67 1 my ($self) = @_;
68 1 ▶ my $c = $self->_capture_node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $c = $self->_capture_node or return 1 0 1
69 1 ▶ my $fee = $c->{seller_receivable_breakdown}{paypal_fee}{value} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fee = $c->{"seller_receivable_breakdown"}{"paypal_fee"}{"value"} or return 1 0 1
70 # PayPal returns decimal strings like "1.23"
71 1 return int($fee * 100 + 0.5);
72 }
73  
74  
75 1 ▶sub total {
Subroutine total: called CC=3 SCAR=11.4
Pod documented
76 1 my ($self) = @_;
77 1 ▶ my $pu = $self->data->{purchase_units} || [];
Condition50%1/2
$self->data->{'purchase_units'} || []
l!l
10
MC/DC0%0/1
$self->data->{'purchase_units'} || []
$self->data->{'purchase_units'}
Truth table50%1/2
A
A= $self->data->{'purchase_units'}
Aresult
11
00
78 1 ▶ return unless @$pu;
Branch: 1 branch
BranchTrueFalseTotal
unless @$pu 0 1 1
79 1 return $pu->[0]{amount}{value};
80 }
81  
82 1 ▶sub currency {
Subroutine currency: called CC=3 SCAR=11.4
Pod documented
83 1 my ($self) = @_;
84 1 ▶ my $pu = $self->data->{purchase_units} || [];
Condition50%1/2
$self->data->{'purchase_units'} || []
l!l
10
MC/DC0%0/1
$self->data->{'purchase_units'} || []
$self->data->{'purchase_units'}
Truth table50%1/2
A
A= $self->data->{'purchase_units'}
Aresult
11
00
85 1 ▶ return unless @$pu;
Branch: 1 branch
BranchTrueFalseTotal
unless @$pu 0 1 1
86 1 return $pu->[0]{amount}{currency_code};
87 }
88  
89  
90 1 ▶sub payer_email {
Subroutine payer_email: called CC=1 SCAR=0.0
Pod documented
91 1 my ($self) = @_;
92 1 return $self->data->{payer}{email_address};
93 }
94  
95 1 ▶sub payer_name {
Subroutine payer_name: called CC=3 SCAR=12.0
Pod documented
96 1 my ($self) = @_;
97 1 ▶ my $n = $self->data->{payer}{name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $n = $self->data->{"payer"}{"name"} or return 1 0 1
98 1 ▶ return join(' ', grep { defined && length } $n->{given_name}, $n->{surname});
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
99 }
100  
101 0 ▶sub payer_id {
Subroutine payer_id: not called CC=1 SCAR=6.9
Pod documented
102 0 my ($self) = @_;
103 0 return $self->data->{payer}{payer_id};
104 }
105  
106  
107 0 ▶sub refresh {
Subroutine refresh: not called CC=1 SCAR=6.9
Pod documented
108 0 my ($self) = @_;
109 0 my $fresh = $self->_client->orders->get($self->id);
110 0 $self->data($fresh->data);
111 0 return $self;
112 }
113  
114  
115 0 ▶sub capture {
Subroutine capture: not called CC=1 SCAR=6.9
Pod documented
116 0 my ($self) = @_;
117 0 my $captured = $self->_client->orders->capture($self->id);
118 0 $self->data($captured->data);
119 0 return $self;
120 }
121  
122  
123 3 1;
124  
125 __END__
« PayPal/API/Webhooks.pm ↑ Summary PayPal/Capture.pm »