PayPal.pm

filter: Statementstmt 92.5% 75 / 81 Branchbran 53.1% 17 / 32 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 78.2% 18 / 23 Podpod 100% 2 / 2 totaltotal 78.5% 117 / 149 CC 21 SCAR 19.8
CC
21
Cov
80%
js_sdk_url
18.3
__ANON__
6.0
__ANON__
3.2
CRAP 7.3
« PayPal/Role/OpenAPI.pm ↑ Summary PayPal/Order.pm »
1 package WWW::PayPal;
2  
3 # ABSTRACT: Perl client for the PayPal REST 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::API::Orders;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use WWW::PayPal::API::Payments;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use WWW::PayPal::API::Products;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use WWW::PayPal::API::Plans;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use WWW::PayPal::API::Subscriptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our $VERSION = '0.002';
15  
16  
17 has client_id => (
18 is => 'ro',
19 0 ▶ default => sub { $ENV{PAYPAL_CLIENT_ID} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 2 );
21  
22  
23 has secret => (
24 is => 'ro',
25 0 ▶ default => sub { $ENV{PAYPAL_SECRET} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 2 );
27  
28  
29 has sandbox => (
30 is => 'ro',
31 0 ▶ default => sub { $ENV{PAYPAL_SANDBOX} ? 1 : 0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PAYPAL_SANDBOX'} ? : 0 0 0
32 2 );
33  
34  
35 has base_url => (
36 is => 'lazy',
37 builder => sub {
38 0 ▶ $_[0]->sandbox
Subroutine __ANON__: not called CC=2 SCAR=11.6
Subroutine _build_base_url: called CC=2 SCAR=11.6
Branch: 2 branches
BranchTrueFalseTotal
$_[0]->sandbox ? : 0 0 0
$_[0]->sandbox ? : 1 0 1
39 ? 'https://api-m.sandbox.paypal.com'
40 : 'https://api-m.paypal.com';
41 },
42 2 );
43  
44  
45 2 with 'WWW::PayPal::Role::HTTP';
46  
47 has orders => (
48 is => 'lazy',
49 1 ▶ builder => sub { WWW::PayPal::API::Orders->new(client => $_[0]) },
Subroutine _build_orders: called CC=1 SCAR=0.0
50 2 );
51  
52  
53 has payments => (
54 is => 'lazy',
55 0 ▶ builder => sub { WWW::PayPal::API::Payments->new(client => $_[0]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 2 );
57  
58  
59 has products => (
60 is => 'lazy',
61 1 ▶ builder => sub { WWW::PayPal::API::Products->new(client => $_[0]) },
Subroutine _build_products: called CC=1 SCAR=0.0
62 2 );
63  
64  
65 has plans => (
66 is => 'lazy',
67 1 ▶ builder => sub { WWW::PayPal::API::Plans->new(client => $_[0]) },
Subroutine _build_plans: called CC=1 SCAR=0.0
68 2 );
69  
70  
71 has subscriptions => (
72 is => 'lazy',
73 1 ▶ builder => sub { WWW::PayPal::API::Subscriptions->new(client => $_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
74 2 );
75  
76  
77 sub js_sdk_url {
78 4 ▶ my ($self, %args) = @_;
Subroutine js_sdk_url: called CC=15 SCAR=29.1
Pod documented
79 4 ▶ croak 'client_id required' unless $self->client_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->client_id 0 4 4
80  
81 my %p = (
82 'client-id' => $self->client_id,
83 4 ▶ intent => lc($args{intent} // 'capture'),
Condition100%2/2
$args{"intent"} // "capture"
l!l
22
MC/DC100%1/1
$args{"intent"} // "capture"
$args{"intent"}
Truth table100%2/2
A
A= $args{"intent"}
Aresult
11
00
84 );
85 4 ▶ $p{currency} = uc $args{currency} if $args{currency};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"currency"} 3 1 4
86 4 ▶ $p{locale} = $args{locale} if $args{locale};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"locale"} 0 4 4
87 4 ▶ $p{'disable-funding'} = _join_list($args{disable_funding}) if $args{disable_funding};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"disable_funding"} 1 3 4
88 4 ▶ $p{'enable-funding'} = _join_list($args{enable_funding}) if $args{enable_funding};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"enable_funding"} 0 4 4
89 4 ▶ $p{components} = _join_list($args{components} // ['buttons']);
Condition50%1/2
$args{"components"} // ["buttons"]
l!l
04
MC/DC0%0/1
$args{"components"} // ["buttons"]
$args{"components"}
Truth table50%1/2
A
A= $args{"components"}
Aresult
11
00
90 4 ▶ $p{vault} = 'true' if $args{vault};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"vault"} 1 3 4
91 4 ▶ $p{'merchant-id'} = $args{merchant_id} if $args{merchant_id};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"merchant_id"} 0 4 4
92 4 ▶ $p{'buyer-country'} = $args{buyer_country} if $args{buyer_country} && $self->sandbox;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"buyer_country"} and $self->sandbox 0 4 4
Condition33%1/3
$args{"buyer_country"} and $self->sandbox
!ll&&!rl&&r
400
MC/DC0%0/2
$args{"buyer_country"} and $self->sandbox
$args{"buyer_country"} $self->sandbox
Truth table33%1/3
A and B
A= $args{"buyer_country"}B= $self->sandbox
ABresult
0X0
100
111
93 4 ▶ $p{debug} = 'true' if $args{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"debug"} 0 4 4
94  
95 # Extra opaque params (e.g. data-partner-attribution-id is an HTML attr,
96 # not a URL param, so we don't mix those in).
97 4 ▶ if (my $extra = $args{params}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $extra = $args{"params"}) 0 4 4
98 0 $p{$_} = $extra->{$_} for keys %$extra;
99 }
100  
101 my $qs = join('&',
102 17 map { _uri_escape($_) . '=' . _uri_escape($p{$_}) }
103 4 sort grep { defined $p{$_} } keys %p
104 );
105 4 return 'https://www.paypal.com/sdk/js?' . $qs;
106 }
107  
108  
109 sub js_sdk_script_tag {
110 1 ▶ my ($self, %args) = @_;
Subroutine js_sdk_script_tag: called CC=1 SCAR=0.0
Pod documented
111 1 my $url = $self->js_sdk_url(%args);
112 1 return '<script src="' . _html_escape($url) . '"></script>';
113 }
114  
115 sub _join_list {
116 5 ▶ my ($v) = @_;
Subroutine _join_list: called CC=2 SCAR=7.2
117 5 ▶ return ref $v eq 'ARRAY' ? join(',', @$v) : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 5 0 5
118 }
119  
120 sub _uri_escape {
121 34 ▶ my ($s) = @_;
Subroutine _uri_escape: called CC=2 SCAR=7.0
122 34 ▶ $s = '' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 34 34
123 34 $s =~ s/([^A-Za-z0-9\-._~])/sprintf('%%%02X', ord($1))/ge;
124 34 return $s;
125 }
126  
127 sub _html_escape {
128 1 ▶ my ($s) = @_;
Subroutine _html_escape: called CC=2 SCAR=7.0
129 1 ▶ $s = '' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 1 1
130 1 $s =~ s/&/&amp;/g;
131 1 $s =~ s/</&lt;/g;
132 1 $s =~ s/>/&gt;/g;
133 1 $s =~ s/"/&quot;/g;
134 1 return $s;
135 }
136  
137  
138 2 1;
139  
140 __END__
« PayPal/Role/OpenAPI.pm ↑ Summary PayPal/Order.pm »