From e4227dd644b3393c18be8b624fc2c09444a37e37 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 27 Mar 2019 13:09:52 -0600 Subject: [PATCH] Fix bugs with sending money --- api/actions/send.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/api/actions/send.php b/api/actions/send.php index cce3b70..bc48ef9 100644 --- a/api/actions/send.php +++ b/api/actions/send.php @@ -20,9 +20,10 @@ if ($amount > $sender["balance"]) { sendJsonResp($Strings->get("Insufficient funds.", false), "ERROR"); } -if (($sender["type"] === 1 && $receiver["type"] === 2) || ($sender["type"] === 2 && $receiver["type"] === 3)) { +if (($sender["type"] == 1 && $receiver["type"] == 2) || ($sender["type"] == 2 && $receiver["type"] == 3)) { + $success = false; $database->action(function ($database) { - global $VARS, $sender, $receiver, $amount; + global $VARS, $sender, $receiver, $amount, $success; $database->update("accounts", ["balance[+]" => $amount], ["accountid" => $receiver["accountid"]]); $database->update("accounts", ["balance[-]" => $amount], ["accountid" => $sender["accountid"]]); @@ -33,9 +34,14 @@ if (($sender["type"] === 1 && $receiver["type"] === 2) || ($sender["type"] === 2 "toid" => $receiver["accountid"], "datetime" => date("Y-m-d H:i:s") ]); + $success = true; }); - sendJsonResp(); + if ($success) { + sendJsonResp(); + } else { + sendJsonResp($Strings->get("An unknown problem occurred.", false), "ERROR"); + } } else { - sendJsonResp($Strings->get("Money cannot be sent from receivers to givers.", false), "ERROR"); + sendJsonResp($Strings->get("Money must be sent from givers to receivers.", false), "ERROR"); } \ No newline at end of file