简体   繁体   中英

Flutterwave payment API integration with PHP and Mysql

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';
    }
}

}?>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM