Business-CPI-Gateway-Moip
view release on metacpan or search on metacpan
lib/Business/CPI/Gateway/Moip.pm view on Meta::CPAN
}
return $xml;
}
sub add_boleto {
my ( $self, $xml, $cart ) = @_;
if (
defined $cart->boleto
) {
$xml .= "\n<Boleto>";
if ( exists $cart->boleto->{ data_vencimento } ) {
$xml .= "\n<DataVencimento>".$cart->boleto->{ data_vencimento }."</DataVencimento>";
}
if ( exists $cart->boleto->{ instrucao1 } ) {
$xml .= "\n<Instrucao1>".$cart->boleto->{ instrucao1 }."</Instrucao1>";
}
if ( exists $cart->boleto->{ instrucao2 } ) {
$xml .= "\n<Instrucao2>".$cart->boleto->{ instrucao2 }."</Instrucao2>";
}
if ( exists $cart->boleto->{ instrucao3 } ) {
$xml .= "\n<Instrucao3>".$cart->boleto->{ instrucao3 }."</Instrucao3>";
}
if ( exists $cart->boleto->{ logo_url } ) {
$xml .= "\n<URLLogo>".$cart->boleto->{ logo_url }."</URLLogo>";
}
if ( exists $cart->boleto->{ expiracao } ) {
my $tipo='';
if ( exists $cart->boleto->{ expiracao }->{ tipo } ) {
$tipo = ' Tipo="Corridos"' if $cart->boleto->{ expiracao }->{ tipo } =~ m/corridos/gi;
$tipo = ' Tipo="Uteis"' if $cart->boleto->{ expiracao }->{ tipo } =~ m/uteis/gi;
}
$xml .= "\n<DiasExpiracao$tipo>".$cart->boleto->{ expiracao }->{ dias }."</DiasExpiracao>";
}
$xml .= "\n</Boleto>";
}
return $xml;
}
=head2 query_transactions()
TODO: http://labs.moip.com.br/blog/saiba-quais-foram-suas-ultimas-transacoes-no-moip-sem-sair-do-seu-site-com-o-moipstatus/
TODO: https://github.com/moiplabs/moip-php/blob/master/lib/MoipStatus.php
*** Não foi implementado pois o moip possúi api boa para transações mas não tem implementado meios para analisar transações entre perÃodo.
O único jeito é fazer login no site via lwp ou similar e pegar as informações direto do markup.. mas ao menos neste momento não há seletores que indicam quais os dados.
=head2 query_transactions example
*** NOT IMPLEMENTED... but this is what it would would like more or less.
Thats how it can be done today... making login and parsing the welcome html screen (no good).
Not good because they dont have it on their api... and its not good to rely on markup to read
this sort of important values.
moipstatus.php, on their github acc: https://github.com/moiplabs/moip-php/blob/master/lib/MoipStatus.php
use HTTP::Tiny;
use MIME::Base64;
use Data::Printer;
use HTTP::Request::Common qw(POST);
use Mojo::DOM;
my $url_login = "https://www.moip.com.br/j_acegi_security_check";
my $login = 'XXXXXXXXXXX';
my $pass = "XXXXXXX";
my $url_transactions = 'https://www.moip.com.br/rest/reports/last-transactions';
my $form_login = [
j_password => $pass,
j_username => $login,
];
my $res = HTTP::Tiny->new( verify_SSL => 0 )->request(
'POST',
$url_login,
{
headers => {
'Authorization' => 'Basic ' . MIME::Base64::encode($login.":".$pass,''),
'Content-Type' => 'application/x-www-form-urlencoded',
},
content => POST( $url_login, [], Content => $form_login )->content,
}
);
warn p $res;
warn "login fail" and die if $res->{ headers }->{ location } =~ m/fail/ig;
my $res2 = HTTP::Tiny->new( verify_SSL => 0 )->request(
'GET',
$res->{headers}->{location}
);
# warn p $res2;
my $dom = Mojo::DOM->new($res2->{content});
SALDO_STATS: {
my $saldo = $dom->at('div.textoCinza11 b.textoAzul11:nth-child(3)');
my $a_receber = $dom->at('div.textoCinza11 b.textoAzul11:nth-child(10)');
my $stats = {
saldo => (defined $saldo) ? $saldo->text : undef,
saldo_a_receber => (defined $a_receber) ? $a_receber->text : undef,
};
warn p $stats;
}
LAST_TRANSACTIONS:{
my $selector = 'div.conteudo>div:eq(1)>div:eq(1)>div:eq(1)>div:eq(0) div.box table[cellpadding=5]>tbody tr';
my $nenhuma = $dom->at( $selector );
warn p $nenhuma;
}
=cut
sub query_transactions {}
=head2 get_transaction_details()
TODO: http://labs.moip.com.br/referencia/consulta-de-instrucao/
=cut
( run in 0.436 second using v1.01-cache-2.11-cpan-de7293f3b23 )