lib/PagSeguro/API/Checkout.pm

filter: Statementstmt 63.8% 30 / 47 Branchbran 28.5% 8 / 28 Conditioncond 20.0% 2 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 4 totaltotal 45.7% 48 / 105 CC 19 SCAR 26.7
CC
19
Cov
47%
send
33.2
payment_url
20.0
code
6.0
CRAP 14.5
« blib/lib/PagSeguro/API/Notification.pm ↑ Summary blib/lib/PagSeguro/API.pm »
1 package PagSeguro::API::Checkout;
2 6 ▶use base 'PagSeguro::API::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # constructor
9 sub new {
10 3 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.7
Pod undocumented
11 3 ▶ my $args = (@_ % 2 == 0)? {@_} : shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 0 ? : 3 0 3
12  
13 return bless {
14 _code => undef,
15 3 ▶ _context => ($args->{context})? $args->{context} : $args,
Branch: 1 branch
BranchTrueFalseTotal
$args->{'context'} ? : 3 0 3
16 _transaction => undef,
17 }, $class;
18 }
19  
20 # accessors
21 sub _context {
22 4 ▶ return $_[0]->{_context} if $_[0]->{_context};
Subroutine _context: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_context"} 4 0 4
23 }
24 sub code {
25 0 ▶ return $_[0]->{_code} if $_[0]->{_code};
Subroutine code: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_code"} 0 0 0
26 }
27  
28 # methods
29 sub send {
30 1 ▶ my $self = shift;
Subroutine send: called CC=8 SCAR=35.0
Pod undocumented
31 1 ▶ my $args = (@_ % 2 == 0) ? {@_} : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 0 ? : 1 0 1
32  
33 1 $self->{_code} = undef;
34  
35 1 ▶ if ($args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args) { } 1 0 1
36  
37 # parse and return by file
38 1 ▶ return XMLin( $args->{file} ) if $args->{file};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"file"} 1 0 1
39  
40 0 $args->{email} = $self->_context->email;
41 0 $args->{token} = $self->_context->token;
42 0 ▶ $args->{currency} = $args->{currency} || 'BRL';
Condition0%0/2
$args->{'currency'} || 'BRL'
l!l
00
MC/DC0%0/1
$args->{'currency'} || 'BRL'
$args->{'currency'}
Truth table0%0/2
A
A= $args->{'currency'}
Aresult
11
00
43 0 ▶ $args->{shippingType} = $args->{shippingType} || '3';
Condition0%0/2
$args->{'shippingType'} || '3'
l!l
00
MC/DC0%0/1
$args->{'shippingType'} || '3'
$args->{'shippingType'}
Truth table0%0/2
A
A= $args->{'shippingType'}
Aresult
11
00
44  
45 # getting response
46 0 my $uri = $self->_checkout_uri( $args );
47 0 my $response = $self->post( $uri, $args );
48  
49 # debug
50 warn "[Debug] Checkout Response: $response\n"
51 0 ▶ if $ENV{PAGSEGURO_API_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PAGSEGURO_API_DEBUG"} 0 0 0
52  
53 0 my $xml = XMLin($response);
54  
55 0 ▶ $self->{_code} = $xml->{code} if $xml->{code};
Branch: 1 branch
BranchTrueFalseTotal
if $xml->{"code"} 0 0 0
56 0 return $xml;
57 }
58 else {
59 # error
60 0 croak "Error: invalid paramether bound";
61 }
62 }
63  
64 sub payment_url {
65 0 ▶ my ($self, $code) = @_;
Subroutine payment_url: not called CC=4 SCAR=30.0
Pod undocumented
66  
67 0 ▶ $code = $self->code unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
68
69 my $uri = join '',
70 (
71 $self->_context->resource($ENV{PAGSEGURO_API_SANDBOX}
72 0 ▶ ? 'SANDBOX_CHECKOUT_PAYMENT'
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PAGSEGURO_API_SANDBOX'} ? : 0 0 0
73 : 'CHECKOUT_PAYMENT'),
74 "?code=", $code
75 );
76  
77 0 ▶ warn "[Debug] URI: $uri\n" if $ENV{PAGSEGURO_API_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PAGSEGURO_API_DEBUG"} 0 0 0
78 0 return $uri;
79 }
80  
81 sub _checkout_uri {
82 1 ▶ my ( $self, $args ) = @_;
Subroutine _checkout_uri: called CC=5 SCAR=17.8
83  
84 # add email and token
85 1 ▶ $args->{email} = $args->{email} || $self->_context->email;
Condition33%1/3
$args->{'email'} || $self->_context->email
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'email'} || $self->_context->email
$args->{'email'} $self->_context->email
Truth table33%1/3
A || B
A= $args->{'email'}B= $self->_context->email
ABresult
1X1
011
000
86 1 ▶ $args->{token} = $args->{token} || $self->_context->token;
Condition33%1/3
$args->{'token'} || $self->_context->token
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'token'} || $self->_context->token
$args->{'token'} $self->_context->token
Truth table33%1/3
A || B
A= $args->{'token'}B= $self->_context->token
ABresult
1X1
011
000
87  
88 # build query string
89 1 my $query_string = join '&', map { "$_=$args->{$_}" } keys %$args;
90  
91 my $uri = join '',
92 (
93 $self->_context->resource(
94 1 ▶ ( $ENV{PAGSEGURO_API_SANDBOX} ? 'SANDBOX_URI' : 'BASE_URI' )
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PAGSEGURO_API_SANDBOX'} ? : 0 1 1
95 ),
96 $self->_context->resource('CHECKOUT'),
97 "?",
98 $query_string
99 );
100  
101 1 ▶ warn "[Debug] URI: $uri\n" if $ENV{PAGSEGURO_API_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PAGSEGURO_API_DEBUG"} 0 1 1
102 1 return $uri;
103 }
104  
105 6 1;
« blib/lib/PagSeguro/API/Notification.pm ↑ Summary blib/lib/PagSeguro/API.pm »