pretienda

This commit is contained in:
mynah
2019-04-04 19:45:51 -06:00
parent 49b1256e27
commit 567e991278
10 changed files with 256 additions and 11 deletions

View File

@@ -27,7 +27,8 @@ use Dojo::Model::Users;
$r->any('/contact')->to('home#contact');
$r->any('/contact2')->to('home#contact2');
$r->any('/pang')->to('home#pang');
# $r->any('/tst')->to('home#tst');
$r->any('/storep')->to('home#storep');
$r->any('/storep/:id' => [id => qr/\d+/])->to('home#storep');
# =============================================================================

View File

@@ -43,9 +43,9 @@ sub tst{
# interesan create time, id, payer: email address, shippng address
}
else{
my %f=('descripcion',' Había una vez un lobito bueno al que maltrataban todos los corderos','precio','33','promo','si!','existencia','3','nombre','Super master evil man','titulo'=>'venganzas del medievo');
$c->stash(%f);
$c->stash(res=> "no");
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'});
@@ -85,7 +85,9 @@ sub cal {
sub event{
my $c = shift;
$c->stash($c->dbv->event($c->param("id")));
my $data=$c->dbv->event($c->param('id'));
$c->redirect_to('cal') unless ($data->{'cname'});
$c->stash($data);
$c->stash(layout=> "defaultContact");
}
@@ -118,6 +120,50 @@ sub store{
$c->stash(layout=> "defaultContact");
}
sub storep{
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('cal') if ($c->param('id')==4);
$c->redirect_to('store') unless ($data->{'id'});
$c->stash($data);
$c->stash(layout=>'default');
}
}
sub tv{
my $c = shift;
$c->stash( videos=>$c->dbv->tv_videos, table=>$c->dbv->tv_series);

View File

@@ -0,0 +1,14 @@
select
id,
objeto,
nombre,
precio,
subnombre,
promocion,
opcion,
descripcion,
imagenb as "imagen",
existencia,
entrega_id "entrega_id"
from tienda where id=? and activo =1;

View File

@@ -62,6 +62,11 @@ sub store{
return _read ($data_path->child("/store/qStore.q")->slurp);
}
sub store_id{
my ($self,$id)=@_;
return _read ($data_path->child("/store/qIdStore.q")->slurp,$id)->[0];
}
sub _read{
my ($q,@bind)=@_;
my (@empty,$arr);