This commit is contained in:
mynah
2019-04-02 19:19:41 -06:00
parent 2848f7ca42
commit d72871332c
6 changed files with 195 additions and 67 deletions

View File

@@ -27,7 +27,7 @@ use Dojo::Model::Users;
$r->any('/contact')->to('home#contact'); $r->any('/contact')->to('home#contact');
$r->any('/contact2')->to('home#contact2'); $r->any('/contact2')->to('home#contact2');
$r->any('/pang')->to('home#pang'); $r->any('/pang')->to('home#pang');
$r->any('/tst')->to('home#tst'); # $r->any('/tst')->to('home#tst');
# ============================================================================= # =============================================================================

View File

@@ -10,11 +10,14 @@ use Data::Dumper;
#========================= #=========================
sub tst{ sub tst{
my $c=shift; my $c=shift;
if( defined($c->req->json) ){
my $oid = $c->req->json->{'orderID'} //0;
log( $oid );
#credentials==== #credentials====
my $client='AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7'; my $client='AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7';
my $secter='EBn8CNOCrJbVZ_fNllXB7oUIm9_vhtqrJMm2zSBGbxSyiiych3cHOIWOLAD5NVw4Z3dmNhmsHQwPsrZ0'; my $secter='EBn8CNOCrJbVZ_fNllXB7oUIm9_vhtqrJMm2zSBGbxSyiiych3cHOIWOLAD5NVw4Z3dmNhmsHQwPsrZ0';
my $pauth='https://api.sandbox.paypal.com/v1/oauth2/token/'; my $pauth='https://api.sandbox.paypal.com/v1/oauth2/token/';
my $porder='https://api.sandbox.paypal.com/v2/checkout/orders/2'; my $porder='https://api.sandbox.paypal.com/v2/checkout/orders/';
#================= #=================
#pre auth ==== #pre auth ====
my $ua = LWP::UserAgent->new; my $ua = LWP::UserAgent->new;
@@ -27,21 +30,24 @@ my $json = JSON->new->utf8;
my $r=$json->decode($res->decoded_content); my $r=$json->decode($res->decoded_content);
#============== #==============
#order details ====
my $ub = LWP::UserAgent->new; my $ub = LWP::UserAgent->new;
$ub->default_header('Content-Type'=> 'application/json' );
$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} ); $ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
my $resb=$ub->get($porder); my $resb=$ub->get($porder.$oid);
log("paypal checkout error!") unless ($resb->is_success ); log("paypal checkout error!") unless ($resb->is_success );
my $jsonb = JSON->new->utf8; my $jsonb = JSON->new->utf8;
my $s=$jsonb->decode($resb->decoded_content); 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{
$c->stash(res=>" $r->{expires_in} $s->{name}"); 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");
$c->stash(layout=>'default'); $c->stash(layout=>'default');
}
#$c->render(text=> $c->config->{radio}{'channel'}); #$c->render(text=> $c->config->{radio}{'channel'});
} }

View File

@@ -1,4 +1,4 @@
section.eimage{ section.item{
background-size:cover; background-size:cover;
height:80vh; height:80vh;
background-attachment: fixed; background-attachment: fixed;

BIN
public/home/tst/grulla_10.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 KiB

View File

@@ -0,0 +1,106 @@
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;
}

View File

@@ -2,40 +2,56 @@
<!--<meta name="viewport" content="width=device-width, initial-scale=1">--> <!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge" />--> <!--<meta http-equiv="X-UA-Compatible" content="IE=edge" />-->
<!--</head>--> <!--</head>-->
<p> %stash css=>["/home/tst/tst.css"];
<%= url_for("$controller/$action/img") %> <section class="item"> <section class="transp flex">
%= url_for->path('/meself') <article class=iimage>
</p> <img class="small" src= "home/store/img/libro.jpg">
<p> </article>
<%= $res %> <article class=iinfo>
</p> <p class="txt"><%= $descripcion %></p>
<p class="promo"><%= $promo %></p>
<!-- Set up a container element for the button --> <p class="precio">Precio:$<%= $precio %> pesos</p>
<p class="existencia">
<% if ($existencia > 10) { =%> <p class="eok"></p> <% } =%>
<% elsif ($existencia >= 1) { =%> <p class="elow">¡Nos quedan pocos!</p> <% } =%>
<% elsif ($existencia == 0) { =%> <p class="eldep">¡Agotado!</p> <% } =%>
<div class=ppl>
<div id="paypal-button-container"></div> <div id="paypal-button-container"></div>
</div>
</article>
</section> </section>
<section class="ibottom">
<p class="nombre"><%= $nombre %></p>
<p class="tit"><%= $titulo %></p>
</section>
<section class="bdat"> </section>
<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7&currency=MXN"></script> <script src="https://www.paypal.com/sdk/js?client-id=AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7&currency=MXN"></script>
<script> <script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({ paypal.Buttons({
// Set up the transaction // Set up the transaction
createOrder: function(data, actions) { createOrder: function(data, actions) {
return actions.order.create({ return actions.order.create({
purchase_units: [{ purchase_units: [{
amount: { amount: {
value: '1.00' value: '0.18'
} }
}] }]
}); }); },
},
// Finalize the transaction
onApprove: function(data, actions) { onApprove: function(data, actions) {
return actions.order.capture().then(function(details) { return actions.order.capture().then(function(details) {
// Show a success message to the buyer return fetch('/tst', {
alert('Transaction completed by ' + details.payer.name.given_name + '!'); method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
})
// .then(response=>response.json())
// .then(data => {alert(data)})
}); });
} }
}).render('#paypal-button-container'); }).render('#paypal-button-container');