diff --git a/lib/Dojo.pm b/lib/Dojo.pm index 365032c..6698653 100755 --- a/lib/Dojo.pm +++ b/lib/Dojo.pm @@ -22,11 +22,13 @@ use Dojo::Model::Vdgproc; $r->any('/')->to('home#home_'); $r->any('/home')->to('home#home'); $r->any('/pod')->to('home#podcast'); - $r->any('/store')->to('home#store'); + # $r->any('/store')->to('home#store'); $r->any('/tv')->to('home#tv'); $r->any('/contact')->to('home#contact'); $r->any('/contact2')->to('home#contact2'); $r->any('/pang')->to('home#pang'); +# json ================== + $r->any('/json/*dreq')->to('data#simple'); # ============================================================================= # de la tienda ================================================================ @@ -35,12 +37,7 @@ use Dojo::Model::Vdgproc; $r->any('/spay/:class/:id' => [class => qr/\d+/, id => qr/\d+/])->to('proc#spay'); $r->any('/spay/intentCreate')->to('proc#intentCreate'); $r->any('/spay/intentConfirm')->to('proc#intentConfirm'); -# ============================================================================= - -# por matar =================================================================== - $r->any('/xpay')->to('misc#stripe'); - $r->any('/storep')->to('home#storep'); - $r->any('/storep/:id' => [id => qr/\d+/])->to('home#storep'); + $r->any('/spay/userCheck')->to('proc#userCheck'); # ============================================================================= # candy ======================================================================= @@ -48,10 +45,6 @@ use Dojo::Model::Vdgproc; $r->any('/candy')->to('home#candy'); # ============================================================================= -# json ======================================================================== - $r->any('/json/*dreq')->to('data#simple'); -# ============================================================================= - # usuarios y accesos ========================================================== $r->any('/reg')->to('users#reg'); @@ -74,14 +67,14 @@ use Dojo::Model::Vdgproc; # admin ======================================================================= my $admin = $r->under('/admin')->to('users#is_admin'); - $admin->any('')->to('home#admin'); - $admin->any('home')->to('home#admin_home'); - $admin->any('radio')->to('home#admin_radio'); - $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'); + $admin->any('')->to('admin#admin'); + $admin->any('home')->to('admin#admin'); + $admin->any('radio')->to('admin#radio'); + $admin->any('eventos')->to('admin#eventos'); + $admin->any('eventos/:type'=> [type=>['e','p','c']])->to('admin#eventos'); + $admin->any('mensajes')->to('admin#mensajes'); + $admin->any('tienda')->to('admin#tienda'); + $admin->any('json/:dreq/:id')->to('admin#json'); # ============================================================================= diff --git a/lib/Dojo/Controller/Admin.pm b/lib/Dojo/Controller/Admin.pm new file mode 100644 index 0000000..0ccc467 --- /dev/null +++ b/lib/Dojo/Controller/Admin.pm @@ -0,0 +1,82 @@ +package Dojo::Controller::Admin; +use Mojo::File 'path'; +use Mojo::JSON qw(decode_json encode_json); +use Mojo::Base 'Mojolicious::Controller'; +use Dojo::Support qw{ log }; + + +# pagina y mensajes =========================================================== +sub admin{ + my $c=shift; + my $n=$c->param("dreq")//""; + my $json = {status => "304"}; + $json = ($c->dbv->rmsgid ($c->param('id')))[0] if ($n =~m/^mensajes$/); + $json = ($c->dbv->ecourse($c->param('id')))[0] if ($n =~m/^ecourse$/); + $json = ($c->dbv->qcourse($c->param('id')))[0] if ($n =~m/^qcourse$/); + $json = ($c->dbv->qplace ($c->param('id')))[0] if ($n =~m/^qplace$/); + $c->render(json=>$json); +} + + +# Eventos ===================================================================== +sub admin_eventos{ + my $c=shift; + if ( (my $t=$c->param('type') // "") =~/[ecp]/){ + my $id=$c->param('id'); + my $req=$c->param('req'); + if ( $req eq "Eliminar"){ + $c->dbv->event_del($id) if ($t eq 'e'); + $c->dbv->course_del($id) if ($t eq 'c'); + $c->dbv->place_del($id) if ($t eq 'p'); + } + elsif( $req eq "Aceptar"){ + if($t eq 'e'){ + my @list=map{$c->param($_)}qw/eplace yini mini dini yend mend dend cost promo pen ecourse eimg een id/; + $c->dbv->event_up(@list) if ($id ==0); + $c->dbv->event_ch(@list) if ($id >0); + } + if($t eq 'c'){ + my @list=map{$c->param($_)}qw/cname csubjects cservices cen id/; + $c->dbv->course_up(@list) if ($id ==0); + $c->dbv->course_ch(@list) if ($id >0); + } + if($t eq 'p'){ + my @list=map{$c->param($_)}qw/pname paddr pobs pto pst pco plat plng pen id/; + $c->dbv->place_up(@list) if ($id ==0); + $c->dbv->place_ch(@list) if ($id >0); + } + } + $c->redirect_to("/admin/eventos"); + } + + $c->stash( + courses=>$c->dbv->courses, + places=>$c->dbv->places, + months=>$c->dbv->months, + events=>$c->dbv->events, + img=>$c->dbv->eimgList, + ); + $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"); +} + +# Funciones auxiliares ======================================================== +sub admin_json{ + my $c=shift; + my $id = $c->param('id'); + my $req = $c->param('dreq'); + my $json = "304"; + $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/; + $c->render(json=>$json); +} diff --git a/lib/Dojo/Controller/Data.pm b/lib/Dojo/Controller/Data.pm index c56b0a2..b440f03 100755 --- a/lib/Dojo/Controller/Data.pm +++ b/lib/Dojo/Controller/Data.pm @@ -8,6 +8,7 @@ use Net::Telnet; my $server_name = ""; our $t; #telnet server object my $data_path = path('lib/Dojo/Model/Data')->make_path; + sub simple{ my $c=shift; my $n=$c->param("dreq")//""; @@ -18,16 +19,6 @@ sub simple{ $c->render(json=>$json); } -sub admin{ - my $c=shift; - my $n=$c->param("dreq")//""; - my $json = {status => "304"}; - $json = ($c->dbv->rmsgid ($c->param('id')))[0] if ($n =~m/^mensajes$/); - $json = ($c->dbv->ecourse($c->param('id')))[0] if ($n =~m/^ecourse$/); - $json = ($c->dbv->qcourse($c->param('id')))[0] if ($n =~m/^qcourse$/); - $json = ($c->dbv->qplace ($c->param('id')))[0] if ($n =~m/^qplace$/); - $c->render(json=>$json); -} #==== candy ===================================================== sub candy{ my $c=shift; @@ -43,32 +34,36 @@ sub candy{ $c->render(json => {a=>$r}); } - sub turnOff{ - grep(/Result: true/,join('',sendT('host:deactivate("'.$server_name.'")')))?1:0 - unless (isOn()==0); - } - sub turnOn{ - grep(/Result: true/,join('',sendT('host:activate("'.$server_name.'")')))?1:0 - unless (isOn()==1); +sub turnOff{ + grep(/Result: true/,join('',sendT('host:deactivate("'.$server_name.'")')))?1:0 + unless (isOn()==0); +} + +sub turnOn{ + grep(/Result: true/,join('',sendT('host:activate("'.$server_name.'")')))?1:0 + unless (isOn()==1); } - sub isOn{return grep(/\s$server_name/,sendT("host:list()"))? 1:0; } +sub isOn{return grep(/\s$server_name/,sendT("host:list()"))? 1:0; } sub sendT{ commandT(shift); my @r = $t->getlines(All=>0); return @r } + sub connectT{ $t = new Net::Telnet ( Port=>5582, Timeout=>1, Errmode=>'return' ); # $t = new Net::Telnet ( Port=>5582, Timeout=>1, Errmode=>'die' ); return 1 if $t->open(); return 0; } + sub commandT{ $t->getlines(All=>0);#empty buffer $t->print(shift); #run istruction } + sub disconnectT{ $t->close();} #========================================================= diff --git a/lib/Dojo/Controller/Example.pm b/lib/Dojo/Controller/Example.pm deleted file mode 100755 index ccf02fe..0000000 --- a/lib/Dojo/Controller/Example.pm +++ /dev/null @@ -1,12 +0,0 @@ -package Dojo::Controller::Example; -use Mojo::Base 'Mojolicious::Controller'; - -# This action will render a template -sub welcome { - my $self = shift; - - # Render template "example/welcome.html.ep" with message - $self->render(msg => 'Welcome to the Mojolicious real-time web framework!'); -} - -1; diff --git a/lib/Dojo/Controller/Misc.pm b/lib/Dojo/Controller/Misc.pm deleted file mode 100644 index b2ccd17..0000000 --- a/lib/Dojo/Controller/Misc.pm +++ /dev/null @@ -1,107 +0,0 @@ -package Dojo::Controller::Misc; -use Mojo::Base 'Mojolicious::Controller'; -use Mojo::Template; -use Dojo::Support qw{ log get_names}; -# estos son paypal=======:w -use LWP::UserAgent; -use HTTP::Request::Common; -use JSON; -use Data::Dumper; - -# 4000004840000008 3, 6, 9, 12, and 18 month installment plans available -# "*p4000004840000008 -# 4242424242424242 No installment plans available. -my $sky='sk_test_GXWsfsoxy5336LrSw7SgTXNC00TV9O4Dbq'; -my $api_create_path='https://api.stripe.com/v1/payment_intents'; - -sub stripe { - my $self = shift; - my $request = defined ($self->req->json)? $self->req->json->{'req'}:"start"; - - # item info ====================== - my $header = "Beijing Wisdom
Healing Center"; - my $title = "Retiro Curso de Tercer método de ZhiNengQiGong"; - my $subtitle = "Una experiencia de instrucción del tercer método y profundización con los instructores ZhangQing (Helen) y QiuFuChun (Karl)."; - my ($amount,$description,$max_time) = (1417500,"Tercer método",9); - # ============================== - - if( $request eq "precheck" ){ - my $pmi=$self->req->json->{'payment_method_id'} // 0; - my $t = intentCreate( $pmi, $amount, $description, $max_time); - $self->render(json=>$t); - } - - elsif( $request eq "check" ){ - my $pii = $self->req->json->{'payment_intent_id'}; - my $plan = $self->req->json->{'selected_plan'}//0; - - unless ($plan==0) {if ($plan->{count} > $max_time) { - log("\n\n max time instalment attempt\n\n"); - $self->render(json=>{'error'=>'max time error'}); - return 0; - }} - my $r = intentConfirm($pii,$plan); - $self->render(json=>$r); - } - - else { - $self->stash(header=>$header); - $self->stash(title=>$title); - $self->stash(subtitle=>$subtitle); - $self->stash(layout=>'xpay'); - } -} - -#stripe appi functions -sub intentCreate{ - my ($pmi,$amount,$descriptor,$max_time) = @_; - my $payment_info=[ - 'payment_method'=>$pmi, - 'amount'=>$amount, - 'currency'=>'mxn', - 'description'=>$descriptor, - 'payment_method_options[card][installments][enabled]'=>'true' - ]; - my $r=stripeAppi($api_create_path,$payment_info); - my $t->{intent_id}=$r->{id}; - foreach (@{$r->{payment_method_options}{card}{installments}{available_plans}}){ - push (@{$t->{available_plans}}, $_) unless ($_->{count}>$max_time); - } - return $t; -} - -sub intentConfirm{ - my ($pii,$plan) = @_; - my $api_confirm_path = "https://api.stripe.com/v1/payment_intents/$pii/confirm"; - my $cplan=0; - - $cplan = [ - 'payment_method_options[card][installments][plan][type]'=>'fixed_count', - 'payment_method_options[card][installments][plan][interval]'=>'month', - 'payment_method_options[card][installments][plan][count]'=>$plan->{count}, - ] - unless ($plan==0); - my $r = stripeAppi($api_confirm_path,$cplan); - my $rtt = { - 'status'=>$r->{'status'}, - 'plan' => $r->{'payment_method_options'}{'card'}{'installments'}{'plan'}, - }; - return $rtt; -} - -sub stripeAppi{ - my ($path,$data) = @_; - my $req = POST $path, $data; - $req->authorization_basic($sky,''); - $req->content_type('application/x-www-form-urlencoded'); - my $ua = LWP::UserAgent->new; - my $res=$ua->request($req); - unless ($res->is_success){ - log("stripe error! path=$path\n data=".Dumper($data)."\n $res->status_line "); - return 0; - } - my $json = JSON->new->utf8; - return $json->decode($res->decoded_content); -} - -1; diff --git a/lib/Dojo/Controller/Proc.pm b/lib/Dojo/Controller/Proc.pm index d1cda06..c47a5c6 100644 --- a/lib/Dojo/Controller/Proc.pm +++ b/lib/Dojo/Controller/Proc.pm @@ -2,55 +2,14 @@ package Dojo::Controller::Proc; use Mojo::Base 'Mojolicious::Controller'; use Mojo::Template; 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; - 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 cal { @@ -71,67 +30,13 @@ sub event{ $c->stash(layout=> "defaultContact"); } - sub store{ my $c = shift; $c->stash( r=>$c->dbg->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 spay{ - my $c = shift; - my $data=$c->mproc->store_id($c->param('class'),$c->param('id')); - $c->stash($data); - if( ($c->param('id') <= 86) && ($c->param('id') >= 80) ) - { $c->stash(layout=>'xpay');} - else {$c->stash(layout=>'default');} -} - -#stripe appi functions +#stripe appi function ============================================================================= sub intentCreate{ my $c = shift; unless (defined ($c->req->json)){ @@ -139,21 +44,28 @@ sub intentCreate{ $c->render(template=>'home/not_found', status=>404); return 0; } - my $pmi=$c->req->json->{'payment_method_id'} // 0; + my $data=$c->mproc->intentCreate($c->req->json->{'tid'}); - my ($amount,$description,$max_time) = ($data->{'precio'},$data->{'nombre'},9); + # if(!@$data){ intentError($c,"event not found",1); return;}; + + my $pmi=$c->req->json->{'payment_method_id'} // 0; + my $amount = $data->{'precio'} * $c->req->json->{'mq'} ; + my $description = $data->{'nombre'}; + my $max_time = 9; + my $api_create_path='https://api.stripe.com/v1/payment_intents'; my $payment_info=[ 'payment_method'=>$pmi, - 'amount'=>$amount, + 'amount'=>$amount*100, 'currency'=>'mxn', 'description'=>$description, 'payment_method_options[card][installments][enabled]'=>'true' ]; my $r=stripeAppi($api_create_path,$payment_info); + if ($r==0){intentError($c,"api create error",1); return;} my $t->{intent_id}=$r->{id}; foreach (@{$r->{payment_method_options}{card}{installments}{available_plans}}){ - push (@{$t->{available_plans}}, $_) unless ($_->{count}>$max_time); + push (@{$t->{available_plans}}, $_) unless ($_->{count} > $max_time); } $c->render(json=>$t); return 0; @@ -162,30 +74,49 @@ sub intentCreate{ sub intentConfirm{ my $c = shift; my $max_time = 9; + unless (defined ($c->req->json)){ $c->stash(layout=>'clean'); $c->render(template=>'home/not_found', status=>404); - return; + return; } - my $pii = $c->req->json->{'payment_intent_id'}; - my $plan = $c->req->json->{'selected_plan'}//0; + + unless ($c->mproc->intentSanity($c->req->json) == 0 ){ + intentError($c,"sanity failed",0); return; } + + my $data = $c->req->json; + my $pii = $data->{'payment_intent_id'}; + my $plan = $data->{'selected_plan'} // 0; my $api_confirm_path = "https://api.stripe.com/v1/payment_intents/$pii/confirm"; - - unless ($plan==0) {if ($plan->{count} > $max_time) { - log("\n\n max time instalment attempt\n\n"); - $c->render(json=>{'error'=>'max time error'}); + + my $cplan = 0; + if ($plan != 0){ + if ($plan->{count} > $max_time) { + intentError($c,'max time installment attempt error',3); return 0; - }} - my $cplan=0; + } + $cplan = [ + 'payment_method_options[card][installments][plan][type]'=>'fixed_count', + 'payment_method_options[card][installments][plan][interval]'=>'month', + 'payment_method_options[card][installments][plan][count]'=>$plan->{count}, + ] + } + + if ( + intentCheck( + $c, + $data->{'payment_intent_id'}, + $data->{'tid'}, + $data->{'mq'} + ) == -1) { + intentError($c,"api confirm error pre",2); return; + } - $cplan = [ - 'payment_method_options[card][installments][plan][type]'=>'fixed_count', - 'payment_method_options[card][installments][plan][interval]'=>'month', - 'payment_method_options[card][installments][plan][count]'=>$plan->{count}, - ] - unless ($plan==0); my $r = stripeAppi($api_confirm_path,$cplan); - my $data=$c->mproc->intentCreate($c->req->json->{'tid'}); + if ($r==0){intentError($c,"api confirm error post",2); return;} + if ($r->{'status'} ne "succeeded" ){intentError($c,"payment not completed,2"); return;} + + $c->mproc->intentConfirm($data,$r); my $rtt = { 'status'=>$r->{'status'}, 'plan' => $r->{'payment_method_options'}{'card'}{'installments'}{'plan'}, @@ -194,11 +125,33 @@ sub intentConfirm{ return 0; } +sub intentError{ # e: error msg, stage: 0-userinfo, 1 icreate. 2 iconfirm + my $c = shift; + $c->render(json => { 'e'=>shift, 'stage'=>shift }); + return 0; +} + +sub userCheck{ + my $c=shift; + my $r = { 'userst' => $c->mproc->userDataSanity($c->req->json)}; + $c->render(json=>$r); + return 0; +} + +sub intentCheck{ + my ($c, $cid, $tid, $mq) = @_; + my $stripe = stripeAppi("https://api.stripe.com/v1/payment_intents/$cid",0); + my $data=$c->mproc->intentCreate($tid); + return -1 unless ( $stripe->{'amount'} == ($data->{'precio'} * $mq)*100); + return 0; +} + sub stripeAppi{ - my $sky='sk_test_GXWsfsoxy5336LrSw7SgTXNC00TV9O4Dbq'; my ($path,$data) = @_; - my $req = POST $path, $data; - $req->authorization_basic($sky,''); + my $req; + if ($data == 0 ) { $req = POST $path;} # -.- + else { $req = POST $path, $data;} + $req->authorization_basic(Dojo::Conf::STRIPE_SK,''); $req->content_type('application/x-www-form-urlencoded'); my $ua = LWP::UserAgent->new; my $res=$ua->request($req); @@ -210,71 +163,49 @@ sub stripeAppi{ return $json->decode($res->decoded_content); } -# Admin ======================================================================= - - - sub admin_eventos{ - my $c=shift; - if ( (my $t=$c->param('type') // "") =~/[ecp]/){ - my $id=$c->param('id'); - my $req=$c->param('req'); - if ( $req eq "Eliminar"){ - $c->dbv->event_del($id) if ($t eq 'e'); - $c->dbv->course_del($id) if ($t eq 'c'); - $c->dbv->place_del($id) if ($t eq 'p'); - } - elsif( $req eq "Aceptar"){ - if($t eq 'e'){ - my @list=map{$c->param($_)}qw/eplace yini mini dini yend mend dend cost promo pen ecourse eimg een id/; - $c->dbv->event_up(@list) if ($id ==0); - $c->dbv->event_ch(@list) if ($id >0); - } - if($t eq 'c'){ - my @list=map{$c->param($_)}qw/cname csubjects cservices cen id/; - $c->dbv->course_up(@list) if ($id ==0); - $c->dbv->course_ch(@list) if ($id >0); - } - if($t eq 'p'){ - my @list=map{$c->param($_)}qw/pname paddr pobs pto pst pco plat plng pen id/; - $c->dbv->place_up(@list) if ($id ==0); - $c->dbv->place_ch(@list) if ($id >0); - } - } - $c->redirect_to("/admin/eventos"); - } +# Not used but maybe later ====================================================== - $c->stash( - courses=>$c->dbv->courses, - places=>$c->dbv->places, - months=>$c->dbv->months, - events=>$c->dbv->events, - img=>$c->dbv->eimgList, - ); - $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; - my $id = $c->param('id'); - my $req = $c->param('dreq'); - my $json = "304"; - $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/; - $c->render(json=>$json); - } - - -#============================================================================== +#sub storeppl{ + #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'); + #} +#} + 1; diff --git a/lib/Dojo/Model/Data/store/qIdStore.q b/lib/Dojo/Model/Data/spay/qIdStore.q similarity index 100% rename from lib/Dojo/Model/Data/store/qIdStore.q rename to lib/Dojo/Model/Data/spay/qIdStore.q diff --git a/lib/Dojo/Model/Data/spay/qIntentConfirm.q b/lib/Dojo/Model/Data/spay/qIntentConfirm.q new file mode 100644 index 0000000..c6a2808 --- /dev/null +++ b/lib/Dojo/Model/Data/spay/qIntentConfirm.q @@ -0,0 +1,19 @@ +insert into caja_evento + ( + cliente_nombre, + cliente_correo, + cliente_comentario, + tienda_evento_id, + talla_id, + cantidad, + monto, + etapa_id, + entrega_id, + pago_clave, + plazo, + fecha_pago + ) +values (?,?,?,?,?,?,?,?,?,?,?,now()) +; + + diff --git a/lib/Dojo/Model/Data/spay/qIntentCreate.q b/lib/Dojo/Model/Data/spay/qIntentCreate.q new file mode 100644 index 0000000..e66bed1 --- /dev/null +++ b/lib/Dojo/Model/Data/spay/qIntentCreate.q @@ -0,0 +1,10 @@ +select + t.precio as precio, + c.nombre as nombre +from + tienda_evento as t +inner join + curso as c on t.curso_id=c.id +where + t.id = ? +; diff --git a/lib/Dojo/Model/Data/store/qEstore.q b/lib/Dojo/Model/Data/store/qEstore.q deleted file mode 100755 index bfc63b7..0000000 --- a/lib/Dojo/Model/Data/store/qEstore.q +++ /dev/null @@ -1,30 +0,0 @@ -select - t.id as tid, - c.nombre as nombre, - c.subnombre as subnombre, - c.descripcion as descripcion, - c.maestro as maestro, - c.imagen_a as cimga, - c.imagen_b as cimgb, - c.imagen_c as cimgc, - day(t.fecha_inicio) as dini, - month(t.fecha_inicio) as mini, - day(t.fecha_fin) as dfin, - month(t.fecha_fin) as mfin, - t.precio as precio, - t.promocion as promo, - t.promo_estado as promo_estado, - t.playera_estado as playera_estado, - t.cupo as cupo, - l.nombre as lnombre, - l.federativa as federativa, - l.pais as pais, - l.municipio as municipio -from tienda_evento as t - join curso as c on c.id = t.curso_id - join lugar as l on l.id = t.lugar_id - -where t.id=? and t.estado =1 -; - - diff --git a/lib/Dojo/Model/Data/store/qStore.q b/lib/Dojo/Model/Data/store/qStore.q deleted file mode 100755 index 00d2b4b..0000000 --- a/lib/Dojo/Model/Data/store/qStore.q +++ /dev/null @@ -1,10 +0,0 @@ -select - id, - objeto as "objeto", - nombre as "nombre", - precio as "precio", - subnombre as "subnombre", - promocion as "promocion", - imagen as "imagen" -from tienda where activo =1; - diff --git a/lib/Dojo/Model/Vdgproc.pm b/lib/Dojo/Model/Vdgproc.pm index bff3bc6..f53046e 100644 --- a/lib/Dojo/Model/Vdgproc.pm +++ b/lib/Dojo/Model/Vdgproc.pm @@ -1,9 +1,10 @@ package Dojo::Model::Vdgproc; use Mojo::File 'path'; use Mojo::JSON qw(decode_json encode_json); -use Dojo::Support qw{month_num2txt log dmph} ; +use Dojo::Support qw{ mtxt month_num2txt log dmph} ; use Mojo::Base 'Mojolicious::Controller'; - +use Email::Valid; +use Data::Dumper; use File::Basename; use Encode qw(decode_utf8 encode_utf8); use Text::Markdown qw{ markdown }; @@ -15,24 +16,13 @@ my $data_path = path('lib/Dojo/Model/Data')->make_path; #just for fun +# Tienda de eventos =========================================================== sub calendar_monthblock { my $r = _read ($data_path->child("cal/q1Block.q")->slurp); map { $_->{fecha}=month_num2txt($_->{month})." ".$_->{year} } @$r; return $r; } -sub mtxt { - my ($di, $mi, $df, $mf)=@_; # dini,mini,dfin,mfin - my $txt; - if ($mi == $mf){ - if ($di == $df){ $txt = "$di de ".month_num2txt($mi);} - else{ $txt = "Del $di al $df de ".month_num2txt($mi);} - } - else{ - $txt = "Del $di de ".month_num2txt($mi)." al $df de ".month_num2txt($mf); - } - return $txt; -} sub calendar_events { my $r = _read ($data_path->child("cal/q3Event.q")->slurp); foreach (@$r) { $_->{fecha} = mtxt( $_->{dini},$_->{mini},$_->{dfin},$_->{mfin}) } @@ -48,29 +38,103 @@ sub event{ sub spay { my ($c,$class,$id) = @_; - return _read ($data_path->child("/store/qIdStore.q")->slurp,$id)->[0]; + return _read ($data_path->child("spay/qIdStore.q")->slurp,$id)->[0]; } -# 4000004840000008 3, 6, 9, 12, and 18 month installment plans available -# "*p4000004840000008 -# 4242424242424242 No installment plans available. - -#============================================================================== sub store_id { my ($c,$class,$id) = @_; - my $r = _read ($data_path->child("/store/qEstore.q")->slurp,$id)->[0]; + my $r = _read ($data_path->child("store/qEstore.q")->slurp,$id)->[0]; $r->{fecha} = mtxt( $r->{dini},$r->{mini},$r->{dfin},$r->{mfin}); return $r; } + +# Stripe payment process ============================================================== +# ====================== +# 4000004840000008 3, 6, 9, 12, and 18 month installment plans available +# "*p4000004840000008 +# 4242424242424242 No installment plans available. +# ====================== + sub intentCreate{ my ($c,$id) = @_; - my $q="select t.precio as precio, c.nombre as nombre from tienda_evento as t inner join curso as c on t.curso_id=c.id where t.id = ? ;"; - return _read ($q,$id)->[0]; + return _read ($data_path->child("spay/qIntentCreate.q")->slurp,$id)->[0]; } + + sub intentConfirm{ - my ($c,$id) = @_; - my $q="select t.precio as precio, c.nombre as nombre from tienda_evento as t inner join curso as c on t.curso_id=c.id where t.id = ? ;"; - return _read ($q,$id)->[0]; + my ($c,$data,$r) = @_; + # cliente_nombre,cliente_correo,cliente_comentario,tienda_evento_id,talla_id,cantidad(1),monto,etapa_id(4),entrega(3),pago_clave,plazo,fecha_pago + my $mq = $data->{'mq'}; + my $students = $data->{'students'}; + my $plan = 0; + if (defined $data->{'selected_plan'}){ + $plan = $data->{'selected_plan'}->{'count'}; + } + for (1..$mq){ + _write ( + $data_path->child("/spay/qIntentConfirm.q")->slurp, + $$students[$_ -1][0], + $$students[$_ -1][1], + $$students[$_ -1][2], + $data->{'tid'}, + $$students[$_ -1][3], + $data->{'mq'}, + $r->{'amount'}, + 4, + 3, + $r->{'id'}, + $plan + ); + } # falta plazo + return ; +} + +# Check payment user info ============== + # data: + # =============== + #'selected_plan' => { 'type' => 'fixed_count', 'count' => 6, 'interval' => 'month' }, + #'mq' => '2', # cantidad de alumnas + #'req' => 'check', + #'payment_intent_id' => 'pi_1G1luSFBHoXN2vhnkl3PIiL1', + #'tid' => 80, #tienda id + #'students' => [ [ 'User', 'me@me.com', 'obs', 'M' ], [ 'usr2', 'mail2', 'obs', 'G' ], undef, undef, undef, undef, undef, undef, undef, undef ] #arr(10) +# =============== + +sub intentSanity{ + my ($c,$d)=@_; + if (defined $d->{'selected_plan'} ){ + return -1 unless defined ($d->{'selected_plan'}{'type'}); + return -1 unless defined ($d->{'selected_plan'}{'count'}); + return -1 unless defined ($d->{'selected_plan'}{'interval'}); + } + return -1 unless defined ($d->{'tid'}) && $d->{'tid'} =~ /^\d+$/ ; + return -1 unless defined ($d->{'req'}) && $d->{'req'} eq 'check'; + return -1 unless defined ($d->{'payment_intent_id'}); + return userDataSanity($c,$d) ; +} + +sub userDataSanity{ + my ($c,$d) = @_; + return -1 unless ( + defined ($d->{'students'}) && # (nombre,mail,observaciones, talla) + defined ($d->{'mq'}) && + $d->{'mq'} =~/^\d+$/ && + $d->{'mq'} < 10 + ); + my %h=qw(n 0 CH 1 M 2 G 3); + my $mq = $d->{'mq'}; + my $students = $d->{'students'}; + for (1..$mq){ + return $_ unless defined( $$students[$_ -1][0] ); + return $_ unless defined( $$students[$_ -1][1] ) && + is_mail($$students[$_ -1][1] ); + $$students[$_ -1][3] = $h{$$students[$_ -1][3] // 'n'}; + } + return 0; +} + +sub is_mail{ + return Email::Valid->address(shift); } #============================================================================== @@ -107,16 +171,7 @@ sub place_ch{ #============================================================================== -#ayudas ===================================== -sub tst{ - - my $c=shift; - my $d=$c->param('n'); - log("------log-------"); - log("$d"); - log("------log-------"); - return 0; -} +# lower level read ===================================== sub _read{ my ($q,@bind)=@_; diff --git a/lib/Dojo/Support.pm b/lib/Dojo/Support.pm index 5ef7a49..910e43d 100755 --- a/lib/Dojo/Support.pm +++ b/lib/Dojo/Support.pm @@ -2,7 +2,7 @@ package Dojo::Support; use strict; use warnings; use Exporter 'import'; -our @EXPORT = qw/ commify month_num2txt log dmph merge_hash load_module get_names /; +our @EXPORT = qw/ mtxt commify month_num2txt log dmph merge_hash load_module get_names /; use Mojo::Base 'Mojolicious'; use File::Basename; @@ -17,6 +17,7 @@ sub log{ my $log = Mojo::Log->new; $log->debug("============ ".shift." ==========="); } + sub get_names{ my $dir = shift; my @file_name; @@ -36,13 +37,26 @@ sub merge_hash{ my $merger = Hash::Merge->new('LEFT_PRECEDENT'); foreach (@_){ $h= $merger->merge($h,$_); - } - return $h; + } + return $h; } + sub month_num2txt{ return ("enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre" =~ m/\w+/g)[shift (@_) -1]; } +sub mtxt { + my ($di, $mi, $df, $mf)=@_; # dini,mini,dfin,mfin + my $txt; + if ($mi == $mf){ + if ($di == $df){ $txt = "$di de ".month_num2txt($mi);} + else{ $txt = "Del $di al $df de ".month_num2txt($mi);} + } + else{ + $txt = "Del $di de ".month_num2txt($mi)." al $df de ".month_num2txt($mf); + } + return $txt; +} #put comas on price numbers sub commify { diff --git a/public/home/admin/admin.css b/public/admin/admin.css similarity index 100% rename from public/home/admin/admin.css rename to public/admin/admin.css diff --git a/public/home/admin/candySwitch/cSwitch.js b/public/admin/candySwitch/cSwitch.js similarity index 100% rename from public/home/admin/candySwitch/cSwitch.js rename to public/admin/candySwitch/cSwitch.js diff --git a/public/home/admin/candySwitch/main.css b/public/admin/candySwitch/main.css similarity index 100% rename from public/home/admin/candySwitch/main.css rename to public/admin/candySwitch/main.css diff --git a/public/home/admin/candySwitch/switch.css b/public/admin/candySwitch/switch.css similarity index 100% rename from public/home/admin/candySwitch/switch.css rename to public/admin/candySwitch/switch.css diff --git a/public/home/admin/event/event.css b/public/admin/event/event.css similarity index 100% rename from public/home/admin/event/event.css rename to public/admin/event/event.css diff --git a/public/home/admin/event/event.js b/public/admin/event/event.js similarity index 100% rename from public/home/admin/event/event.js rename to public/admin/event/event.js diff --git a/public/home/admin/home/admin.css b/public/admin/home/admin.css similarity index 100% rename from public/home/admin/home/admin.css rename to public/admin/home/admin.css diff --git a/public/home/admin/home/buttons.js b/public/admin/home/buttons.js similarity index 100% rename from public/home/admin/home/buttons.js rename to public/admin/home/buttons.js diff --git a/public/home/admin/home/fb.js b/public/admin/home/fb.js similarity index 100% rename from public/home/admin/home/fb.js rename to public/admin/home/fb.js diff --git a/public/home/admin/mensajes/msg.css b/public/admin/mensajes/msg.css similarity index 100% rename from public/home/admin/mensajes/msg.css rename to public/admin/mensajes/msg.css diff --git a/public/home/admin/mensajes/msg.js b/public/admin/mensajes/msg.js similarity index 100% rename from public/home/admin/mensajes/msg.js rename to public/admin/mensajes/msg.js diff --git a/public/home/admin/radio/admin.css b/public/admin/radio/admin.css similarity index 100% rename from public/home/admin/radio/admin.css rename to public/admin/radio/admin.css diff --git a/public/home/admin/radio/loadInfo.js b/public/admin/radio/loadInfo.js similarity index 100% rename from public/home/admin/radio/loadInfo.js rename to public/admin/radio/loadInfo.js diff --git a/public/home/admin/tienda/tienda.css b/public/admin/tienda/tienda.css similarity index 100% rename from public/home/admin/tienda/tienda.css rename to public/admin/tienda/tienda.css diff --git a/public/home/admin/tienda/tienda.js b/public/admin/tienda/tienda.js similarity index 100% rename from public/home/admin/tienda/tienda.js rename to public/admin/tienda/tienda.js diff --git a/public/home/store/img/China.jpg b/public/home/store/img/China.jpg deleted file mode 100755 index 870d653..0000000 Binary files a/public/home/store/img/China.jpg and /dev/null differ diff --git a/public/home/store/img/libreta.jpg b/public/home/store/img/libreta.jpg deleted file mode 100755 index a49ec19..0000000 Binary files a/public/home/store/img/libreta.jpg and /dev/null differ diff --git a/public/home/store/img/libro.jpg b/public/home/store/img/libro.jpg deleted file mode 100755 index 5266c74..0000000 Binary files a/public/home/store/img/libro.jpg and /dev/null differ diff --git a/public/home/store/img/libro_old.jpg b/public/home/store/img/libro_old.jpg deleted file mode 100755 index bdfb4d7..0000000 Binary files a/public/home/store/img/libro_old.jpg and /dev/null differ diff --git a/public/home/store/img/mapa.jpg b/public/home/store/img/mapa.jpg deleted file mode 100755 index d6271fc..0000000 Binary files a/public/home/store/img/mapa.jpg and /dev/null differ diff --git a/public/home/store/img/momo.jpg b/public/home/store/img/momo.jpg deleted file mode 100755 index 898ee76..0000000 Binary files a/public/home/store/img/momo.jpg and /dev/null differ diff --git a/public/home/store/img/playera.jpg b/public/home/store/img/playera.jpg deleted file mode 100755 index 3954ff3..0000000 Binary files a/public/home/store/img/playera.jpg and /dev/null differ diff --git a/public/home/store/img/separa.jpg b/public/home/store/img/separa.jpg deleted file mode 100755 index b175eb9..0000000 Binary files a/public/home/store/img/separa.jpg and /dev/null differ diff --git a/public/home/store/shop.css b/public/home/store/shop.css deleted file mode 100755 index ac94cb5..0000000 --- a/public/home/store/shop.css +++ /dev/null @@ -1,62 +0,0 @@ -article.heading{ - width:100%; - height:55vh; - min-height:350px; - display: inline-block; - background-color: #333333; - text-align: center; - margin-top: 50px; -} -p.heading{ - font-size:5em; - color:white; - color: white; - margin: 20vh auto auto auto; -} -article.shop{ - justify-content:center; - -webkit-justify-content:center; - margin-top: 40px; -} -article.shop:hover{ - background-color:rgba(240,240,240); - cursor:pointer; -} - -a:link, a:visited { - text-decoration: none; - color:unset; -} - - -div.simage{ - flex:3; - max-width:350px; - transition: .5s ease; -} -div.simage:hover{ - transform:scale(1.2,1.2); -} -div.simage > img{ - max-width:70%; - max-height:100%; - margin:auto; - display:block; -} -div.description{ - flex:2; - max-width:250px; -} -p.description{ font-size:0.8em; } -p.title{font-weight:bold;} -p.promo{font-weight:bold; color:#C22A39;} -article.separator{ - background-repeat: no-repeat; - background-image: url(" #path img/separa.jpg"); - height: 20px; - background-size: contain; - background-position: center; - margin-top:30px; -} - - diff --git a/public/home/storep/grulla_10.jpg b/public/home/storep/grulla_10.jpg deleted file mode 100755 index 5e7a690..0000000 Binary files a/public/home/storep/grulla_10.jpg and /dev/null differ diff --git a/public/home/storep/storep.css b/public/home/storep/storep.css deleted file mode 100755 index af077aa..0000000 --- a/public/home/storep/storep.css +++ /dev/null @@ -1,106 +0,0 @@ -section.item{ - background-size:cover; - background-attachment: fixed; - background-image:url("grulla_10.jpg"); - background-position:center; - display:block; - padding:50px 0px 0px 0px; - -} -section.transp{ - background-color:rgba(255,255,255,0.8); - max-width: 1000px; -margin: auto; -padding: 20px 0px; -} - -article.iimage{ - flex:5 1; - margin:auto; - display:inline; - padding:0px 5px; - -} -img.small{ - border-radius:20px; - display:block; - width:auto; - height:100%; - min-height:60vh; - margin:auto; - padding:15px; -} -article.iinfo{ - flex:4 1; - margin:auto; - padding: 5px 15px; -} -p.txt{ - background-color:white; - font-size:1.2em; - padding: 20px; - text-align: center; -} - -section.ibottom{ - background: #C22A39; - padding:40px; - -} - -section.description{ - background-color:white; - justify-content: center; - -webkit-justify-content: center; -} - -p.promo{ -color: #c22a39; -font-size: 1.4em; -text-align:right; -margin-right:10%; - font-weight:bold; -} - - -p.elow{ -color: black; -font-size: 1.4em; -text-align:right; -margin-right:10%; -} - -p.eldep{ -color: #c22a39; -font-size: 1.4em; -text-align:right; - text-transform: uppercase; -margin-right:10%; - font-weight:bold; -} - -div.ppl{ -background-color: rgba(0,0,0,0.8); -border-radius: 25px; -padding:20px; -text-align: center; -} -p.nombre{ - font-size: 2.2em; - color: white; - text-align: left; - margin: auto; - text-decoration: underline; - max-width:850px; - font-weight:bold; -} - -p.tit{ - font-size: 1.8em; - color: white; - text-align: center; - margin: 30px auto; - font-style: italic; -} - - diff --git a/public/misc/stripe.js b/public/misc/stripe.js deleted file mode 100644 index 8fae3ec..0000000 --- a/public/misc/stripe.js +++ /dev/null @@ -1,131 +0,0 @@ - -var stripe = Stripe('pk_test_wxFt0GhsUK2YsprkLXa2iFrQ00nfjAeucu'); -var elements = stripe.elements(); -var cardElement = elements.create('card', { - style: { - base: { - //iconColor: '#c4f0ff', - iconColor: '#64a0af', - color: '#000000', - fontWeight: 500, - fontFamily: 'Roboto, Open Sans, Segoe UI, sans-serif', - fontSize: '18px', - fontSmoothing: 'antialiased', - ':-webkit-autofill': { - color: '#fce883', - }, - '::placeholder': { - // color: '#87BBFD', - color: '#87BBFD', - }, - }, - invalid: { - iconColor: '#8f577e', - color: '#8F577E', - }, - }, -}); -cardElement.mount('#card-element'); - - -var cardholderName = document.getElementById('cardholder-name'); -var cardButton = document.getElementById('card-button'); - -///*y este el codigo de validación de la tarjeta*/ -cardButton.addEventListener('click', function(ev) { - document.getElementById('cover').hidden = false; - document.getElementById("cover").style.opacity = "0.8"; - stripe.createPaymentMethod('card', cardElement, { - billing_details: {name: cardholderName.value} - }) - .then(function(result) { - // Show error in payment form - if (result.error) { - document.getElementById("cover").style.opacity = "0"; - setTimeout(function(){ document.getElementById('cover').hidden = true;},500); - console.log("network error"); - } - // Otherwise send paymentMethod.id to your server (see Step 2) - else { - fetch('/xpay', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ payment_method_id: result.paymentMethod.id, req:"precheck"}) - }) - .then(function(result) { - // Handle server response (see Step 3) - result.json().then(function(json) { handleInstallmentPlans(json); }) - }); - } - }); -}); - -///*presenta los planes de pago */ -const selectPlanForm = document.getElementById('installment-plan-form'); -let availablePlans = []; - -const handleInstallmentPlans = async (response) => { - if (response.error) { // Show error from server on payment form - console.log("preauth response error"); - } - else { - // Store the payment intent ID. - document.getElementById('payment-intent-id').value = response.intent_id; - availablePlans = response.available_plans; - // Show available installment options - availablePlans.forEach((plan, idx) => { - const newInput = document.getElementById('immediate-plan').cloneNode(); - newInput.setAttribute('value', idx); - newInput.setAttribute('id', ''); - const label = document.createElement('label'); - label.appendChild(newInput); - label.appendChild( - document.createTextNode(`${plan.count} meses`), - ); - selectPlanForm.appendChild(label); - }); - document.getElementById('cinfo').hidden = true; - document.getElementById('cplan').hidden = false; - } - document.getElementById("cover").style.opacity = "0"; - setTimeout(function(){ document.getElementById('cover').hidden = true;},500); -}; - -// termina la transacción -const confirmButton = document.getElementById('confirm-button'); -confirmButton.addEventListener('click', async (ev) => { - document.getElementById('cover').hidden = false; - document.getElementById("cover").style.opacity = "0.8"; - const selectedPlanIdx = selectPlanForm.installment_plan.value; - const selectedPlan = availablePlans[selectedPlanIdx]; - const intentId = document.getElementById('payment-intent-id').value; - const response = await fetch('/xpay', { - method: 'POST', - headers: {'Content-Type': 'application/json'}, - body: JSON.stringify({ - payment_intent_id: intentId, - selected_plan: selectedPlan, - req:"check" - }), - }); - const responseJson = await response.json(); - // Show success / error response. - document.getElementById("cover").style.opacity = "0"; - setTimeout(function(){ document.getElementById('cover').hidden = true;},500); - document.getElementById('cmsg').hidden = false; - document.getElementById('cplan').hidden = true; - var message; - if (responseJson.status === "succeeded" && selectedPlan !== undefined) { - message = `¡Tu compra a ${ - selectedPlan.count - } meses sin intereses se ha realizado con éxito! `; - } else if (responseJson.status === "succeeded") { - message = "¡Tu compra se ha realizado con éxito!"; - } else { - message = `Tenemos un problema para verificar tus datos. - Por favor intenta de nuevo o comunícate con nosotros`; - } - - document.getElementById("status-message").innerText = message; -}); - diff --git a/public/misc/xpay.css b/public/misc/xpay.css deleted file mode 100644 index b8d6daa..0000000 --- a/public/misc/xpay.css +++ /dev/null @@ -1,44 +0,0 @@ -html{font-family:"serif";} -section.title{ - /*background-color:#2f2c2c;*/ - /*color:white;*/ -} - -article.title{ -} - -h2{ -} -h1{ -} -div#cover{ - background: black; - z-index: 85; - position: fixed; - width: 100%; - height: 100%; - transition:opacity .4s linear; - top:0px; - opacity:0; -} -section.cardinfo{ -} -div#details{ - min-width:504px; -} -form{ - text-align:center; -} -label{ - text-align:center; - margin:auto; -} -input{ - display:block; - margin:auto; -} - -button{ -} -div#card-element{ -} diff --git a/public/home/cal/cal.css b/public/proc/cal/cal.css similarity index 100% rename from public/home/cal/cal.css rename to public/proc/cal/cal.css diff --git a/public/home/cal/img/Argentina.jpg b/public/proc/cal/img/Argentina.jpg similarity index 100% rename from public/home/cal/img/Argentina.jpg rename to public/proc/cal/img/Argentina.jpg diff --git a/public/home/cal/img/CDMX.jpg b/public/proc/cal/img/CDMX.jpg similarity index 100% rename from public/home/cal/img/CDMX.jpg rename to public/proc/cal/img/CDMX.jpg diff --git a/public/home/cal/img/Cancun.jpg b/public/proc/cal/img/Cancun.jpg similarity index 100% rename from public/home/cal/img/Cancun.jpg rename to public/proc/cal/img/Cancun.jpg diff --git a/public/home/cal/img/Carmen.jpg b/public/proc/cal/img/Carmen.jpg similarity index 100% rename from public/home/cal/img/Carmen.jpg rename to public/proc/cal/img/Carmen.jpg diff --git a/public/home/cal/img/Chile.jpg b/public/proc/cal/img/Chile.jpg similarity index 100% rename from public/home/cal/img/Chile.jpg rename to public/proc/cal/img/Chile.jpg diff --git a/public/home/cal/img/China.jpg b/public/proc/cal/img/China.jpg similarity index 100% rename from public/home/cal/img/China.jpg rename to public/proc/cal/img/China.jpg diff --git a/public/home/cal/img/Cuba.jpg b/public/proc/cal/img/Cuba.jpg similarity index 100% rename from public/home/cal/img/Cuba.jpg rename to public/proc/cal/img/Cuba.jpg diff --git a/public/home/cal/img/Ensenada.jpg b/public/proc/cal/img/Ensenada.jpg similarity index 100% rename from public/home/cal/img/Ensenada.jpg rename to public/proc/cal/img/Ensenada.jpg diff --git a/public/home/cal/img/Guadalajara.jpg b/public/proc/cal/img/Guadalajara.jpg similarity index 100% rename from public/home/cal/img/Guadalajara.jpg rename to public/proc/cal/img/Guadalajara.jpg diff --git a/public/home/cal/img/Hidalgo.jpg b/public/proc/cal/img/Hidalgo.jpg similarity index 100% rename from public/home/cal/img/Hidalgo.jpg rename to public/proc/cal/img/Hidalgo.jpg diff --git a/public/home/cal/img/Leon.jpg b/public/proc/cal/img/Leon.jpg similarity index 100% rename from public/home/cal/img/Leon.jpg rename to public/proc/cal/img/Leon.jpg diff --git a/public/home/cal/img/Merida.jpg b/public/proc/cal/img/Merida.jpg similarity index 100% rename from public/home/cal/img/Merida.jpg rename to public/proc/cal/img/Merida.jpg diff --git a/public/home/cal/img/Mexicali.jpg b/public/proc/cal/img/Mexicali.jpg similarity index 100% rename from public/home/cal/img/Mexicali.jpg rename to public/proc/cal/img/Mexicali.jpg diff --git a/public/home/cal/img/Monterrey.jpg b/public/proc/cal/img/Monterrey.jpg similarity index 100% rename from public/home/cal/img/Monterrey.jpg rename to public/proc/cal/img/Monterrey.jpg diff --git a/public/home/cal/img/Oaxaca.jpg b/public/proc/cal/img/Oaxaca.jpg similarity index 100% rename from public/home/cal/img/Oaxaca.jpg rename to public/proc/cal/img/Oaxaca.jpg diff --git a/public/home/cal/img/Puebla.jpg b/public/proc/cal/img/Puebla.jpg similarity index 100% rename from public/home/cal/img/Puebla.jpg rename to public/proc/cal/img/Puebla.jpg diff --git a/public/home/cal/img/Queretaro.jpg b/public/proc/cal/img/Queretaro.jpg similarity index 100% rename from public/home/cal/img/Queretaro.jpg rename to public/proc/cal/img/Queretaro.jpg diff --git a/public/home/cal/img/Tepoztlan.jpg b/public/proc/cal/img/Tepoztlan.jpg similarity index 100% rename from public/home/cal/img/Tepoztlan.jpg rename to public/proc/cal/img/Tepoztlan.jpg diff --git a/public/home/cal/img/Veracruz.jpg b/public/proc/cal/img/Veracruz.jpg similarity index 100% rename from public/home/cal/img/Veracruz.jpg rename to public/proc/cal/img/Veracruz.jpg diff --git a/public/home/cal/img/Xalapa.jpg b/public/proc/cal/img/Xalapa.jpg similarity index 100% rename from public/home/cal/img/Xalapa.jpg rename to public/proc/cal/img/Xalapa.jpg diff --git a/public/home/cal/img/Xalpan.jpg b/public/proc/cal/img/Xalpan.jpg similarity index 100% rename from public/home/cal/img/Xalpan.jpg rename to public/proc/cal/img/Xalpan.jpg diff --git a/public/home/event/event.css b/public/proc/event/event.css similarity index 100% rename from public/home/event/event.css rename to public/proc/event/event.css diff --git a/public/home/event/img/grulla_10.jpg b/public/proc/event/img/grulla_10.jpg similarity index 100% rename from public/home/event/img/grulla_10.jpg rename to public/proc/event/img/grulla_10.jpg diff --git a/public/home/spay/grulla_10.jpg b/public/proc/spay/grulla_10.jpg similarity index 100% rename from public/home/spay/grulla_10.jpg rename to public/proc/spay/grulla_10.jpg diff --git a/public/home/spay/storep.css b/public/proc/spay/storep.css similarity index 100% rename from public/home/spay/storep.css rename to public/proc/spay/storep.css diff --git a/public/home/spay/stripe.js b/public/proc/spay/stripe.js similarity index 76% rename from public/home/spay/stripe.js rename to public/proc/spay/stripe.js index 72dd88e..7a5beb2 100644 --- a/public/home/spay/stripe.js +++ b/public/proc/spay/stripe.js @@ -2,6 +2,7 @@ var it=1; var students = new Array(10); +/* price format (comas) */ window.addEventListener('load', function() { document.getElementById('cu').innerHTML=cu.toLocaleString(); document.getElementById('gt').innerHTML=cu.toLocaleString(); @@ -12,19 +13,25 @@ mq.addEventListener('change',function() { var mult = cu*mq.value; document.getElementById('gt').innerHTML=mult.toLocaleString(); }); +/* ====================== */ -/* hide contact form, show card info fields */ +/* vars to hide contact form, show card info fields */ var cinfob = document.getElementById('cinfob'); var cinfo = document.getElementById('cinfo'); var cform = document.getElementById('cform'); var ccard = document.getElementById('ccard'); +/* ====================== */ + +/* back button ========== */ cinfob.addEventListener('click', function(ev){ it --; atof(); if (it==1){cinfob.hidden=true;} }); +/* ====================== */ +/* fwd button============ */ cinfo.addEventListener('click', function(ev){ if ( (document.forms["cform"]["mname"].value =="") || @@ -33,18 +40,39 @@ cinfo.addEventListener('click', function(ev){ else if ( mq.value > it) { students[it - 1]=ftoa(); it ++; - if(typeof students[it - 1]!== "undefined"){ - atof(); - } + if(typeof students[it - 1]!== "undefined"){ atof(); } cinfob.hidden=false; } else { students[it - 1]=ftoa(); - cform.hidden = true; - ccard.hidden = false; + document.getElementById('cover').hidden = false; + document.getElementById("cover").style.opacity = "0.8"; + fetch('/spay/userCheck', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ students:students, req:"precheck", mq:mq.value}) + + }) + .then((response) => response.json()) + .then((data) => { + if(data.userst == "0"){ + cform.hidden = true; + ccard.hidden = false; + } + else{ alert("hay un error en los datos de alumnos"); } + }) + .catch((error) => { + console.error('Error:', error); + }); + + document.getElementById("cover").style.opacity = "0"; + setTimeout(function(){ document.getElementById('cover').hidden = true;},500); } }); +/* ====================== */ + +/* save form to array=== */ function ftoa(){ var rad; if (document.getElementById('r2').checked) { rad = document.getElementById('r2').value; } @@ -63,17 +91,21 @@ function ftoa(){ return x; } +/* ====================== */ +/* load form from array=== */ function atof(){ - document.forms["cform"]["mname"].value = students[it-1][0]; - document.forms["cform"]["mmail"].value = students[it-1][1]; - document.getElementById('obs').value = students[it-1][2]; - if(document.getElementById('r2').value == students[it-1][3]){ document.getElementById('r2').checked=true;} - if(document.getElementById('r1').value == students[it-1][3]){ document.getElementById('r1').checked=true;} - if(document.getElementById('r3').value == students[it-1][3]){ document.getElementById('r3').checked=true;} + document.forms["cform"]["mname"].value = students[it-1][0]; + document.forms["cform"]["mmail"].value = students[it-1][1]; + document.getElementById('obs').value = students[it-1][2]; + if(document.getElementById('r2').value == students[it-1][3]){ document.getElementById('r2').checked=true;} + if(document.getElementById('r1').value == students[it-1][3]){ document.getElementById('r1').checked=true;} + if(document.getElementById('r3').value == students[it-1][3]){ document.getElementById('r3').checked=true;} } +/* ====================== */ /* stripe magic begins here */ +/* ====================================================== */ var stripe = Stripe('pk_test_wxFt0GhsUK2YsprkLXa2iFrQ00nfjAeucu'); var elements = stripe.elements(); var cardElement = elements.create('card', { @@ -125,7 +157,7 @@ cardButton.addEventListener('click', function(ev) { fetch('/spay/intentCreate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ payment_method_id: result.paymentMethod.id, req:"precheck", qantity:mq.value, tid:tid}) + body: JSON.stringify({ payment_method_id: result.paymentMethod.id, req:"precheck", mq:mq.value, tid:tid}) }) .then(function(result) { // Handle server response (see Step 3) @@ -144,6 +176,7 @@ const handleInstallmentPlans = async (response) => { console.log("preauth response error"); } else { + // si avaliable plans es indefinido, se queda alli con el cover // Store the payment intent ID. document.getElementById('payment-intent-id').value = response.intent_id; availablePlans = response.available_plans; diff --git a/templates/home/admin/candySwitch.html.ep b/templates/admin/candySwitch.html.ep similarity index 100% rename from templates/home/admin/candySwitch.html.ep rename to templates/admin/candySwitch.html.ep diff --git a/templates/home/admin/event.html.ep b/templates/admin/event.html.ep similarity index 98% rename from templates/home/admin/event.html.ep rename to templates/admin/event.html.ep index b5c2d0b..6ac7c99 100755 --- a/templates/home/admin/event.html.ep +++ b/templates/admin/event.html.ep @@ -1,5 +1,5 @@ -% stash css=>["/home/admin/admin.css","/home/admin/event/event.css"]; -% stash js=>["/home/admin/event/event.js"]; +% stash css=>["/admin/admin.css","/admin/event/event.css"]; +% stash js=>["//admin/event/event.js"];

