line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PagSeguro::API::Payment; |
2
|
3
|
|
|
3
|
|
13
|
use Moo; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
14
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
extends 'PagSeguro::API::Base'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
1663
|
use PagSeguro::API::Util; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
169
|
|
7
|
3
|
|
|
3
|
|
1059
|
use PagSeguro::API::Request; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
95
|
|
8
|
3
|
|
|
3
|
|
1376
|
use PagSeguro::API::Payment::Sender; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2249
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# attributes |
11
|
|
|
|
|
|
|
has reference => (is => 'rw'); |
12
|
|
|
|
|
|
|
has redirect_url => (is => 'rw'); |
13
|
|
|
|
|
|
|
has notification_url => (is => 'rw'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# sender |
16
|
|
|
|
|
|
|
has sender => (is => 'rw', default => sub{ PagSeguro::API::Payment::Sender->new }); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# item list |
19
|
|
|
|
|
|
|
has items => (is => 'rw', default => sub { [] }); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# methods |
23
|
|
|
|
|
|
|
sub item { |
24
|
0
|
|
|
0
|
|
|
my ($self, $id) = @_; |
25
|
0
|
0
|
|
|
|
|
do{ return $_ if $_->{id} eq $id } |
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
for @{$self->items}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub add_item { |
30
|
0
|
|
|
0
|
|
|
my $self = shift; |
31
|
0
|
0
|
|
|
|
|
my $args = (@_ % 2 == 0)? {@_} : undef; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# required |
34
|
0
|
0
|
|
|
|
|
$args->{quantity} = 1 unless $args->{quantity}; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
push @{$self->items}, $args; |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub request { |
40
|
0
|
|
|
0
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# build http post params |
43
|
0
|
|
|
|
|
|
my $params = $self->_build_params; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $req = PagSeguro::API::Request->new; |
46
|
0
|
|
|
|
|
|
my $res = $req->post( |
47
|
|
|
|
|
|
|
url => $self->api_uri . '/checkout/', |
48
|
|
|
|
|
|
|
params => $params |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# parse response |
52
|
0
|
0
|
0
|
|
|
|
if($res && !$res->error){ |
53
|
0
|
|
|
|
|
|
my $data = $res->data; |
54
|
0
|
|
|
|
|
|
my $result = $self->_parse_request($data); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$res->data($result); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $res; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub request_form { |
63
|
0
|
|
|
0
|
|
|
my $self = shift; |
64
|
0
|
0
|
|
|
|
|
my $args = (@_ % 2 == 0)? {@_} : undef; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# default button |
67
|
0
|
|
0
|
|
|
|
my $btn_name = delete $args->{text} || 'Checkout'; |
68
|
0
|
0
|
|
|
|
|
$args->{type} = 'submit' unless $args->{type}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# build http post params |
72
|
0
|
|
|
|
|
|
my $params = $self->_build_params; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# remove sensitive data |
75
|
0
|
|
|
|
|
|
delete $params->{token}; |
76
|
0
|
|
|
|
|
|
delete $params->{email}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $base_uri = $self->base_uri; |
80
|
0
|
|
|
|
|
|
my $html = qq{ |
81
|
|
|
|
|
|
|
$html .= qq{ \n} |
82
|
0
|
|
|
|
|
|
for keys %$params; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $btn_params = join ' ', map { "$_=\"$args->{$_}\"" } keys %$args; |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$html .= qq{\n}; |
86
|
0
|
|
|
|
|
|
$html .= qq{}; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return $html; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _build_params { |
92
|
0
|
|
|
0
|
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# prapare parameters |
95
|
0
|
|
|
|
|
|
my $params = {}; |
96
|
0
|
|
|
|
|
|
$params->{email} = $self->email; |
97
|
0
|
|
|
|
|
|
$params->{token} = $self->token; |
98
|
0
|
|
|
|
|
|
$params->{receiverEmail} = $self->email; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# payment information |
101
|
0
|
|
|
|
|
|
$params->{reference} = $self->reference; |
102
|
0
|
|
|
|
|
|
$params->{currency} = 'BRL'; |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
$params->{redirectURL} = $self->redirect_url |
105
|
|
|
|
|
|
|
if $self->redirect_url; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
$params->{notificationURL} = $self->notification_url |
108
|
|
|
|
|
|
|
if $self->notification_url; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# sender information |
111
|
0
|
0
|
|
|
|
|
if($self->sender){ |
112
|
0
|
|
|
|
|
|
my $s = $self->sender; |
113
|
0
|
0
|
|
|
|
|
$params->{senderName} = $s->name if $s->name; |
114
|
0
|
0
|
|
|
|
|
$params->{senderEmail} = $s->email if $s->email; |
115
|
0
|
0
|
|
|
|
|
$params->{senderPhone} = $s->phone if $s->phone; |
116
|
0
|
0
|
|
|
|
|
$params->{senderAreaCode} = $s->area_code if $s->area_code; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# items information |
120
|
0
|
|
|
|
|
|
my $c = 1; |
121
|
0
|
|
|
|
|
|
for my $i (@{$self->items}){ |
|
0
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
map { my $k=camelize($_).$c;$params->{"item$k"}=$i->{$_} } keys %$i; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$c++; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return $params; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _parse_request { |
130
|
0
|
|
|
0
|
|
|
my $self = shift; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# read xml |
133
|
0
|
0
|
|
|
|
|
my $xml = $self->xml($_[0]) if $_[0]; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# getting /checkout/code |
136
|
0
|
|
|
|
|
|
my $code = $xml->find('/checkout/code')->string_value; |
137
|
0
|
|
|
|
|
|
my $date = $xml->find('/checkout/date')->string_value; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return { |
140
|
0
|
|
|
|
|
|
code => $code, |
141
|
|
|
|
|
|
|
date => $date, |
142
|
|
|
|
|
|
|
payment_url => $self->base_uri . "/v2/checkout/payment.html?code=$code" |
143
|
|
|
|
|
|
|
}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
__END__ |