wallet cleanup

This commit is contained in:
CHIEFSOFT\ameye
2023-07-27 04:44:02 -04:00
parent d8b8a615a8
commit 2bde1c928c
2 changed files with 49 additions and 12 deletions
+3 -3
View File
@@ -964,14 +964,14 @@ Foreign-key constraints:
REQ_STRING (in, "code", 4, 5, "(.*)");
REQ_LONG( in, "dir", 1, -1 );
REQ_LONG( in, "sendmoney_id", 1, -1 );
REQ_LONG( in, "wallet_id", 1, -1 );
CVars vw;
vw["currency"] = "NAIRA"; // this might become a variable based on the country
vw["currency"].set_valid( true );
long wallet_id = CheckWallet(in["member_id"].Long(),vw);
long retDb = load_db_record( out, "SELECT balance AS curr_balance FROM members WHERE id = %lu", in["member_id"].Long());
long retDb = load_db_record( out, "SELECT amount AS new_balance FROM members_wallet WHERE id = %lu AND member_id = %lu",wallet_id, in["member_id"].Long());
if (retDb)
{ in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true ); // get this one LIVE
+46 -9
View File
@@ -291,7 +291,10 @@ long do_transferPayment(CVars in) {
long amount = 0;
long fee = 0;
long total = 0;
long wallet_id = 0;
REQ_STRING(in, "wallet_uid", 3, 150, "(.*)");
REQ_STRING(in, "terminating_country_code", 2, 2, "(.*)");
/*
CREATE TABLE sendmoney_payment
@@ -315,12 +318,34 @@ long do_transferPayment(CVars in) {
throw new bad_parameter(out, "senderid");
}
if (payMode == PAYMENT_MODE) {
amount = REQ_LONG(in, "amount", 1, -1);
fee = REQ_LONG(in, "fee", 1, -1);
total = amount + fee; // make sure you are cent here
if (out["balance"].Long() >= total) // do you have this money
CVars wl;
if ( load_db_record(wl, "SELECT w.*,c.country,w.amount,w.id AS wallet_id from members_wallet w LEFT join currency c ON c.code=w.currency"
" WHERE c.country='%s' AND w.member_id=%lu AND w.uid='%s' ",in["terminating_country_code"].c_str(), in["member_id"].Long(),in["wallet_uid"].c_str())> 0){
if ( LongTotalCost > wl["amount"].Long() )
{
out["status_message"] = "insufficient_balance_error";
out["status_text"] = "insufficient balance for transaction";
return ret;
}
wallet_id = wl["wallet_id"].Long();
}
else
{
out["status_message"] = "wallet_not_found_error";
throw new bad_parameter(out, "senderid");
// return ret;
}
if (wl["amount"].Long() >= total && wallet_id > 0) // do you have this money
{
CVars x;
x["transfer_mode"] = PAYMENT_MODE;
@@ -335,7 +360,7 @@ long do_transferPayment(CVars in) {
x["fee"].set_valid(true);
x["total"] = total;
x["total"].set_valid(true);
x["current_balance"] = out["balance"];
x["current_balance"] = wl["amount"];
x["current_balance"].set_valid(true);
payment_id = 0;
@@ -357,12 +382,15 @@ long do_transferPayment(CVars in) {
y["code"].set_valid(true);
y["dir"] = DIR_TARGET;
y["dir"].set_valid(true);
y["wallet_id"] = wallet_id;
y["wallet_id"].set_valid(true);
//y["payment_id"] = out["payment_id"]; y["payment_id"].set_valid( true );
ret = WrenchSendMoneyPayment(y, out);
if (ret == PHP_CREATED_OK) {
load_db_record(out, "SELECT balance AS new_balance FROM members WHERE id = %lu", customer_id);
load_db_record(out, "SELECT amount AS new_balance FROM members_wallet WHERE id = %lu", wallet_id);
pgsql_exec("UPDATE sendmoney_payment SET new_balance=%lu WHERE id=%lu", out["new_balance"].Long(), out["payment_id"].Long());
ret = PHP_API_OK;
}
@@ -448,10 +476,11 @@ long WRB_doServiceTransferComplete(CVars in, CVars &out) {
CVars wl;
if ( load_db_record(wl, "SELECT w.*,c.country,w.amount from members_wallet w LEFT join currency c ON c.code=w.currency"
" WHERE c.country='%s' AND w.member_id=%lu AND w.uid='%s' ",in["TerminatingCountryCode"].c_str(), in["member_id"].Long(),in["wallet_uid"].c_str())> 0){
if (in["amount"].Long() > wl["amount"].Long() )
{ out["status_message"] = "insufficient_balance_error";
out["status_text"] = "insufficient balance for transaction";
return ret;
if ( LongTotalCost > wl["amount"].Long() )
{
out["status_message"] = "insufficient_balance_error";
out["status_text"] = "insufficient balance for transaction";
return ret;
}
}
else
@@ -583,13 +612,17 @@ long WRB_doServiceTransferComplete(CVars in, CVars &out) {
pm["fee"].set_valid(true);
pm["mode"] = PAYMENT_MODE;
pm["mode"].set_valid(true);
pm["wallet_uid"] in["wallet_uid"];
pm["wallet_uid"].set_valid(true);
pm["terminating_country_code"] in["TerminatingCountryCode"];
pm["terminating_country_code"].set_valid(true);
/*
#define SM_PENDING 1
#define SM_CANCEL 3
#define SM_FAILED 4
#define SM_COMPLETED 5
*/
// REQ_STRING(in, "wallet_uid", 3, 150, "(.*)"); make sure we align the wallet
if (do_transferPayment(pm) == PHP_API_OK) {
out["sendmoney_status"] = SM_PENDING;
in["sendmoney_id"] = out["money_transfer_id"];
@@ -602,7 +635,11 @@ long WRB_doServiceTransferComplete(CVars in, CVars &out) {
throw new runtime_error("Failed to create payment record");
}
load_db_record(out, "SELECT r.firstname, r.lastname, m.*,mp.confirmation,r.firstname||' '||r.lastname AS Recitient,r.account_no,b.name AS bank_name FROM money_transfer m LEFT JOIN members_payments mp ON mp.what_sendmoney = m.id LEFT JOIN sendmoney_recipient r ON r.id = m.recipientid LEFT JOIN bank_entity_codes b ON b.code = r.bank_code WHERE m.id=%lu", out["money_transfer_id"].Long());
load_db_record(out, "SELECT r.firstname, r.lastname, m.*,mp.confirmation,r.firstname||' '||r.lastname AS Recitient,"
" r.account_no,b.name AS bank_name FROM money_transfer m "
" LEFT JOIN members_payments mp ON mp.what_sendmoney = m.id "
" LEFT JOIN sendmoney_recipient r ON r.id = m.recipientid "
" LEFT JOIN bank_entity_codes b ON b.code = r.bank_code WHERE m.id=%lu", out["money_transfer_id"].Long());
} catch (runtime_error& ex) {