0

Here is my payment page upon success it should be storing results into db through process_payment.php but it is just not inserting anything into databse and straight away shows me the succ page

here is process_payment.php

`       <?php
        //connect the database
        include("includes/config.php");
         
        //get the payment details from payment page
         
        if(isset($_POST['payment_id']) && isset($_POST['amount']) && isset($_POST['name']))
        {
            $paymentId = $_POST['payment_id'];
            $amount = $_POST['amount'];
            $name = $_POST['name'];
         
            //insert data into database
            $sql="INSERT INTO razorpay_payment (name,amount,payment_status,payment_id)VALUES('$name','$amount','paid','$paymentId')";
            $stmt=$db->prepare($sql);
            $stmt->execute();
        }
        ?>`

and here is the payment page

    <script type="text/javascript">
        function pay_now(){
              //get the input from the form
              var name = $("#payee_name").val();
              var amount = $("#amount").val();
              var actual_amount = amount*100;
              var description = $('#description').val();
              //var actual_amount = amount;
              var options = {
                "key": "rzp_test_dgsdfgsdfgsdg", // Enter the Key ID generated from the Dashboard
                "amount": actual_amount, // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
                "currency": "INR",
                "name": name,
                "description": description,
                "image": "razorpay.png",
                "payment_id": "order_IluGWxBm9U8zJ8", //This is a sample Order ID. Pass the `id` obtained in the response of Step 1
                "handler": function (response){
                    console.log(response);
                    $.ajax({
     
                        url: 'process_payment.php',
                        'type': 'POST',
                        'data': {'payment_id':response.razorpay_payment_id,'amount':actual_amount,'name':name},
                        success:function(data){
                            console.log(data);
                          window.location.href = 'thank_you.php';
                        }
     
                    });
                    // alert(response.razorpay_payment_id);
                    // alert(response.razorpay_order_id);
                    // alert(response.razorpay_signature)
                },
                 
            };
            var rzp1 = new Razorpay(options);
            rzp1.on('payment.failed', function (response){
                    alert(response.error.code);
                    alert(response.error.description);
                    alert(response.error.source);
                    alert(response.error.step);
                    alert(response.error.reason);
                    alert(response.error.metadata.order_id);
                    alert(response.error.metadata.payment_id);
            });
            document.getElementById('rzp-button1').onclick = function(e){
                rzp1.open();
                e.preventDefault();
            }
        }
    </script>
    

can someone help me out please

already posted above

Tanya
  • 21
  • 4
  • 1
    Your PHP is wide open to SQL injection because of the POST variables used directly in the SQL rather than a `prepared statement`... can you explain what you see in the console for the AJAX request (network) - does the request get made, does it contain suitable values for data parameters? Have you added `echo` statements in the PHP to debug where the script fails? – Professor Abronsius Apr 30 '23 at 07:18
  • 1
    You have `'type': 'POST'` whereas it should be `'method': 'POST'`. – KIKO Software Apr 30 '23 at 07:18
  • @KIKOSoftware still not inserting anything – Tanya Apr 30 '23 at 08:09
  • Please follow the link shown in the reason your question was closed. The answers there can help you. – KIKO Software Apr 30 '23 at 08:15
  • 1
    Are you planning to do any useful debugging, as per the first comment? That's the way to solve it – ADyson Apr 30 '23 at 08:40
  • @ADyson I am not very good at debugging I need guidance – Tanya Apr 30 '23 at 16:17
  • https://www.google.com/amp/s/www.atatus.com/blog/php-debugging/amp/ – ADyson Apr 30 '23 at 18:56
  • https://phpdelusions.net/basic_principles_of_web_programming#debugging – ADyson Apr 30 '23 at 18:57
  • 1
    And there are no doubt many more guides online too, for php and also for javascript. Make sure you learn how to use your browser's Developer Tools too. Debugging is a vital skill, you need to gain some experience with it. Otherwise you'll always just be guessing and relying on others to help you – ADyson Apr 30 '23 at 18:57

0 Answers0