paypaltst
This commit is contained in:
@@ -69,6 +69,7 @@ use Dojo::Model::Users;
|
||||
$admin->any('eventos')->to('home#admin_eventos');
|
||||
$admin->any('eventos/:type'=> [type=>['e','p','c']])->to('home#admin_eventos');
|
||||
$admin->any('mensajes')->to('home#admin_mensajes');
|
||||
$admin->any('tienda')->to('home#admin_tienda');
|
||||
$admin->any('json/:dreq/:id')->to('home#admin_json');
|
||||
|
||||
# =============================================================================
|
||||
|
||||
@@ -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/;
|
||||
|
||||
4
lib/Dojo/Model/Data/admin/tienda/json/qStore.q
Normal file
4
lib/Dojo/Model/Data/admin/tienda/json/qStore.q
Normal 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=?;
|
||||
4
lib/Dojo/Model/Data/admin/tienda/json/qUsers.q
Executable file
4
lib/Dojo/Model/Data/admin/tienda/json/qUsers.q
Executable file
@@ -0,0 +1,4 @@
|
||||
select
|
||||
correo,telefono as tel, observacion as obs,date(ultima) as ultima
|
||||
from usuario where id=?;
|
||||
|
||||
3
lib/Dojo/Model/Data/admin/tienda/qStore.q
Normal file
3
lib/Dojo/Model/Data/admin/tienda/qStore.q
Normal file
@@ -0,0 +1,3 @@
|
||||
select
|
||||
id,nombre,existencia,precio,activo
|
||||
from tienda order by id;
|
||||
4
lib/Dojo/Model/Data/admin/tienda/qUsers.q
Executable file
4
lib/Dojo/Model/Data/admin/tienda/qUsers.q
Executable file
@@ -0,0 +1,4 @@
|
||||
select
|
||||
id,usuario,nombre
|
||||
from usuario order by usuario;
|
||||
|
||||
@@ -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
|
||||
|
||||
29
public/home/admin/tienda/tienda.css
Executable file
29
public/home/admin/tienda/tienda.css
Executable file
@@ -0,0 +1,29 @@
|
||||
section.messages{
|
||||
justify-content:end;
|
||||
}
|
||||
article.select{
|
||||
flex:1;
|
||||
overflow:auto;
|
||||
min-width:200px;
|
||||
max-width:400px;
|
||||
|
||||
}
|
||||
select.entry{
|
||||
margin:10px;
|
||||
min-height:400px;
|
||||
}
|
||||
option.entry{
|
||||
margin:10px;
|
||||
}
|
||||
article.view{
|
||||
flex:1;
|
||||
min-width:200px;
|
||||
max-width:500px;
|
||||
padding-right: 40px;
|
||||
}
|
||||
article.view p{}
|
||||
div.spcr{
|
||||
background-color:gray;
|
||||
height:3px;
|
||||
width:30px;
|
||||
}
|
||||
23
public/home/admin/tienda/tienda.js
Executable file
23
public/home/admin/tienda/tienda.js
Executable file
@@ -0,0 +1,23 @@
|
||||
|
||||
d3.select("select#suser").on("change",function(){
|
||||
var uid=d3.select("select#suser").node().value;
|
||||
d3.json("/admin/json/usuarios/"+uid ,function(d){
|
||||
if(d !=undefined) {if(d != 0){
|
||||
d3.select("p#correo").text(d.correo);
|
||||
d3.select("p#tel").text(d.tel);
|
||||
d3.select("p#obs").text(d.obs);
|
||||
d3.select("p#ultima").text(d.ultima);
|
||||
}}});
|
||||
});
|
||||
|
||||
d3.select("select#sentry").on("change",function(){
|
||||
var tid=d3.select("select#sentry").node().value;
|
||||
d3.json("/admin/json/tienda/"+tid ,function(d){
|
||||
if(d !=undefined) {if(d != 0){
|
||||
d3.select("p#imagen").text(d.imagen);
|
||||
d3.select("p#precio").text(d.precio);
|
||||
d3.select("p#descripcion").text(d.descripcion);
|
||||
d3.select("p#vigencia").text(d.vigencia);
|
||||
d3.select("p#entrega").text(d.entrega);
|
||||
}}});
|
||||
});
|
||||
62
templates/home/admin/tienda.html.ep
Executable file
62
templates/home/admin/tienda.html.ep
Executable file
@@ -0,0 +1,62 @@
|
||||
% stash css=>["/home/admin/admin.css","/home/admin/tienda/tienda.css"];
|
||||
% stash js=>["/home/admin/tienda/tienda.js"];
|
||||
<section class="flex">
|
||||
<article class="select">
|
||||
<select id="suser" class="entry" size=10>
|
||||
<% map{ %>
|
||||
<option value="<%= $_->{'id'} %>" class="entry">
|
||||
<%= $_->{'usuario'}%>, <%= $_->{'nombre'} %>
|
||||
</option>
|
||||
<% } %><% (@{stash('u')}); %>
|
||||
</select>
|
||||
</article>
|
||||
<article class="users">
|
||||
<div class="spcr"></div>
|
||||
<p id="correo">correo</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="tel">tel</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="obs">obs</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="ultima">ultima</p>
|
||||
</article>
|
||||
<article class=store">
|
||||
<div class="spcr"></div>
|
||||
<p id="nombre">nombre</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="correo">correo</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="obs">mensaje</p>
|
||||
</article>
|
||||
</section>
|
||||
<section class="flex byElement">
|
||||
<article class="select">
|
||||
<select id="sentry" class="entry" size=10>
|
||||
<% map{ %>
|
||||
<option value="<%= $_->{'id'} %>"
|
||||
class="entry <% if ($_->{'existencia'} =~/^[0-5]$/ ){ %>warn<% } %>">
|
||||
<%= $_->{'nombre'} %>, $<%= $_->{'precio'} %>
|
||||
</option>
|
||||
<% } %><% (@{stash('s')}); %>
|
||||
</select>
|
||||
</article>
|
||||
<article class="users">
|
||||
<div class="spcr"></div>
|
||||
<p id="imagen">nombre</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="precio">correo</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="descripcion">mensaje</p>
|
||||
<p id="vigencia">mensaje</p>
|
||||
<p id="entrega">mensaje</p>
|
||||
</article>
|
||||
</article>
|
||||
<article class=store">
|
||||
<div class="spcr"></div>
|
||||
<p id="nombre">nombre</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="correo">correo</p>
|
||||
<div class="spcr"></div>
|
||||
<p id="obs">mensaje</p>
|
||||
</article>
|
||||
</section>
|
||||
@@ -1,10 +1,43 @@
|
||||
<p> <%= url_for("$controller/$action/img") %> </p>
|
||||
<!--<head>-->
|
||||
<!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
|
||||
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge" />-->
|
||||
<!--</head>-->
|
||||
<p>
|
||||
<%= url_for("$controller/$action/img") %>
|
||||
%= url_for->path('/meself')
|
||||
</p>
|
||||
<p>
|
||||
%= url_for->path('/meself')
|
||||
<%= $res %>
|
||||
</p>
|
||||
|
||||
<!-- Set up a container element for the button -->
|
||||
<div id="paypal-button-container"></div>
|
||||
|
||||
<!-- Include the PayPal JavaScript SDK -->
|
||||
<script src="https://www.paypal.com/sdk/js?client-id=AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7¤cy=MXN"></script>
|
||||
|
||||
<script>
|
||||
// Render the PayPal button into #paypal-button-container
|
||||
paypal.Buttons({
|
||||
|
||||
// Set up the transaction
|
||||
createOrder: function(data, actions) {
|
||||
return actions.order.create({
|
||||
purchase_units: [{
|
||||
amount: {
|
||||
value: '1.00'
|
||||
}
|
||||
}]
|
||||
});
|
||||
},
|
||||
|
||||
// Finalize the transaction
|
||||
onApprove: function(data, actions) {
|
||||
return actions.order.capture().then(function(details) {
|
||||
// Show a success message to the buyer
|
||||
alert('Transaction completed by ' + details.payer.name.given_name + '!');
|
||||
});
|
||||
}
|
||||
}).render('#paypal-button-container');
|
||||
</script>
|
||||
|
||||
</p>
|
||||
<p>
|
||||
% foreach (@{$ilist}) {
|
||||
<%= $_ %>
|
||||
% }
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user