API/Transaction.pm

filter: Statementstmt 27.2% 15 / 55 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 2 totaltotal 24.0% 19 / 79 CC 8 SCAR 30.4
CC
8
Cov
22%
by_code
42.0
_parse_transaction
12.0
by_notification_code
2.0
CRAP 21.0
↑ Summary API/Payment.pm »
1 package PagSeguro::API::Transaction;
2 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 extends 'PagSeguro::API::Base';
5  
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use PagSeguro::API::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use PagSeguro::API::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # attributes
11 3 has code => (is => 'rw');
12  
13 0 ▶sub by_code {
Subroutine by_code: not called CC=6 SCAR=37.4
Pod undocumented
14 0 my ($self, $code) = (shift, shift);
15 0 ▶ my $args = (@_ % 2 == 0)? {@_} : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 0 ? : 0 0 0
16  
17 0 ▶ croak "error: code cannot be null!" unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
18  
19 0 my $email = $self->email;
20 0 my $token = $self->token;
21  
22 0 my $req = PagSeguro::API::Request->new;
23 0 my $uri = $self->api_uri . "/transactions/${code}?email=${email}&token=${token}";
24
25 # is notification
26 $uri = $self->api_uri . "/transactions/notifications/${code}?email=${email}&token=${token}"
27 0 ▶ if $args->{notification};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"notification"} 0 0 0
28  
29 # api response
30 0 my $res = $req->get(url => $uri);
31  
32 0 ▶ if($res && !$res->error){
Branch: 1 branch
BranchTrueFalseTotal
if ($res and not $res->error) 0 0 0
Condition0%0/3
$res and not $res->error
!ll&&!rl&&r
000
MC/DC0%0/2
$res and not $res->error
$res not $res->error
Truth table0%0/3
A and not(B)
A= $resB= not $res->error
ABresult
0X0
100
111
33 0 my $result = $self->_parse_transaction($res->data);
34 0 $res->data($result);
35 }
36
37 0 return $res;
38 }
39  
40 0 ▶sub by_notification_code {
Subroutine by_notification_code: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my ($self, $code) = (shift, shift);
42 0 return $self->by_code($code, notification => 1);
43 }
44  
45 0 ▶sub _parse_transaction {
Subroutine _parse_transaction: not called CC=3 SCAR=24.8
46 0 my $self = shift;
47
48 # read xml
49 0 ▶ my $xml = $self->xml($_[0]) if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
50
51 my $data = {
52 0 date => eval { $xml->find('/transaction/date')->string_value },
53 0 code => eval { $xml->find('/transaction/code')->string_value },
54 0 type => eval { $xml->find('/transaction/type')->string_value },
55 0 status => eval { $xml->find('/transaction/status')->string_value },
56 0 reference => eval { $xml->find('/transaction/reference')->string_value },
57 0 lastEventDate => eval { $xml->find('/transaction/lastEventDate')->string_value },
58 0 grossAmount => eval { $xml->find('/transaction/grossAmount')->string_value },
59 paymentMethod => {
60 0 type => eval { $xml->find('/transaction/paymentMethod/type')->string_value },
61 0 code => eval { $xml->find('/transaction/paymentMethod/code')->string_value },
62 },
63 sender => {
64 0 name => eval { $xml->find('/transaction/sender/name')->string_value },
65 0 email => eval { $xml->find('/transaction/sender/email')->string_value },
66 phone => {
67 0 areaCode => eval { $xml->find('/transaction/sender/phone/areaCode')->string_value },
68 0 number => eval { $xml->find('/transaction/sender/phone/number')->string_value },
69 }
70 },
71 items => []
72 };
73  
74 0 for my $i ($xml->findnodes('//items/item')){
75 my $item = {
76 0 id => eval { $i->find('./id')->string_value },
77 0 description => eval { $i->find('./description')->string_value },
78 0 quantity => eval { $i->find('./quantity')->string_value },
79 0 amount => eval { $i->find('./amount')->string_value },
80 };
81  
82 0 push @{$data->{items}}, $item;
83 }
84  
85 0 return $data;
86 }
87  
88 3 1;
89 __END__
↑ Summary API/Payment.pm »