29.-Realizar el pago con stripe en PHP
En este tutorial vamos a Realizar el pago con stripe en PHP siguiendo estos pasos:
- 1.- Habilitar el boton pagar.
- 2.- Realizar el cargo a través de stripe.
- 3.- Guardar los datos de la venta en la tabla ventas.
Codigo: https://github.com/programadornovato/ecommerce/commit/d856c46bdf63684cde91cda51a8b1eab2fb0c1db
factura.php
<?php $total=$_REQUEST['total']??''; include_once "stripe/init.php"; \Stripe\Stripe::setApiKey("sk_test_JaTXHOFLk3lllnj1PnpahfxR00NLGmUe8M"); $toke=$_POST['stripeToken']; $charge=\Stripe\Charge::create([ 'amount'=>$total, 'currency'=>'usd', 'description'=>'Pago de ecommerce', 'source'=>$toke ]); if($charge['captured']){ $queryVenta="INSERT INTO ventas (idCli ,idPago ,fecha) values ('".$_SESSION['idCliente']."','".$charge['id']."',now()); "; $resVenta=mysqli_query($con,$queryVenta); $id=mysqli_insert_id($con); if($resVenta){ echo "La venta fue exitosa con el id=".$id; } } ?>
index.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>My ecommerce by pn</title> <!-- Tell the browser to be responsive to screen width --> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Font Awesome --> <link rel="stylesheet" href="admin/plugins/fontawesome-free/css/all.min.css"> <!-- Ionicons --> <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <!-- Theme style --> <link rel="stylesheet" href="admin/dist/css/adminlte.min.css"> <!-- Daterange picker --> <link rel="stylesheet" href="admin/plugins/daterangepicker/daterangepicker.css"> <!-- Google Font: Source Sans Pro --> <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet"> <link rel="stylesheet" href="admin/css/stripe.css"> <?php session_start(); $accion=$_REQUEST['accion']??''; if($accion=='cerrar'){ session_destroy(); header("Refresh:0"); } ?> </head> <body> <?php include_once "admin/db_ecommerce.php"; $con = mysqli_connect($host, $user, $pass, $db); ?> <div class="container"> <div class="row"> <div class="col-12"> <?php include_once "menu.php"; $modulo=$_REQUEST['modulo']??''; if($modulo=="productos" || $modulo=="" ){ include_once "productos.php"; } if( $modulo=="detalleproducto" ){ include_once "detalleProducto.php"; } if( $modulo=="carrito" ){ include_once "carrito.php"; } if( $modulo=="envio" ){ include_once "envio.php"; } if( $modulo=="pasarela" ){ include_once "pasarela.php"; } if( $modulo=="factura" ){ include_once "factura.php"; } ?> </div> </div> </div> <!-- jQuery --> <script src="admin/plugins/jquery/jquery.min.js"></script> <!-- jQuery UI 1.11.4 --> <script src="admin/plugins/jquery-ui/jquery-ui.min.js"></script> <!-- Bootstrap 4 --> <script src="admin/plugins/bootstrap/js/bootstrap.bundle.min.js"></script> <!-- daterangepicker --> <script src="admin/plugins/moment/moment.min.js"></script> <script src="admin/plugins/daterangepicker/daterangepicker.js"></script> <!-- AdminLTE App --> <script src="admin/dist/js/adminlte.js"></script> <!-- AdminLTE dashboard demo (This is only for demo purposes) --> <script src="admin/dist/js/pages/dashboard.js"></script> <script src="https://js.stripe.com/v3/"></script> <script src="admin/js/stripe.js"></script> <script src="admin/js/ecommerce.js"></script> </body> </html>
pasarela.php
<form action="index.php?modulo=factura" method="post" id="payment-form"> <table class="table table-striped table-inverse" id="tablaPasarela"> <thead class="thead-inverse"> <tr> <th>Imagen</th> <th>Nombre</th> <th>Cantidad</th> <th>Precio</th> <th>Total</th> </tr> </thead> <tbody> </tbody> </table> <div class="form-row"> <h4 class="mt3">Datos de su tarjeta</h4> <div id="card-element" class="form-control"> <!-- A Stripe Element will be inserted here. --> </div> <!-- Used to display form errors. --> <div id="card-errors" role="alert"></div> </div> <div class="mt-3"> <h4>Terminos y condiciones</h4> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Minima, soluta non quibusdam, assumenda mollitia expedita nihil quisquam sapiente optio rem reiciendis voluptatum laborum eos consectetur obcaecati sint incidunt doloribus placeat! Lorem, ipsum dolor sit amet consectetur (le entrego mi alrma a programamdor novato y acepto dar like) adipisicing elit. Minima, soluta non quibusdam, assumenda mollitia expedita nihil quisquam sapiente optio rem reiciendis voluptatum laborum eos consectetur obcaecati sint incidunt doloribus placeat! Lorem, ipsum dolor sit amet consectetur adipisicing elit. Minima, soluta non quibusdam, assumenda mollitia expedita nihil quisquam sapiente optio rem reiciendis voluptatum laborum eos consectetur obcaecati sint incidunt doloribus placeat! <div class="form-check"> <label class="form-check-label"> <input type="checkbox" class="form-check-input" name="" id="" value="checkedValue" checked> Acepto los terminos y condiciones </label> </div> </div> <div class="mt-3"> <a class="btn btn-warning" href="index.php?modulo=envio" role="button">Ir a envio</a> <button type="submit" class="btn btn-primary float-right">Pagar</button> </div> </form>
🎦Curso de PHP🐘 y MySql🐬: https://www.youtube.com/playlist?list=PLCTD_CpMeEKS2Dvb-WNrAuDAXObB8GzJ0
🎦[Curso] Laravel Tutorial en Español: https://www.youtube.com/playlist?list=PLCTD_CpMeEKQcVcM4u4qddLYRE37S_0XS
🎦Curso]Ajax con Jquery de 0 a 100 🌇: https://www.youtube.com/watch?v=52yI0xiB73A&list=PLCTD_CpMeEKSYJ1J15M8PknOMwOpeqsXz
🎦Mysql configurar una replicación maestro – esclavo 🐬: https://www.youtube.com/watch?v=RY-EdBOJWEs
🎦[Curso] Visual Studio Code 🆚 de 0 a 100: https://www.youtube.com/playlist?list=PLCTD_CpMeEKQbdlT8efsS-veXuvYZ1UWn
🎦[Curso] Bootstrap de 0 a 100 🌈: https://www.youtube.com/playlist?list=PLCTD_CpMeEKSVmsZJIumVvfDviuW-c9AT
🎦[Curso] HTML y CSS de 0 a 100 🌐: https://www.youtube.com/playlist?list=PLCTD_CpMeEKS1SmufBGPOV1mjNfCiLwek
🎦 Esta lista de reproducción: https://www.youtube.com/playlist?list=PLCTD_CpMeEKQhRiJx7Wv3pM3rYvT9_CS9 .
Codigos en gdrive: https://drive.google.com/file/d/1QW8ExkL8eS7nQ5HTDvUuSkkGJMSmecGV/view?usp=sharing
Gracias por apoyar este canal: https://www.patreon.com/programadornovato?fan_landing=true
🔗 Facebook: https://facebook.com/ProgramadorNovatoOficial
🔗 Twitter: https://twitter.com/programadornova
🔗 Linkedin: https://www.linkedin.com/in/programadornovato/
🔗 Instagram: https://www.instagram.com/programadornovato/
<<Anterior tutorial Siguiente tutorial >>