Add merchant transaction capability
parent
33e375299c
commit
5e0b50b473
@ -0,0 +1,27 @@
|
|||||||
|
<?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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$accountid = $database->get("accounts", ["[>]authkeys" => ["accountid"]], "accounts.accountid", ["key" => $VARS["key"]]);
|
||||||
|
|
||||||
|
$amount = $VARS["amount"] * 1.0;
|
||||||
|
|
||||||
|
if ($amount <= 0 || $amount > 999.99) {
|
||||||
|
sendJsonResp($Strings->get("Amount must be more than zero and less than 999.99.", false), "ERROR");
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
$txcode = substr(hash("sha256", random_bytes(100)), 0, 20);
|
||||||
|
} while ($database->has("merchant_transactions", ["txcode" => $txcode]));
|
||||||
|
|
||||||
|
$database->insert("merchant_transactions", ["txcode" => $txcode, "amount" => $amount, "merchantid" => $accountid]);
|
||||||
|
|
||||||
|
exitWithJson([
|
||||||
|
"status" => "OK",
|
||||||
|
"txcode" => $txcode,
|
||||||
|
"amount" => $amount
|
||||||
|
]);
|
@ -0,0 +1,22 @@
|
|||||||
|
<?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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$accountid = $database->get("accounts", ["[>]authkeys" => ["accountid"]], "accounts.accountid", ["key" => $VARS["key"]]);
|
||||||
|
|
||||||
|
if (!$database->has("merchant_transactions", ["AND" => ["txcode" => $VARS["txcode"], "merchantid" => $accountid]])) {
|
||||||
|
sendJsonResp($Strings->get("Transaction does not exist.", false), "ERROR");
|
||||||
|
}
|
||||||
|
|
||||||
|
$transaction = $database->get("merchant_transactions", ["amount", "complete", "txcode"], ["txcode" => $VARS["txcode"]]);
|
||||||
|
|
||||||
|
exitWithJson([
|
||||||
|
"status" => "OK",
|
||||||
|
"txcode" => $transaction["txcode"],
|
||||||
|
"amount" => $transaction["amount"],
|
||||||
|
"complete" => $transaction["complete"] == true
|
||||||
|
]);
|
Binary file not shown.
Loading…
Reference in New Issue