function createTransaction($sender, $recipient, $amount, $description, $tan)
{
    $return = returnValue();
    //if (gettype($recipient) != "integer" && gettype($recipient) != "double") {
    //Whitelisting recipient
    if (!is_numeric($recipient)) {
        $return->value = false;
        $return->msg = "Invalid recipient";
        return $return;
    }
    if ($recipient == $sender) {
        $return->value = false;
        $return->msg = "Recipient account must be different from sender.";
        return $return;
    }
    //Whitelisting amount
    if (!is_numeric($amount) || $amount < 1 || $amount > PHP_INT_MAX) {
        $return->value = false;
        $return->msg = "Amount must be a number greater than zero but less than PHP_INT_MAX";
        return $return;
    }
    //Whitelisting TAN
    if (empty($tan) or preg_match('/[^A-Za-z0-9]/', $tan)) {
        $return->value = false;
        $return->msg = "Invalid TAN";
        return $return;
    }
    //Whitelisting Description
    if (preg_match('/[^A-Za-z0-9\'\\.\\/\\, ]/', $description)) {
        $return->value = false;
        $return->msg = 'Description may only contain letters, digits, and the special characters ".", ",", and "/"';
        return $return;
    }
    $recipientAccount = selectAccountByNumber($recipient);
    if (!$recipientAccount) {
        $return->value = false;
        $return->msg = "Recipient account not found";
        return $return;
    }
    $senderAccount = selectAccountByNumber($sender);
    if ($senderAccount->BALANCE < $amount) {
        $return->value = false;
        $return->msg = "Insufficient funds";
        return $return;
    }
    validateSCSTAN($tan);
    $tanEntry = selectTanByTan($tan);
    if (!$tanEntry) {
        $return->value = false;
        $return->msg = "Invalid TAN";
        return $return;
    }
    // check if TAN is in db
    if ($tanEntry->CLIENT_ACCOUNT !== $senderAccount->ID || $tanEntry->STATUS !== "V") {
        $return->value = false;
        $return->msg = "TAN Used or not valid";
        return $return;
    }
    $invalidateTan = updateTanStatus($tanEntry->ID);
    if (!$invalidateTan) {
        $return->value = false;
        $return->msg = "Tan update failed";
        return $return;
    }
    $insert = insertTransaction($senderAccount->ID, $recipientAccount->ID, $amount, $description, $tanEntry->ID);
    if (!$insert) {
        $return->value = false;
        $return->msg = "Transaction failed";
        return $return;
    }
    if ($amount <= 10000) {
        $balance = updateBalance($senderAccount->ID, $recipientAccount->ID, $amount);
        if (!$balance) {
            $return->value = false;
            $return->msg = "Error updating balance";
            return $return;
        }
    }
    $return->value = true;
    $return->msg = "Transaction successful";
    return $return;
}
 function insertBuyTransaction($data)
 {
     $cardpack = new SimpleXMLElement($data);
     $datetime = $cardpack->certificate[0]->datetime;
     $player = $cardpack->certificate[0]->player;
     insertTransaction($datetime, $player, 'x', 'buy');
 }
Exemple #3
0
    while ($row = $result->fetch_assoc()) {
        $code = $row["code"];
        $name = $row["name"];
        array_push($jsonArray["name"], $name);
        array_push($jsonArray["code"], $code);
    }
    echo json_encode($jsonArray);
}
if ($_GET && $_GET["requestMethod"]) {
    $requestMethod = trim($_GET["requestMethod"]);
    if ($requestMethod == "findTeacher") {
        findTeacher();
    } else {
        if ($requestMethod == "insertParentAndChild") {
            $childId = insertParentAndChild($conn, $appid, $secret);
            echo insertTransaction($conn, $childId);
        } else {
            if ($requestMethod == "teacherDetails") {
                getTeacherDetails($conn);
            } else {
                if ($requestMethod == "updateParentMobile") {
                    updateParentMobile($conn, $yunpian);
                } else {
                    if ($requestMethod == "myRecord") {
                        getMyRecord($conn);
                    } else {
                        if ($requestMethod == "cancelTransaction") {
                            cancelTransaction($conn);
                        } else {
                            if ($requestMethod == "parseCodeForDisplay") {
                                parseCodeForDisplay($conn);