Add profile fetch and money sending APIs
parent
dfae57bc01
commit
073fcbad58
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
if (!$database->has("accounts", ["publicid" => $VARS["id"]])) {
|
||||
sendJsonResp($Strings->get("Could not find a matching account.", false), "ERROR");
|
||||
}
|
||||
|
||||
$profile = $database->get("accounts", ["publicid", "name", "username", "type", "verified"], ["publicid" => $VARS["id"]]);
|
||||
|
||||
// Make sure the name field always has something useful
|
||||
if (empty($profile["name"])) {
|
||||
$profile["name"] = $profile["username"];
|
||||
}
|
||||
|
||||
$profile["verified"] = $profile["verified"] == 1;
|
||||
|
||||
exitWithJson([
|
||||
"status" => "OK",
|
||||
"profile" => $profile
|
||||
]);
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
$sender = $database->get("accounts", ["[>]authkeys" => "accountid"], ["accounts.accountid", "balance", "type"], ["authkeys.key" => $VARS["key"]]);
|
||||
|
||||
if (!$database->has("accounts", ["publicid" => $VARS["to"]])) {
|
||||
sendJsonResp($Strings->get("Could not find the receiving account.", false), "ERROR");
|
||||
}
|
||||
|
||||
$receiver = $database->get("accounts", ["accountid", "balance", "type"], ["publicid" => $VARS["to"]]);
|
||||
|
||||
$amount = $VARS["amount"] * 1.0;
|
||||
|
||||
if ($amount > $sender["balance"]) {
|
||||
sendJsonResp($Strings->get("Insufficient funds.", false), "ERROR");
|
||||
}
|
||||
|
||||
if (($sender["type"] === 1 && $receiver["type"] === 2) || ($sender["type"] === 2 && $receiver["type"] === 3)) {
|
||||
$database->action(function ($database) {
|
||||
global $VARS, $sender, $receiver, $amount;
|
||||
|
||||
$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")
|
||||
]);
|
||||
});
|
||||
|
||||
sendJsonResp();
|
||||
} else {
|
||||
sendJsonResp($Strings->get("Money cannot be sent from receivers to givers.", false), "ERROR");
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue