132 lines
3.6 KiB
Perl
Executable File
132 lines
3.6 KiB
Perl
Executable File
package Dojo::Controller::Home;
|
|
use Mojo::Base 'Mojolicious::Controller';
|
|
use Mojo::Template;
|
|
use Dojo::Support qw{send_mail log get_names};
|
|
use JSON;
|
|
use Data::Dumper;
|
|
#=========================
|
|
sub tst{
|
|
my $c=shift;
|
|
if( defined($c->req->json) ){
|
|
my $oid = $c->req->json->{'orderID'} //0;
|
|
log( $oid );
|
|
#credentials====
|
|
my $client='AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7';
|
|
my $secter='EBn8CNOCrJbVZ_fNllXB7oUIm9_vhtqrJMm2zSBGbxSyiiych3cHOIWOLAD5NVw4Z3dmNhmsHQwPsrZ0';
|
|
my $pauth='https://api.sandbox.paypal.com/v1/oauth2/token/';
|
|
my $porder='https://api.sandbox.paypal.com/v2/checkout/orders/';
|
|
#=================
|
|
#pre auth ====
|
|
my $ua = LWP::UserAgent->new;
|
|
my $req=POST $pauth, ["grant_type"=>"client_credentials"];
|
|
$req->authorization_basic($client,$secter);
|
|
$req->content_type('application/x-www-form-urlencoded');
|
|
my $res=$ua->request($req);
|
|
log("paypal pre auth error! $res->status_line") unless ($res->is_success );
|
|
my $json = JSON->new->utf8;
|
|
my $r=$json->decode($res->decoded_content);
|
|
#==============
|
|
|
|
#order details ====
|
|
my $ub = LWP::UserAgent->new;
|
|
$ub->default_header('Content-Type'=> 'application/json' );
|
|
$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
|
|
my $resb=$ub->get($porder.$oid);
|
|
log("paypal checkout error!") unless ($resb->is_success );
|
|
my $jsonb = JSON->new->utf8;
|
|
my $s=$jsonb->decode($resb->decoded_content);
|
|
#===================
|
|
$c->rendered(200); #es default,nomas para enfatizar que puede ser 400 o 500
|
|
# interesan create time, id, payer: email address, shippng address
|
|
}
|
|
else{
|
|
my $data=$c->dbg->store_id($c->param('id'));
|
|
$c->redirect_to('store') unless ($data->{'id'});
|
|
$c->stash($data);
|
|
$c->stash(layout=>'default');
|
|
}
|
|
#$c->render(text=> $c->config->{radio}{'channel'});
|
|
|
|
}
|
|
# User ========================================================================
|
|
sub home_ {
|
|
my $c = shift;
|
|
$c->redirect_to("/home") ;
|
|
}
|
|
|
|
sub home {
|
|
my $c = shift;
|
|
# por hacer: par evitar la animacion del intro
|
|
# $c->stash(moda=>$c->req->headers->referrer );
|
|
$c->stash( $c->dbv->mod) ;
|
|
$c->stash(layout=>'default');
|
|
}
|
|
|
|
sub pang {
|
|
my $c = shift;
|
|
my $h=$c->dbv->pang_md;
|
|
map { $c->stash( $_ => $h->{$_}) } keys %$h;
|
|
$c->stash(layout=>'default');
|
|
}
|
|
|
|
sub contact{
|
|
my $c = shift;
|
|
if ($c->param("mup")){
|
|
$c->flash(mname => $c->param("mname"));
|
|
$c->dbv->contact(
|
|
$c->param("mname"),
|
|
$c->param("mail"),
|
|
$c->match->stack->[-1]{action},
|
|
$c->param("msg")
|
|
);
|
|
$c->redirect_to('contact2');
|
|
}else{
|
|
$c->stash(layout=>'default');
|
|
}
|
|
}
|
|
|
|
sub contact2{
|
|
my $c = shift;
|
|
$c->redirect_to("home") unless $c->flash('mname');
|
|
$c->stash( mname=>$c->flash('mname'));
|
|
$c->stash(layout=>'default');
|
|
}
|
|
|
|
sub tv{
|
|
my $c = shift;
|
|
$c->stash( videos=>$c->dbv->tv_videos, table=>$c->dbv->tv_series);
|
|
$c->stash(layout=> "defaultContact");
|
|
}
|
|
|
|
sub podcast{
|
|
my $c = shift;
|
|
$c->stash(layout=> "defaultContact");
|
|
$c->stash( t=>$c->dbv->podcast_txt, pod=>$c->dbv->podcast_infoHash);
|
|
}
|
|
|
|
sub bcast{
|
|
my $c = shift;
|
|
$c->stash(layout=> "defaultContact");
|
|
}
|
|
|
|
sub radio{
|
|
my $c=shift;
|
|
$c->stash(layout=> "defaultContact");
|
|
$c->stash($c->dbv->mod);
|
|
$c->stash(nick=>$c->session("nick"));
|
|
}
|
|
|
|
sub candy{
|
|
my $c=shift;
|
|
$c->stash( css=>["/ext/candy/libs.min.css","/home/candy/default.css"]);
|
|
$c->stash( js=>["/home/candy/loader.js","/ext/candy/libs.min.js","/ext/candy/candy.min.js"]);
|
|
|
|
$c->stash(layout=> "clean");
|
|
$c->stash(nick=>$c->session("nick"));
|
|
}
|
|
|
|
#==============================================================================
|
|
|
|
|
|
1;
|