0

recently i upgraded my VPS server so as to increase the ram and storage

After upgrade i noticed that my payment api started giving an error

Error: Illegal characters found in URL

Which i have never encountered before, my API which is used for processing payments has been running for years and just stopped in march after my upgraded

This is the code am using presently

<?php 
                /* $myparams = array();
                $myparams['subpdtid'] = #### ;
                $myparams['submittedref'] = $_SESSION['genref'] ;
                $myparams['submittedamt'] = $_SESSION['amt4hash'] ;
                $myparams['rettxref'] = $_POST['txnref'] ;
                $myparams['retpayRef'] = $_POST['payRef'] ;
                $myparams['retretref'] = $_POST['retRef'] ;
                $myparams['retcardnum'] = $_POST['cardNum'] ;
                $myparams['retappramt'] = $_POST['apprAmt'] ;
                $myparams['nhash'] = '########################################################################' ;
                 */


                $subpdtid = ####; // your product ID
                $submittedref = $_POST['tnx_ref']; // unique ref I generated for the trans
                $submittedamt = $_POST['amount'];
                //$rettxref= $_POST['txnref']; // ref from isw
                //$retpayRef=$_POST['payRef'];  // pay ref from isw
                //$retretref = $_POST['retRef'];  // ret ref from isw
                //$retcardnum = $_POST['cardNum'];  // ret cardnum from isw
                //$retappramt = $_POST['apprAmt'];  // ret appr amt from isw

    $nhash = "04F61D7F7EEE6C80E5D227CA6DAAEA878F46C47B67A9DC7A5A699AD2D13A6249187E85667709F0D978D6697E33817DC771FBA109110ADAD1C4E642D20D439BC2" ; // the mac key sent to you
    $hashv = $subpdtid.$submittedref.$nhash;  // concatenate the strings for hash again
    $thash = hash('sha512',$hashv);
// $credentials = "mithun:mithun";

     $parami = array(
        "productid"=>$subpdtid,
        "transactionreference"=>$submittedref,
        "amount"=>$submittedamt
        ); 
    $ponmo = http_build_query($parami) . "\n";

        //$url = "https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.xml?$ponmo";// xml
        $url = "https://webpay.interswitchng.com/paydirect/api/v1/gettransaction.json?$ponmo"; // json

        //note the variables appended to the url as get values for these parameters
        $headers = array(
        "GET /HTTP/1.1",
        "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1",
        //"Content-type:  multipart/form-data",
        //"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
        "Accept-Language: en-us,en;q=0.5",
        //"Accept-Encoding: gzip,deflate",
        //"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
        "Keep-Alive: 300",      
        "Connection: keep-alive",
        //"Hash:$thash",
        "Hash: $thash " );
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,120);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER ,false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 120);     


        $data = curl_exec($ch); 

 if (curl_errno($ch)) { 
  print "Error: " . curl_error($ch);
    }
 else {  
 // Show me the result
 // $json = simplexml_load_string($data);
    $json = json_decode($data, TRUE);
 //var_dump($data);
 curl_close($ch);
 print_r($json);
 //echo ($json['ResponseCode']);  
 //echo ($json['ResponseDescription']);
 // loop through the array nicely for your UI
  }?>
<?php session_start(); 
//if(isset($_POST['name'])){
    //$amt1 =  htmlspecialchars(mysql_real_escape_string($_POST['amount'])) * 100 ;
    $desc = $json['ResponseDescription'];
    $_SESSION['desc'] =  $desc;
    $rep = $json['ResponseCode'];
    $_SESSION['rep'] =  $rep;
    $tref = $_POST['tnx_ref']; 
    $_SESSION['tref'] =  $tref;
    $amts = $_POST['amount'] /100; 
    $_SESSION['amount'] =  $amts;



//}
?>



      <?php echo ($json['ResponseCode']); ?> 
                            <?php echo ($json ->ResponseDescription);?><div align ="center"><h2 style="color:#090" align="center"> <?php echo ($json['ResponseDescription'] ); ?> </h2><br /><img src="wait.gif" width="200"  /><div align ="center"><form action="query.php" method="post" name="niid" id="niid"></form><br /></div>
        <script type="text/javascript"> 

   window.onload=function(){ 
    window.setTimeout(function() { document.niid.submit(); }, 3000);
};

</script>

                <?php } else {?>
<div align ="center"><h2 style="color:#F00" align="center"> Your Transaction Was Not Successfull<br />Reason: <?php echo ($json['ResponseDescription'] ); ?></h2><br /><img src="wait.gif" width="200"  /></div>

Please can anyone enlighten me?

1 Answer 1

1

It is because you are appending unwanted \n after string

change your code to

 $ponmo = http_build_query($parami);

        //$url = "https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.xml?$ponmo";// xml
        $url = "https://webpay.interswitchng.com/paydirect/api/v1/gettransaction.json?$ponmo"; // json
Sign up to request clarification or add additional context in comments.

1 Comment

thanks bro, good to learn from guys like u, i will like ur answer in a minute

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.