| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Moip; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
69937
|
use IO::Socket::SSL; |
|
|
4
|
|
|
|
|
285505
|
|
|
|
4
|
|
|
|
|
29
|
|
|
4
|
4
|
|
|
4
|
|
2549
|
use MIME::Base64; |
|
|
4
|
|
|
|
|
2401
|
|
|
|
4
|
|
|
|
|
208
|
|
|
5
|
4
|
|
|
4
|
|
1706
|
use Furl; |
|
|
4
|
|
|
|
|
76858
|
|
|
|
4
|
|
|
|
|
127
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
2068
|
use String::CamelCase (); |
|
|
4
|
|
|
|
|
2265
|
|
|
|
4
|
|
|
|
|
88
|
|
|
8
|
4
|
|
|
4
|
|
2431
|
use XML::SAX::Writer; |
|
|
4
|
|
|
|
|
147905
|
|
|
|
4
|
|
|
|
|
135
|
|
|
9
|
4
|
|
|
4
|
|
3019
|
use XML::Generator::PerlData; |
|
|
4
|
|
|
|
|
17674
|
|
|
|
4
|
|
|
|
|
113
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
8221
|
use Moo; |
|
|
4
|
|
|
|
|
52143
|
|
|
|
4
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.03; |
|
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
|
|
|
|
|
|
|
has 'decode_as', is => 'rw', default => undef; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub pagamento_unico { |
|
49
|
4
|
|
|
4
|
0
|
5095
|
my ($self, $args) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
17
|
my $xml = $self->_gen_xml( $args ); |
|
52
|
4
|
|
|
|
|
68
|
my $auth = 'Basic ' . MIME::Base64::encode( $self->token . ':' . $self->key, ''); |
|
53
|
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
35
|
my $res = $self->ua->post( |
|
55
|
|
|
|
|
|
|
$self->api_url, |
|
56
|
|
|
|
|
|
|
[ 'Authorization' => $auth ], |
|
57
|
|
|
|
|
|
|
$xml |
|
58
|
|
|
|
|
|
|
); |
|
59
|
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
1933
|
my %data = ( response => $res ); |
|
61
|
4
|
100
|
|
|
|
15
|
if ($res->is_success) { |
|
62
|
3
|
|
|
|
|
20
|
my $c = $res->content; |
|
63
|
3
|
50
|
|
|
|
35
|
$data{id} = $1 if $c =~ m{(.+?)}; |
|
64
|
3
|
50
|
|
|
|
20
|
$data{status} = $1 if $c =~ m{(.+?)}; |
|
65
|
3
|
100
|
|
|
|
13
|
$data{token} = $1 if $c =~ m{(.+?)}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
21
|
while ($c =~ m{(.+?)}gs) { |
|
68
|
3
|
|
|
|
|
3
|
push @{$data{erros}}, { codigo => $1, mensagem => $2 }; |
|
|
3
|
|
|
|
|
20
|
|
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
18
|
return \%data; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _gen_xml { |
|
76
|
4
|
|
|
4
|
|
8
|
my ($self, $args) = @_; |
|
77
|
4
|
|
|
|
|
6
|
my $xml; |
|
78
|
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
76
|
my $generator = XML::Generator::PerlData->new( |
|
80
|
|
|
|
|
|
|
Handler => XML::SAX::Writer->new( |
|
81
|
|
|
|
|
|
|
Output => \$xml, |
|
82
|
|
|
|
|
|
|
EncodeFrom => $self->decode_as, |
|
83
|
|
|
|
|
|
|
EncodeTo => 'iso-8859-1' |
|
84
|
|
|
|
|
|
|
), |
|
85
|
|
|
|
|
|
|
rootname => 'EnviarInstrucao', |
|
86
|
|
|
|
|
|
|
keymap => { |
|
87
|
|
|
|
|
|
|
'*' => \&String::CamelCase::camelize, |
|
88
|
|
|
|
|
|
|
'url_notificacao' => 'URLNotificacao', |
|
89
|
|
|
|
|
|
|
'url_logo' => 'URLLogo', |
|
90
|
|
|
|
|
|
|
'url_retorno' => 'URLRetorno', |
|
91
|
|
|
|
|
|
|
}, |
|
92
|
|
|
|
|
|
|
attrmap => { InstrucaoUnica => ['TipoValidacao'] }, |
|
93
|
|
|
|
|
|
|
); |
|
94
|
|
|
|
|
|
|
|
|
95
|
4
|
|
|
4
|
|
8763
|
no autovivification; |
|
|
4
|
|
|
|
|
3305
|
|
|
|
4
|
|
|
|
|
27
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
1194
|
$args->{valores}{valor} = delete $args->{valor}; |
|
98
|
|
|
|
|
|
|
|
|
99
|
4
|
50
|
|
|
|
19
|
if (my $acrescimo = delete $args->{acrescimo}) { |
|
100
|
0
|
|
|
|
|
0
|
$args->{valores}{acrescimo} = $acrescimo; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
4
|
50
|
|
|
|
15
|
if (my $deducao = delete $args->{deducao}) { |
|
104
|
0
|
|
|
|
|
0
|
$args->{valores}{deducao} = $deducao; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
4
|
100
|
|
|
|
30
|
if (my $cep = delete $args->{pagador}{endereco_cobranca}{cep}) { |
|
108
|
1
|
|
|
|
|
4
|
$args->{pagador}{endereco_cobranca}{CEP} = $cep; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
4
|
|
|
|
|
14
|
my $xml_args = { instrucao_unica => $args }; |
|
112
|
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
18
|
$generator->parse( $xml_args ); |
|
114
|
|
|
|
|
|
|
|
|
115
|
4
|
|
|
|
|
9343
|
return $xml; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
|
119
|
|
|
|
|
|
|
__END__ |