0

Hye developers, I'm designing a payment gateway that will authenticate user card details, I want redirect user to a page if its correct and payment is successful, I'm using

  <?php

require_once 'wallet.class.php';
$class = new wallet('mysql:host=127.0.0.1;dbname=pooldb', "root", ""); // change the host and database to the host server




// making payment 
if(isset($_REQUEST["amount"])){

$card = [
  "card_no" => $_REQUEST["cardNO"],
  "cvv" => $_REQUEST["cvc"],
  "expiry_month" => $_REQUEST["month"],
  "expiry_year" => $_REQUEST["year"]
];

$info = [
    "id" => 1, // Login in user
    "amount" => $_REQUEST["amount"], // amount
    "url" => "http://payment.php" // response URL
];

$token = $class->Tokenize($_REQUEST["auth"], $card, $_REQUEST["bvn"]);

if($token == "Token True"){
    $payment = $class->Payment($card, $info);

    if($payment == "Paid True"){
        $class->CheckUser_AndSave($info["id"], $info["amount"]);

        header("Location:upload.php");
        exit();
    }
    else if($payment == "Paid False"){
        // make an action to dispaly and input box and button for OTP 
        echo "Paid False";
        $_SESSION['mssage'] = $class->message;
    }
    else{
        echo $payment; // error message
    }
}
else{
    echo "Your card was not tokenize. Try agin.";
}
}

 // doing OTP action here
elseif (isset ($_REQUEST["otp"])) { // Send entered OTP here
$info = [
    "id" => 1, // Login in user
    "amount" => $_REQUEST["amount"], // amount
];

$otp = $class->OTP($_REQUEST["otp"]);

if($otp == "OTP True"){
    $class->CheckUser_AndSave($info["id"], $info["amount"]);
}
else{
    echo "Something went wrong.";
}
}

but instead of redirecting to upload page, it only display it below the current page and everything is stretch, please I need help

benyusouf
  • 325
  • 2
  • 6
  • 17

2 Answers2

0

You should probably redirect and exit like the following,

if($payment == "Paid True"){
    $class->CheckUser_AndSave($info["id"], $info["amount"]);
    header("Location:upload.php");
    exit();
}

Also make sure you haven't echoed/printed anything before this line.

Saravanan Sampathkumar
  • 3,201
  • 1
  • 20
  • 46
0

use javascript to redirect as Japanguy suggest, it now works

if($payment == "Paid True"){
        $class->CheckUser_AndSave($info["id"], $info["amount"]);

        echo "<script>
            window.location.href='upload.php';
        </script>";
    }
benyusouf
  • 325
  • 2
  • 6
  • 17