}
function test_input($data)
{
    $data = trim($data);
    // remove whitespaces and predefined chars(&lt->'<') - both ends
    $data = htmlspecialchars($data);
    // converts predefined chars and process the data and then returns.
    return $data;
}
if ($_POST && $firstnameError == "" && $lastnameError == "" && $emailError == "" && $phoneError == "") {
    require_once 'PassportPayments.php';
    $appId = "37Z8ZDAZE8N";
    $appSecret = "b2578c560673697eb49834b05a70aa1a";
    $publicKey = "37XI8CVAQSK";
    $endPoint = 'https://sandbox.passportpayments.com';
    $pp = new PassportPayments($appId, $appSecret, $publicKey, $endPoint);
    $customerAdd = $pp->saveCustomer($firstname, $lastname, $email, $phone, "");
    if ($customerAdd->status != 200) {
        echo "message: " . $customerAdd->message . "<br>";
    } else {
        header('Location: home.php');
    }
} else {
    ?>
<!DOCTYPE HTML>
<html>
<body>

<h1>Add a Customer</h1>

<form method="post" action="<?php 
    $data = trim($data);
    // remove whitespaces and predefined chars(&lt->'<') - both ends
    $data = htmlspecialchars($data);
    // converts predefined chars and process the data and then returns.
    return $data;
}
?>

<?php 
if ($_POST && $amountError == "" && $currencyError == "") {
    require_once 'PassportPayments.php';
    $appId = "37Z8ZDAZE8N";
    $appSecret = "b2578c560673697eb49834b05a70aa1a";
    $publicKey = "37XI8CVAQSK";
    $endPoint = 'https://sandbox.passportpayments.com';
    $pp = new PassportPayments($appId, $appSecret, $publicKey, $endPoint);
    $cardId = $_POST["cardId"];
    $resp = $pp->captureByCardId($cardId, $params);
    if ($resp->status != 200) {
        echo "message: " . $resp->message . "<br>";
    } else {
        header('Location: listOfTransactions.php?cdid=' . $cardId . '&cid=' . $customerId . '');
        //no status exists-no error-success
    }
} else {
    if ($_GET) {
        $cardId = $_GET["cardId"];
    } else {
        $cardId = $_POST["cardId"];
    }
    ?>
<h1>HOME PAGE</h1>

<form action= "addCustomer.php">
	<input type="submit" name="" value="Add a customer">

</form>

<h2>  List of all the customers </h2>
<?php 
//Printing all customers
require_once 'PassportPayments.php';
$appId = "37Z8ZDAZE8N";
$appSecret = "b2578c560673697eb49834b05a70aa1a";
$publicKey = "37XI8CVAQSK";
$endPoint = 'https://sandbox.passportpayments.com';
$pp = new PassportPayments($appId, $appSecret, $publicKey, $endPoint);
$customers = $pp->getAllCustomers();
//decoded, objects form
$encoded = json_encode($customers);
//encoding to further decode, string form
$decoded = json_decode($encoded, true);
//converted into associative arrays
for ($i = 0; $i < count($customers->data); $i++) {
    $val = $decoded["data"][$i]["id"];
    echo '<a href="listofCards.php?id=' . $val . '">' . $decoded["data"][$i]["firstname"] . '</a>';
    echo '<br><br>';
}
?>
</body>
</html>
}
function test_input($data)
{
    $data = trim($data);
    // remove whitespaces and predefined chars(&lt->'<') - both ends
    $data = htmlspecialchars($data);
    // converts predefined chars and process the data and then returns.
    return $data;
}
if ($_POST && $cardnumberError == "" && $expmonthError == "" && $expyearError == "" && $cvvError == "" && $nameoncardError == "") {
    require_once 'PassportPayments.php';
    $appId = "37Z8ZDAZE8N";
    $appSecret = "b2578c560673697eb49834b05a70aa1a";
    $publicKey = "37XI8CVAQSK";
    $endPoint = 'https://sandbox.passportpayments.com';
    $pp = new PassportPayments($appId, $appSecret, $publicKey, $endPoint);
    $resp = $pp->getCardToken($cardnumber, $expmonth, $expyear, $cvv, $nameoncard);
    if ($resp->status != 200) {
        echo "message:" . $resp->message . "getTokenErrorMsg" . "<br>";
    } else {
        $cardToken = $resp->data->card_tmptoken;
        $customerId = $_POST["cid"];
        $add_card = $pp->addCard($customerId, $cardToken);
        if ($add_card->status != 200) {
            echo "message: " . $add_card->message . "CardError" . "<br>";
        } else {
            header('Location: listofCards.php?id=' . $customerId . '');
        }
    }
} else {
    if ($_GET) {
<!DOCTYPE HTML>
<html>
<body>
<h1>Transactions</h1>
<?php 
require_once 'PassportPayments.php';
$appId = "37Z8ZDAZE8N";
$appSecret = "b2578c560673697eb49834b05a70aa1a";
$publicKey = "37XI8CVAQSK";
$endPoint = 'https://sandbox.passportpayments.com';
$pp = new PassportPayments($appId, $appSecret, $publicKey, $endPoint);
$cardId = $_GET["cdid"];
$customerId = $_GET["cid"];
?>

<form method="get" action= "chargeCard.php">
	<input type="submit" name="" value="Charge Card">
	<input type="hidden" name="cardId" value="<?php 
echo $cardId;
?>
">
	<input type="hidden" name="cid" value="<?php 
echo $customerId;
?>
">
</form>


<h1> List of all associated Transactions </h1>

<?php 
<!DOCTYPE HTML>
<html>
<body>
<h1>Cards</h1>
<?php 
require_once 'PassportPayments.php';
$appId = "37Z8ZDAZE8N";
$appSecret = "b2578c560673697eb49834b05a70aa1a";
$publicKey = "37XI8CVAQSK";
$endPoint = 'https://sandbox.passportpayments.com';
$pp = new PassportPayments($appId, $appSecret, $publicKey, $endPoint);
?>

<?php 
$custid = $_GET["id"];
?>



<form method="get" action= "addCard.php?">
	<input type="submit" name="" value="Add Card">
	<input type="hidden" name="cid" value="<?php 
echo $custid;
?>
">
</form>

<h2>  List of all the associated cards</h2>
<?php 
//Printing all cards
$customerId = $_GET["id"];