get("accounts", ["[>]authkeys" => "accountid"], ["accounts.accountid", "balance", "type"], ["authkeys.key" => $VARS["key"]]); $amount = $VARS["amount"] * 1.0; if (!$database->has("accounts", ["publicid" => $VARS["to"]])) { if (!$database->has("merchant_transactions", ["txcode" => $VARS["to"]])) { sendJsonResp($Strings->get("Could not find the receiving account.", false), "ERROR"); } else { $receiver = $database->get("accounts", ["[>]merchant_transactions" => ["accountid" => "merchantid"]], ["accounts.accountid", "accounts.balance", "accounts.type", "merchant_transactions.amount", "merchant_transactions.complete"], ["txcode" => $VARS["to"]]); if ($receiver["complete"] == true) { sendJsonResp($Strings->get("The transaction has already been completed.", false), "ERROR"); } if ($amount != $receiver["amount"]) { sendJsonResp($Strings->get("You must send the exact amount shown ($receiver[amount]).", false), "ERROR"); } } } else { $receiver = $database->get("accounts", ["accountid", "balance", "type"], ["publicid" => $VARS["to"]]); } if ($amount > $sender["balance"]) { sendJsonResp($Strings->get("Insufficient funds.", false), "ERROR"); } if (($sender["type"] == 1 && $receiver["type"] == 2) || ($sender["type"] == 2 && $receiver["type"] == 3)) { $success = false; $database->action(function ($database) { global $VARS, $sender, $receiver, $amount, $success; $database->update("accounts", ["balance[+]" => $amount], ["accountid" => $receiver["accountid"]]); $database->update("accounts", ["balance[-]" => $amount], ["accountid" => $sender["accountid"]]); $database->insert("transactions", [ "amount" => $amount, "fromid" => $sender["accountid"], "toid" => $receiver["accountid"], "datetime" => date("Y-m-d H:i:s") ]); if ($receiver["type"] == 3) { $database->update("merchant_transactions", ["complete" => true], ["txcode" => $VARS["to"]]); } $success = true; }); if ($success) { sendJsonResp(); } else { sendJsonResp($Strings->get("An unknown problem occurred.", false), "ERROR"); } } else { sendJsonResp($Strings->get("Money must be sent from givers to receivers.", false), "ERROR"); }