This commit is contained in:
2022-03-07 14:00:36 -05:00
parent b0747071e9
commit b9de6b4a98
5 changed files with 105 additions and 19 deletions
+1
View File
@@ -13,6 +13,7 @@ long WrenchCanceContractPayment( CVars in, CVars &out );
long WrenchNewCardPayment( CVars in, CVars &out );
long WrenchCardRechargePayment( CVars in, CVars &out );
long CheckWallet(long member_id,CVars in);
long DeductMemberWallet(long member_id,long wallet_id,long amount, long payment_id);
#endif
+1 -1
View File
@@ -172,7 +172,7 @@ enum { PARTNER_STRIPE };
#define WRENCHBOARD_ACCOUNT_WALLETS 11060
#define WRENCHBOARD_USER_DELETEACC 11990
#define WRENCHBOARD_ACCOUNT_END 11999
//**************************************************************
#define WRENCHBOARD_GROUP_START 12000
+58 -1
View File
@@ -111,6 +111,7 @@ created timestamp without time zone DEFAULT now()
long WrenchBoardMobileSendMoney(CVars in, CVars &out);
long WrenchBoardMobileSendJobInterest(CVars in, CVars &out);
long WrenchReturnPendingJobList(CVars in, CVars &out);
long WrenchBoardMobileSendUserWallet(CVars in, CVars &out);
long test() {
FILE* oldFile = Output2FILE::Stream();
@@ -317,7 +318,20 @@ test();
break;
case WRENCHBOARD_ACCOUNT_WALLETS:
logfmt(logINFO, "/account_calls()");
logfmt(logINFO, "/account_calls()");
return WrenchBoardMobileSendUserWallet(in, out);
break;
case WRENCHBOARD_USER_DELETEACC:
REQ_LONG(in, "member_id", 1, -1);
REQ_STRING(in, "reason", 2, 149, "(.*)");
CVars xx;
xx["member_id"] = in["member_id"]; xx["member_id"].set_valid(true);
xx["reason"] = in["reason"]; xx["reason"].set_valid(true);
out["delete_id"] = insert_db_record(DBS_VALID, "members_delete", "members_delete_id_seq", xx);
/*
DO THE DELETE HERE NOW
*/
break;
}
@@ -327,6 +341,42 @@ test();
#define PHP_API_TRANSFER_COMPLETE 200
long WrenchBoardMobileSendUserWallet(CVars in, CVars &out) {
logfmt(logINFO, "WrenchBoardMobileSendUserWallet()");
char vname[30];
long ret = PHP_API_BAD_PARAM;
try {
REQ_LONG(in, "member_id", 1, -1);
out["total_record"] = "0";
const PGresult *res;
res = pgsql_query(" SELECT * FROM members_wallet WHERE member_id = %lu", in["member_id"].Long());
if (res != NULL && pgsql_num_rows(res) > 0) {
out["total_record"] = pgsql_num_rows(res);
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
if (f.empty()) continue;
CVars rec;
map_to_cvars(f, rec);
snprintf(vname, sizeof (vname), "amount_%05d", i);
out[vname] = rec["amount"];
snprintf(vname, sizeof (vname), "currency_%05d", i);
out[vname] = rec["currency"];
}
}
ret = PHP_API_OK;
out["status"] = "OK";
} catch (bad_parameter) {
logfmt(logINFO, "ERROR CALL long WrenchBoardMobileSendUserWallet(CVars in, CVars &out)");
}
logfmt(logINFO, "/WrenchReturnPendingJobList()");
return ret;
}
long WrenchBoardMobileSendJobInterest(CVars in, CVars &out) {
long ret = PHP_API_BAD_PARAM;
try {
@@ -1162,6 +1212,13 @@ long LoginWrenchBoardAccount(CVars in, CVars &out) {
ret = load_db_record(out, "SELECT *,id AS member_id , to_char(last_login, 'Day Mon dd, yyyy HH:MI AM') AS last_login2 FROM members WHERE status=1 AND LOWER(username)=LOWER('%s') AND password= md5('%s')", in["username"].c_str(), in["password"].c_str());
if (ret) {
CVars vw;
vw["currency"] = "NAIRA"; // this might become a variable based on the country
vw["currency"].set_valid( true );
long wallet_id = CheckWallet(out["member_id"].Long(),vw);
load_db_record( out, "SELECT amount AS balance FROM members_wallet WHERE member_id = %lu AND currency='%s' ", out["member_id"].Long(), vw["currency"].c_str());
pgsql_exec("DELETE FROM members_session WHERE member_id=%ld ", out["member_id"].Long());
// remove all existing session
+39 -13
View File
@@ -71,6 +71,27 @@ if ( load_db_record( y, "SELECT * FROM members_wallet WHERE id = %lu AND member_
return 1;
}
long DeductMemberWallet(long member_id,long wallet_id,long amount, long payment_id){
logfmt(FLOG_MAX, "DeductMemberWallet ************************" );
logfmt(FLOG_MAX, "Review this design so as not to loose money ");
logfmt(FLOG_MAX, "DeductMemberWallet ************************" );
CVars y;
if ( load_db_record( y, "SELECT * FROM members_wallet WHERE id = %lu AND member_id =%lu", wallet_id,member_id ) > 0 )
{
CVars x;
x["member_id"] = member_id; x["member_id"].set_valid( true ); //
x["payment_id"] = payment_id; x["payment_id"].set_valid( true ); //
x["amount"] = amount; x["amount"].set_valid( true ); //
x["balance"] = y["amount"]; x["balance"].set_valid( true ); //
insert_db_record( DBS_VALID, "members_wallet_detail", "members_wallet_detail_id_seq", x );
pgsql_exec("UPDATE members_wallet SET amount=amount - %lu,prev_amount=%lu WHERE member_id = %lu AND id=%lu",amount,y["amount"].Long(),member_id , wallet_id); // pay attention to who you pay here
}
return 1;
}
long WrenchNewCardPayment( CVars in, CVars &out )
{
long payment_return = 0; // just return 0 if not okay , payment_id is all okay
@@ -362,7 +383,11 @@ Foreign-key constraints:
REQ_LONG( in, "dir", 1, -1 );
REQ_LONG( in, "offer_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());
@@ -413,7 +438,8 @@ Foreign-key constraints:
ret = PHP_CREATED_OK;
x["flags"] = FLAG_START; x["flags"].set_valid( true ); // done not completed yet
// now generate the confirmation
pgsql_exec("UPDATE members SET balance=balance - %lu WHERE id = %lu",in["amount"].Long() + in["fee"].Long(),in["member_id"].Long() );
pgsql_exec("UPDATE members SET balance=balance - %lu WHERE id = %lu",in["amount"].Long() + in["fee"].Long(),in["member_id"].Long() );
DeductMemberWallet(in["member_id"].Long(), wallet_id,in["amount"].Long(), payment_id);
char confirmation[15] = "";
Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call
x["flags"] = FLAG_OK; x["flags"].set_valid( true );
@@ -658,6 +684,11 @@ Foreign-key constraints:
REQ_LONG( in, "dir", 1, -1 );
REQ_LONG( in, "sendmoney_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());
@@ -715,27 +746,22 @@ Foreign-key constraints:
out["status"] = "Failure to create";
return PHP_API_BAD_PARAM;
}
out["payment_id"] = payment_id; out["payment_id"].set_valid( true );
if (payment_id) {
ret = PHP_CREATED_OK;
x["flags"] = FLAG_START; x["flags"].set_valid( true ); // done not completed yet
// now generate the confirmation
pgsql_exec("UPDATE members SET balance=balance - %lu WHERE id = %lu",in["amount"].Long() + in["fee"].Long(),in["member_id"].Long() );
//pgsql_exec("UPDATE members SET balance=balance - %lu WHERE id = %lu",in["amount"].Long() + in["fee"].Long(),in["member_id"].Long() );
DeductMemberWallet(in["member_id"].Long(), wallet_id,in["amount"].Long() + in["fee"].Long(), payment_id);
char confirmation[15] = "";
Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call
x["flags"] = FLAG_OK; x["flags"].set_valid( true );
x["payment_id"] = payment_id; x["payment_id"].set_valid( true );
pgsql_exec("UPDATE members_payments SET flags = %lu WHERE id = %lu",x["flags"].Long(),payment_id );
load_db_record( out, "SELECT * FROM members_payments WHERE id = %lu ", payment_id );
ret = PHP_CREATED_OK;
load_db_record( out, "SELECT * FROM members_payments WHERE id = %lu ", payment_id );
} else {
out["status"] = "Uanble to create payment";
}
+6 -4
View File
@@ -139,9 +139,11 @@ long INTW_configure(CVars in, CVars &out) ;
long member_sendmoney(CVars in, CVars &out) {
//plog->SetFileName( PREFIX"/logs/member_sendmoney.log" );
//return INTW_doServiceTransfer(in, out);
return WRB_doServiceTransferComplete(in, out);
//return 0;
long ret = WRB_doServiceTransferComplete(in, out);
logfmt(logINFO, "************************ E****** member_sendmoney(CVars in, CVars out) =%lu",ret);
return ret;
}
long member_addrecipient(CVars in, CVars &out) {
@@ -598,7 +600,7 @@ long WRB_doServiceTransferComplete(CVars in, CVars &out) {
}
logfmt(logINFO, "/long INTW_doTransfer(CVars in, CVars &out)");
logfmt(logINFO, "/long WRB_doServiceTransferComplete(CVars in, CVars &out)");
return ret;
}