PayPal.pm

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