Flutterwave payment API integration with PHP and Mysql

476 Views Asked by At

How do I update mysql db payment status from pending to success in the flutterwave api please find the code snippet below. the db connection is included from a controller.php file

<php?

if($amountPaid >= $amountToPay) {

                echo 'Payment successful';

                //* Continue to give item to the user
                $res = json_decode($response);
                $array= json_decode($response,true);
               
            $payment_id = $array["data"]["id"];
            $transaction_amount = $array["data"]["amount"];
            $payment_status = $array["status"];
            $tx_ref = $array["data"]["tx_ref"];
            
      
            $query3 = "UPDATE transaction_details SET payment_id=$payment_id , payment_status= 
            $payment_status WHERE tx_ref=$tx_ref";
            

            if ($conn->query($query3) === TRUE) {
              echo "Record updated successfully";
            } else {
              echo "Error updating record: " . $conn->error;
            }
            
            $conn->close();
                
     
                
             
                 header('location: congratulations.php');
             }  else {
                echo 'unusual transaction detected';
            }
          
    }else
    {
        echo 'Can not process payment';
    }
}

} ?>

1

There are 1 best solutions below

0
On

Ok thanks everyone just figured it out . Had the problem because I sort of mixed up my coding styles using OOP and procedural in same codelines. solved it by using mysqli procedural prepared statement. This helped me to bind the variables to mysql db fields