Editar Eventos

diff --git a/templates/home/admin/home.html.ep b/templates/admin/home.html.ep similarity index 93% rename from templates/home/admin/home.html.ep rename to templates/admin/home.html.ep index b391c33..833e1b5 100755 --- a/templates/home/admin/home.html.ep +++ b/templates/admin/home.html.ep @@ -1,5 +1,5 @@ -% stash css=>["/home/admin/admin.css","/home/admin/home/admin.css"]; -% stash js=>["/home/admin/home/buttons.js","/home/admin/home/fb.js"]; +% stash css=>["/admin/admin.css","/admin/home/admin.css"]; +% stash js=>["/admin/home/buttons.js","/admin/home/fb.js"];

Editar Casa

diff --git a/templates/home/admin/mensajes.html.ep b/templates/admin/mensajes.html.ep similarity index 80% rename from templates/home/admin/mensajes.html.ep rename to templates/admin/mensajes.html.ep index e1c6659..78e790d 100755 --- a/templates/home/admin/mensajes.html.ep +++ b/templates/admin/mensajes.html.ep @@ -1,5 +1,5 @@ -% stash css=>["/home/admin/admin.css","/home/admin/mensajes/msg.css"]; -% stash js=>["/home/admin/mensajes/msg.js"]; +% stash css=>["/admin/admin.css","/admin/mensajes/msg.css"]; +% stash js=>["/admin/mensajes/msg.js"];
diff --git a/templates/misc/stripe.html.ep b/templates/misc/stripe.html.ep deleted file mode 100644 index ebaecda..0000000 --- a/templates/misc/stripe.html.ep +++ /dev/null @@ -1,56 +0,0 @@ - -% stash css => ["misc/xpay.css"]; -% stash js => ["misc/stripe.js"]; -
-

<%== $header %>

-
-
-
-

<%= $title %>

-

<%= $subtitle %>

-
-
- -
- -
-

Datos de la tarjeta

-
- - - - -
- -
-
- - -
diff --git a/templates/proc/cal.html.ep b/templates/proc/cal.html.ep index 1ae5490..c4ceb14 100755 --- a/templates/proc/cal.html.ep +++ b/templates/proc/cal.html.ep @@ -1,4 +1,4 @@ -% stash css=>["home/cal/cal.css/"]; +% stash css=>["proc/cal/cal.css/"];

Próximos eventos

% foreach (@$b) { @@ -19,7 +19,7 @@

<%= $d->{nombre} %>

- +
...
diff --git a/templates/proc/estore.html.ep b/templates/proc/estore.html.ep deleted file mode 100755 index fb80deb..0000000 --- a/templates/proc/estore.html.ep +++ /dev/null @@ -1,24 +0,0 @@ -%stash css=>["/home/storep/storep.css"]; -
-
-

<%= $nombre %>

-

<%= $lmunicipio %>, <%= $lfederativa %>

-
-
- -
-
-

<%= $subnombre %>

-

<%= $descripcion %>

-

<%= $promocion %>

-

Precio:$<%= $precio %> pesos

-

- <% if ($cupo > 10) { =%>

<% } =%> - <% elsif ($cupo >= 5) { =%>

¡Nos quedan pocos lugarel!

<% } =%> - <% elsif ($cupo == 0) { =%>

¡Agotado!

<% } =%> -
-
-
-
- - diff --git a/templates/proc/event.html.ep b/templates/proc/event.html.ep index 9f9b882..d06c923 100755 --- a/templates/proc/event.html.ep +++ b/templates/proc/event.html.ep @@ -1,4 +1,4 @@ -% stash css=> ["/home/event/event.css"]; +% stash css=> ["/proc/event/event.css"];
diff --git a/templates/proc/spay.html.ep b/templates/proc/spay.html.ep index 9b34d4b..967b9bf 100755 --- a/templates/proc/spay.html.ep +++ b/templates/proc/spay.html.ep @@ -1,5 +1,5 @@ -%stash css=>["/home/spay/storep.css"]; -%stash js => ["/home/spay/stripe.js"]; +%stash css=>["/proc/spay/storep.css"]; +%stash js => ["/proc/spay/stripe.js"];
@@ -12,7 +12,7 @@

<%= $subnombre %>

- +

<%= $descripcion %>

diff --git a/templates/proc/store.html.ep b/templates/proc/store.html.ep deleted file mode 100755 index 0b90455..0000000 --- a/templates/proc/store.html.ep +++ /dev/null @@ -1,22 +0,0 @@ -% stash css=>["/home/store/shop.css"]; -
-

TIENDA VIRTUAL

- % for (@$r){ - -
-
{imagen} "%> >
-
-

<%= $_->{objeto} %>

-

<%= $_->{nombre} %>

- % if ( $_->{precio} != -1){ -

$<%= $_->{precio} %> pesos

- %} -

<%= $_->{subnombre} %>

-

<%= $_->{promocion} %>

-
-
-
-
- %} -
- diff --git a/templates/proc/storep.html.ep b/templates/proc/storep.html.ep deleted file mode 100755 index 9177c4f..0000000 --- a/templates/proc/storep.html.ep +++ /dev/null @@ -1,60 +0,0 @@ - - - - -%stash css=>["/home/storep/storep.css"]; -
-
- -
-
-

<%= $subnombre %>

-

<%= $descripcion %>

-

<%= $promocion %>

-

Precio:$<%= $precio %> pesos

-

- <% if ($existencia > 10) { =%>

<% } =%> - <% elsif ($existencia >= 1) { =%>

¡Nos quedan pocos!

<% } =%> - <% elsif ($existencia == 0) { =%>

¡Agotado!

<% } =%> -
-
-
-
-
-
-

<%= $objeto %>

-

<%= $nombre %>

-
-
- - - - -