fix
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user