JezK
Edit File: paypal.php
<?php if(!isset($_SESSION)) session_start(); //$_POST['amount']=10; $clientID = 'AXwi3t9S-6mMvvF-94ozt0D7aBhdRPtt2Q7QldF4HXFuDTlDtjWS6Kt26I9x9BtKnEihQ5YM45Be3Dmh'; $paypalEnv = 'EJXc3Ln8U1trxTtdqrba-pnLqKim9f9lx1dGCgbvyPLrc3SK6fNPgsBPOe5EH8HUEQLLmqMo2ssGqA3y'; $type = 1; $vendor_id = 0; $show_paypal_button=''; $show_message_container='style="display:none;"'; $message_container_message='Please wait while we verify the payment.'; $show_gotoApp_button='style="display:none;"'; $show_price_container=''; $amount = $_POST['amount']; $currency = $_POST['currency']; include('../classes/class_users.php'); $users=new Users(); $checkPaymentDoneSlot=$users->checkSlotAlreadyBooked($_POST); if($checkPaymentDoneSlot){ echo "<script>alert('Sorry selected slots are aleady booked some one. Please select alternative slots');window.location='../bookAppointment.php?pid=".$users->encrypt_decrypt('encrypt',$_POST['businessid'])."';</script>"; } $show_android_goto_app_button='hide'; $show_ios_deeplink='hide'; $show_android_goto_app_button='hide'; $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $url = ($protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $url1 = explode('include',$url); //return $url1[0]; $SITE_URL = $url1[0]."paypal/"; echo $show_paypal_button; ?> <!DOCTYPE html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <!--meta name="apple-itunes-app" content="app-id=1053086749"--> <title>Video Consultation Payment</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <!-- jQuery library --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!-- Latest compiled JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <!-- Paypal javascript SDK --> <script src="https://www.paypalobjects.com/api/checkout.js"></script> </head> <body> <div style="text-align:center;"> <img src="./logo.jpeg" style="width:150px;max-width:100%;" /> <div id="price-container" <?php echo $show_price_container; ?>> <label>Total Amount:</label> <?php echo $currency ." ".$amount; ?> </div> <div id="paypal-button" <?php echo $show_paypal_button; ?>></div> <div style="display:none;"> <button type="button" onclick="verifyTransaction();">Pay Now</button> </div> <div id="message-container" <?php echo $show_message_container; ?>> <?php echo $message_container_message; ?> </div> <div id="goto-app" <?php echo $show_gotoApp_button; ?>> Goto Yayway app </div> <?php //$show_ios_deeplink=''; ?> <form name="myForm1" id="myForm1" action="Yayway://domain/gotoapp/" class="<?php echo $show_ios_deeplink; ?>" > <input type="submit" name="submit1" value="Goto App" class="btn btn-success" style="background-color: #bca912;" /> </form><br> <form name="myForm1" id="payment-success-form" action="Yayway://domain/payment_success/" class="hide" > <input type="submit" name="submit1" value="Payment Success" class="btn btn-success" /> </form><br> <form name="myForm1" id="payment-failed-form" action="Yayway://domain/payment_cancel/" class="hide" > <input type="submit" name="submit1" value="Payment Failed" class="btn btn-warning" /> </form><br> <form name="myForm1" id="payment-failed-form" action="com.charles.yayway" class="<?php echo $show_android_goto_app_button; ?>" > <input type="button" name="submit1" value="Goto APP" class="btn btn-warning" onclick="redirect_android(<?php echo $platform; ?>);" /> </form><br> </div> <script> var myglobal; var amount=<?php echo $amount; ?> ; var cclientname='<?php echo $_POST['clientName']; ?>'; var cemail='<?php echo $_POST['email']; ?>'; var cmobile='<?php echo $_POST['mobileNo']; ?>'; var ccountry_code='<?php echo $_POST['country_code']; ?>'; var cslotbooking_date='<?php echo $_POST['slotbooking_date']; ?>'; var cbusinessid='<?php echo $_POST['businessid']; ?>'; var cslotbooking='<?php echo $_POST['slotbooking']; ?>'; var currency ='<?php echo $currency;?>'; var type=<?php echo $type; ?>; var SITE_URL='<?php echo $SITE_URL; ?>'; var payment_status=false; paypal.Button.render({ env: '<?php echo "sandbox"; ?>', // Optional: specify 'sandbox' environment client: { sandbox: '<?php echo $clientID; ?>', production: '<?php echo $clientID; ?>' }, payment: function(data, actions) { return actions.payment.create({ transactions: [ { amount: { total: amount, currency: 'USD' } } ] }, { input_fields: { no_shipping: 1 } }); }, commit: true, // Optional: show a 'Pay Now' button in the checkout flow onAuthorize: function(data, actions) { // Get the payment details return actions.payment.get().then(function(paymentDetails) { // Show a confirmation using the details from paymentDetails // Then listen for a click on your confirm button console.log(paymentDetails); return actions.payment.execute().then(function() { // Show a success page to the buyer //alert("payment success."); actions.payment.get().then(function(data) { //alert('Got payment details.'); myglobal=data; if(data.state === 'approved'){ $('#message-container').show(); $('#paypal-button').hide(); var transactionId = data.transactions[0].related_resources[0].sale.id; verifyTransaction(transactionId); setInterval(function(){ verifyTransaction(transactionId); },10000); //verify payment at server //$.post(''); //alert("Transaction ID: "+ transactionId + " \n State: " +data.state); }else{ //console.log(data); } }); }); }); }, onCancel:function(){ alert('payment cancelled.'); $('#message-container').show(); $('#message-container').html('Payment cancelled.'); //$('#goto-app').show(); window.location='../bookingSucess.php?status=fail' } }, '#paypal-button'); var recheckTransaction=true; function verifyTransaction(transactionId) { if(recheckTransaction) { $.post('verifyTransaction.php',{ transactionId:transactionId, type:type, cclientname:cclientname, cemail:cemail, cmobile:cmobile, ccountry_code:ccountry_code, cslotbooking_date:cslotbooking_date, cbusinessid:cbusinessid, cslotbooking:cslotbooking, currency:currency },function(response){ console.log(response); if(response.message == 'success') { payment_status=true; recheckTransaction=false; //$('#message-container').html('Payment verified successfully.'); window.location='../bookingSucess.php?transactionid='+response.transactionID+'&status=success' } else { /*recheckTransaction=false; $('#message-container').html('Payment verification failed.'); $('#payment-failed-form')[0].submit();*/ window.location='../bookingSucess.php?status=fail' } }); } } </script> <script> function redirect_android(redirect_type){ if(payment_status) { mode="success"; } else { mode="failed"; } window.location = "../index.php?mode="+mode; } function verifyTransaction_dummy(transactionId) { $('#message-container').show(); transactionId=makeid(16); $.post('verifyTransaction.php',{ transactionId:transactionId, type:type, cart_id:cart_id, vendor_id:vendor_id },function(response){ if(response.message == 'success') { recheckTransaction=false; $('#message-container').html('Payment verified successfully.'); if(platform == 2) { location.replace('success.php') } } else if(response.message == 'failed') { recheckTransaction=false; $('#message-container').html('Payment verification failed.'); //$('#goto-app').show(); } }); } function makeid(len) { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < len; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } </script> <style> html,body{ height:100%; padding:0; margin:0; } body{ /*background: #c19a46;*/ } .hide{ display: none; } </style> </body>