line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Moip; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
78590
|
use IO::Socket::SSL; |
|
4
|
|
|
|
|
346854
|
|
|
4
|
|
|
|
|
34
|
|
4
|
4
|
|
|
4
|
|
3456
|
use MIME::Base64; |
|
4
|
|
|
|
|
3058
|
|
|
4
|
|
|
|
|
269
|
|
5
|
4
|
|
|
4
|
|
2104
|
use Furl; |
|
4
|
|
|
|
|
93935
|
|
|
4
|
|
|
|
|
149
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
2438
|
use String::CamelCase (); |
|
4
|
|
|
|
|
2329
|
|
|
4
|
|
|
|
|
110
|
|
8
|
4
|
|
|
4
|
|
2840
|
use XML::SAX::Writer; |
|
4
|
|
|
|
|
150067
|
|
|
4
|
|
|
|
|
144
|
|
9
|
4
|
|
|
4
|
|
3207
|
use XML::Generator::PerlData; |
|
4
|
|
|
|
|
42450
|
|
|
4
|
|
|
|
|
147
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
2847
|
use Moo; |
|
4
|
|
|
|
|
51870
|
|
|
4
|
|
|
|
|
29
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.02; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'ua', is => 'ro', default => sub { |
16
|
|
|
|
|
|
|
Furl->new( |
17
|
|
|
|
|
|
|
agent => "Net-Moip/$VERSION", |
18
|
|
|
|
|
|
|
timeout => 5, |
19
|
|
|
|
|
|
|
max_redirects => 3, |
20
|
|
|
|
|
|
|
ssl_opts => { SSL_verify_mode => SSL_VERIFY_PEER() } |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'token', is => 'ro', required => 1; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'key', is => 'ro', required => 1; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has 'api_url', ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
writer => '_set_api_url', |
31
|
|
|
|
|
|
|
default => 'https://www.moip.com.br/ws/alpha/EnviarInstrucao/Unica' |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'sandbox', ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
default => 0, |
37
|
|
|
|
|
|
|
trigger => sub { |
38
|
|
|
|
|
|
|
my ($self, $sandbox) = @_; |
39
|
|
|
|
|
|
|
$self->_set_api_url( $sandbox |
40
|
|
|
|
|
|
|
? 'https://desenvolvedor.moip.com.br/sandbox/ws/alpha/EnviarInstrucao/Unica' |
41
|
|
|
|
|
|
|
: 'https://www.moip.com.br/ws/alpha/EnviarInstrucao/Unica' |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub pagamento_unico { |
47
|
4
|
|
|
4
|
0
|
6023
|
my ($self, $args) = @_; |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
18
|
my $xml = $self->_gen_xml( $args ); |
50
|
4
|
|
|
|
|
96
|
my $auth = 'Basic ' . MIME::Base64::encode( $self->token . ':' . $self->key, ''); |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
47
|
my $res = $self->ua->post( |
53
|
|
|
|
|
|
|
$self->api_url, |
54
|
|
|
|
|
|
|
[ 'Authorization' => $auth ], |
55
|
|
|
|
|
|
|
$xml |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
1857
|
my %data = ( response => $res ); |
59
|
4
|
100
|
|
|
|
19
|
if ($res->is_success) { |
60
|
3
|
|
|
|
|
25
|
my $c = $res->content; |
61
|
3
|
50
|
|
|
|
43
|
$data{id} = $1 if $c =~ m{(.+?)}; |
62
|
3
|
50
|
|
|
|
26
|
$data{status} = $1 if $c =~ m{(.+?)}; |
63
|
3
|
100
|
|
|
|
16
|
$data{token} = $1 if $c =~ m{(.+?)}; |
64
|
|
|
|
|
|
|
|
65
|
3
|
|
|
|
|
24
|
while ($c =~ m{(.+?)}gs) { |
66
|
3
|
|
|
|
|
5
|
push @{$data{erros}}, { codigo => $1, mensagem => $2 }; |
|
3
|
|
|
|
|
25
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
4
|
|
|
|
|
20
|
return \%data; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _gen_xml { |
74
|
4
|
|
|
4
|
|
9
|
my ($self, $args) = @_; |
75
|
4
|
|
|
|
|
7
|
my $xml; |
76
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
48
|
my $generator = XML::Generator::PerlData->new( |
78
|
|
|
|
|
|
|
Handler => XML::SAX::Writer->new(Output => \$xml), |
79
|
|
|
|
|
|
|
rootname => 'EnviarInstrucao', |
80
|
|
|
|
|
|
|
keymap => { |
81
|
|
|
|
|
|
|
'*' => \&String::CamelCase::camelize, |
82
|
|
|
|
|
|
|
'url_notificacao' => 'URLNotificacao', |
83
|
|
|
|
|
|
|
'url_logo' => 'URLLogo', |
84
|
|
|
|
|
|
|
'url_retorno' => 'URLRetorno', |
85
|
|
|
|
|
|
|
}, |
86
|
|
|
|
|
|
|
attrmap => { InstrucaoUnica => ['TipoValidacao'] }, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
4
|
|
|
4
|
|
9467
|
no autovivification; |
|
4
|
|
|
|
|
3601
|
|
|
4
|
|
|
|
|
32
|
|
90
|
|
|
|
|
|
|
|
91
|
4
|
|
|
|
|
1636
|
$args->{valores}{valor} = delete $args->{valor}; |
92
|
|
|
|
|
|
|
|
93
|
4
|
50
|
|
|
|
25
|
if (my $acrescimo = delete $args->{acrescimo}) { |
94
|
0
|
|
|
|
|
0
|
$args->{valores}{acrescimo} = $acrescimo; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
4
|
50
|
|
|
|
19
|
if (my $deducao = delete $args->{deducao}) { |
98
|
0
|
|
|
|
|
0
|
$args->{valores}{deducao} = $deducao; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
4
|
100
|
|
|
|
36
|
if (my $cep = delete $args->{pagador}{endereco_cobranca}{cep}) { |
102
|
1
|
|
|
|
|
4
|
$args->{pagador}{endereco_cobranca}{CEP} = $cep; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
4
|
|
|
|
|
19
|
my $xml_args = { instrucao_unica => $args }; |
106
|
|
|
|
|
|
|
|
107
|
4
|
|
|
|
|
24
|
$generator->parse( $xml_args ); |
108
|
|
|
|
|
|
|
|
109
|
4
|
|
|
|
|
8852
|
return $xml; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
__END__ |