PayPal/Order.pm

filter: Statementstmt 80.3% 49 / 61 Branchbran 55.5% 10 / 18 Conditioncond 50.0% 8 / 16 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 78.9% 15 / 19 Podpod 100% 14 / 14 totaltotal 70.8% 97 / 137 CC 18 SCAR 10.0
CC
18
Cov
71%
_capture_node
4.3
link_for
4.1
fee_in_cent
3.1
CRAP 2.7
« PayPal.pm ↑ Summary PayPal/Capture.pm »
1 package WWW::PayPal::Order;
2  
3 # ABSTRACT: PayPal Orders v2 order entity
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 namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.002';
10  
11  
12 2 has _client => (
13 is => 'ro',
14 required => 1,
15 weak_ref => 1,
16 init_arg => 'client',
17 );
18  
19 2 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 sub _links {
31 1 ▶ my ($self) = @_;
Subroutine _links: called CC=2 SCAR=7.2
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 sub link_for {
36 1 ▶ my ($self, $rel) = @_;
Subroutine link_for: called CC=4 SCAR=14.2
Pod documented
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 sub approve_url {
45 1 ▶ my ($self) = @_;
Subroutine approve_url: called CC=2 SCAR=8.1
Pod documented
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 sub _capture_node {
52 2 ▶ my ($self) = @_;
Subroutine _capture_node: called CC=4 SCAR=14.6
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 sub capture_id {
60 1 ▶ my ($self) = @_;
Subroutine capture_id: called CC=2 SCAR=7.1
Pod documented
61 1 ▶ my $c = $self->_capture_node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $c = $self->_capture_node or return 0 1 1
62 1 return $c->{id};
63 }
64  
65  
66 sub fee_in_cent {
67 1 ▶ my ($self) = @_;
Subroutine fee_in_cent: called CC=3 SCAR=11.4
Pod documented
68 1 ▶ my $c = $self->_capture_node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $c = $self->_capture_node or return 0 1 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 0 1 1
70 # PayPal returns decimal strings like "1.23"
71 1 return int($fee * 100 + 0.5);
72 }
73  
74  
75 sub total {
76 1 ▶ my ($self) = @_;
Subroutine total: called CC=3 SCAR=11.4
Pod documented
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 sub currency {
83 1 ▶ my ($self) = @_;
Subroutine currency: called CC=3 SCAR=11.4
Pod documented
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 sub payer_email {
91 1 ▶ my ($self) = @_;
Subroutine payer_email: called CC=1 SCAR=0.0
Pod documented
92 1 return $self->data->{payer}{email_address};
93 }
94  
95 sub payer_name {
96 1 ▶ my ($self) = @_;
Subroutine payer_name: called CC=3 SCAR=11.4
Pod documented
97 1 ▶ my $n = $self->data->{payer}{name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $n = $self->data->{"payer"}{"name"} or return 0 1 1
98 1 ▶ return join(' ', grep { defined && length } $n->{given_name}, $n->{surname});
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ 2 0 2
99 }
100  
101 sub payer_id {
102 0 ▶ my ($self) = @_;
Subroutine payer_id: not called CC=1 SCAR=6.9
Pod documented
103 0 return $self->data->{payer}{payer_id};
104 }
105  
106  
107 sub refresh {
108 0 ▶ my ($self) = @_;
Subroutine refresh: not called CC=1 SCAR=6.9
Pod documented
109 0 my $fresh = $self->_client->orders->get($self->id);
110 0 $self->data($fresh->data);
111 0 return $self;
112 }
113  
114  
115 sub capture {
116 0 ▶ my ($self) = @_;
Subroutine capture: not called CC=1 SCAR=6.9
Pod documented
117 0 my $captured = $self->_client->orders->capture($self->id);
118 0 $self->data($captured->data);
119 0 return $self;
120 }
121  
122  
123 2 1;
124  
125 __END__
« PayPal.pm ↑ Summary PayPal/Capture.pm »