paypaltst

This commit is contained in:
mynah
2019-03-28 04:06:59 -06:00
parent 63ffc6c7d4
commit 2848f7ca42
11 changed files with 260 additions and 14 deletions

View File

@@ -1,11 +1,48 @@
package Dojo::Controller::Home;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Template;
#use Dojo::Support qw{ log dmph merge_hash load_module get_names};
use Dojo::Support qw{ log get_names};
# estos son paypal=======:w
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;
use Data::Dumper;
#=========================
sub tst{
my $c=shift;
$c->render(text=> $c->config->{radio}{'channel'});
#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/2';
#=================
#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);
#==============
my $ub = LWP::UserAgent->new;
$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
my $resb=$ub->get($porder);
log("paypal checkout error!") unless ($resb->is_success );
my $jsonb = JSON->new->utf8;
my $s=$jsonb->decode($resb->decoded_content);
$c->stash(res=>" $r->{expires_in} $s->{name}");
$c->stash(layout=>'default');
#$c->render(text=> $c->config->{radio}{'channel'});
}
# User ========================================================================
@@ -185,6 +222,14 @@ sub bcast{
$c->stash(template=>"home/admin/event");
$c->stash(layout=>"admin");
}
sub admin_tienda{
my $c=shift;
$c->stash(u=>$c->dbv->user_heads);
$c->stash(s=>$c->dbv->store_heads);
$c->stash(template=>"home/admin/tienda");
$c->stash(layout=>"admin");
}
sub admin_json{
my $c=shift;
@@ -192,6 +237,8 @@ sub bcast{
my $req = $c->param('dreq');
my $json = "304";
$json = $c->dbv->msg($id) if $req=~/mensaje/;
$json = $c->dbv->user($id) if $req=~/usuarios/;
$json = $c->dbv->astore($id) if $req=~/tienda/;
$json = $c->dbv->course($id) if $req=~/course/;
$json = $c->dbv->place($id) if $req=~/place/;
$json = $c->dbv->eventa($id) if $req=~/event/;

View File

@@ -0,0 +1,4 @@
select
a.id,a.nombre,a.existencia,a.imagen,a.precio,a.activo,a.descripcion,date(a.vigencia) as vigencia,b.nombre as entrega
from tienda as a inner join entrega as b where a.entrega_id=b.id
and a.id=?;

View File

@@ -0,0 +1,4 @@
select
correo,telefono as tel, observacion as obs,date(ultima) as ultima
from usuario where id=?;

View File

@@ -0,0 +1,3 @@
select
id,nombre,existencia,precio,activo
from tienda order by id;

View File

@@ -0,0 +1,4 @@
select
id,usuario,nombre
from usuario order by usuario;

View File

@@ -1,6 +1,6 @@
package Dojo::Model::Vuelo; use Mojo::File 'path';
use Mojo::JSON qw(decode_json encode_json);
use Dojo::Support qw{ log dmph merge_hash load_module get_names};
use Dojo::Support qw{ log dmph} ;
use Mojo::Base 'Mojolicious::Controller';
@@ -83,6 +83,22 @@ sub podcast_infoHash{
$dbh->disconnect();
return shift @$h;
}
sub user_heads{
return _readgrulla($data_path->child("admin/tienda/qUsers.q")->slurp);
}
sub store_heads{
return _readgrulla($data_path->child("admin/tienda/qStore.q")->slurp);
}
sub user {
return shift @{_readgrulla($data_path->child("admin/tienda/json/qUsers.q")->slurp,pop)}}
sub astore {
return shift @{_readgrulla($data_path->child("/admin/tienda/json/qStore.q")->slurp,pop)}}
sub courses{ return _read("select nombre as name, id from curso;")}
sub course { return shift @{_read($data_path->child("/admin/event/json/qCourse.q")->slurp,pop)}}
sub places { return _read("select nombre as name, id from lugar;")}
@@ -94,9 +110,8 @@ sub podcast_infoHash{
sub eimgList{
my $dp = path('public/home/cal/img')->make_path;
return [ map{ $_->basename} grep{/(jpg|png)$/i}@{$dp->list} ];
}
#==============================================================================
# Write vdg user ==============================================================
sub contact{
@@ -104,7 +119,7 @@ sub contact{
my $q="insert into entrada (nombre,correo,pagina,texto,fecha) values(?,?,?,?,now() )" ;
my @a=@_;
#simple method to ignore spam
return _writemsg($q,@a) unless $a[3]=~m/http|website|\<a/;
return _writemsg($q,@a) unless $a[3]=~m/http|website|\<a|feedback|forms|suscribe|advertise|newsletter|promotion|Madam/;
return 0;
}
#==============================================================================
@@ -189,6 +204,27 @@ sub _writemsg{
log("db write: $h");
return $h;
}
sub _readgrulla{
my ($q,@bind)=@_;
my @empty;
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::GRULLADB.":".Dojo::Conf::GRULLADB_H,Dojo::Conf::GRULLADB_UR,Dojo::Conf::GRULLADB_URP, {mysql_enable_utf8 => 1});
return \@empty unless($dbh);
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind)//"error";
$dbh->disconnect();
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
return $h;
}
sub _writegrulla{
my ($q,@bind)=@_;
my (@empty);
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::GRULLADB.":".Dojo::Conf::GRULLADB_H,Dojo::Conf::GRULLADB_UW,Dojo::Conf::GRULLADB_UWP,{mysql_enable_utf8 => 1} );
return 0 unless($dbh);
my $h=$dbh->do($q,{ Slice => {} },@bind)//"error";
$dbh->disconnect();
log("db write: $h");
return $h;
}
sub load_md{
return "" unless