<?php
    if(isset($_POST['banks'])){
        $banks = $_POST['banks'];
        $account_num = $_POST['account_num'];
        
        
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://api.paystack.co/bank/resolve?account_number=".rawurlencode($account_num)."&bank_code=".rawurlencode($banks),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => array(
            "Authorization: Bearer sk_live_d3ab9a7f934cb3c400ca40ac602f72255f8655eb",
            "Cache-Control: no-cache",
            ),
        ));
        
        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        if ($err) {
            echo "cURL Error #:" . $err;
        }else{
            $result = json_decode($response);
            $verify = $result->status;
        }
    
        if($verify){
            $name = $result->data->account_name;
            
            echo '
            <div class="col-md-6 form-group">
            <label>Account Name</label>
                <input type="text" name="" value="'.$name.'" class="form-control" readonly>
            </div>
            <div class="col-md-6"></div>
            <div class="col-md-12">
            <form action="" method="post">
            <input type="hidden" name="account_name" value="'.$name.'">
            <input type="hidden" name="account_number" value="'.$account_num.'">
            <input type="hidden" name="bankcode" value="'.$banks.'">
            <div class="alert alert-success" style="font-weight: bold;"><em class="icon ni ni-check-circle-fill"></em>Account Number Verified</div>
            <div class="form-group">
                <button type="submit" name="sub_acct" class="btn btn-lg btn-primary">Update Bank Details</button>
            </div>
            </div>
            
            </form>';
                            
        }else{
            echo '<div class="alert alert-danger" style="font-weight: bold;"><em class="icon ni ni-shield-star-fill"></em>Invalid Account Number</div>';
                            
        }
}

?>

