This commit is contained in:
mynah
2020-01-15 23:42:58 -06:00
parent 567e991278
commit 252ec865b3
33 changed files with 1556 additions and 238 deletions

View File

@@ -2,9 +2,6 @@ package Dojo::Controller::Home;
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;
#=========================
@@ -70,25 +67,6 @@ sub pang {
my $h=$c->dbv->pang_md;
map { $c->stash( $_ => $h->{$_}) } keys %$h;
$c->stash(layout=>'default');
}
sub cal {
my $c = shift;
my $data=$c->dbv->calendar_events;
my $block=$c->dbv->calendar_monthblock;
my %h;
map{ push @{ $h{$_->{bid}} },$_; }(@$data);
$c->stash( r=>\%h, b=>$block);
$c->stash(layout=>'default');
}
sub event{
my $c = shift;
my $data=$c->dbv->event($c->param('id'));
$c->redirect_to('cal') unless ($data->{'cname'});
$c->stash($data);
$c->stash(layout=> "defaultContact");
}
sub contact{
@@ -114,56 +92,6 @@ sub contact2{
$c->stash(layout=>'default');
}
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 tv{
my $c = shift;
$c->stash( videos=>$c->dbv->tv_videos, table=>$c->dbv->tv_series);
@@ -181,21 +109,21 @@ sub bcast{
$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 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"]);
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"));
}
$c->stash(layout=> "clean");
$c->stash(nick=>$c->session("nick"));
}
#==============================================================================
@@ -234,55 +162,6 @@ sub bcast{
$c->stash(layout=>"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");
}
$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');
@@ -290,10 +169,6 @@ sub bcast{
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/;
$c->render(json=>$json);
}

107
lib/Dojo/Controller/Misc.pm Normal file
View File

@@ -0,0 +1,107 @@
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 </br> 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;

280
lib/Dojo/Controller/Proc.pm Normal file
View File

@@ -0,0 +1,280 @@
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 {
my $c = shift;
my $data=$c->mproc->calendar_events;
my $block=$c->mproc->calendar_monthblock;
my %h;
map{ push @{ $h{$_->{bid}} },$_; }(@$data);
$c->stash( r=>\%h, b=>$block);
$c->stash(layout=>'default');
}
sub event{
my $c = shift;
my $data=$c->mproc->event($c->param('id'));
$c->redirect_to('cal') unless ($data->{'cname'});
$c->stash($data);
$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
sub intentCreate{
my $c = shift;
unless (defined ($c->req->json)){
$c->stash(layout=>'clean');
$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);
my $api_create_path='https://api.stripe.com/v1/payment_intents';
my $payment_info=[
'payment_method'=>$pmi,
'amount'=>$amount,
'currency'=>'mxn',
'description'=>$description,
'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);
}
$c->render(json=>$t);
return 0;
}
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;
}
my $pii = $c->req->json->{'payment_intent_id'};
my $plan = $c->req->json->{'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'});
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},
]
unless ($plan==0);
my $r = stripeAppi($api_confirm_path,$cplan);
my $data=$c->mproc->intentCreate($c->req->json->{'tid'});
my $rtt = {
'status'=>$r->{'status'},
'plan' => $r->{'payment_method_options'}{'card'}{'installments'}{'plan'},
};
$c->render(json=>$rtt);
return 0;
}
sub stripeAppi{
my $sky='sk_test_GXWsfsoxy5336LrSw7SgTXNC00TV9O4Dbq';
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);
}
# 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");
}
$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);
}
#==============================================================================
1;