This commit is contained in:
2022-08-08 07:32:09 -04:00
parent 7aa911b1f7
commit ea4f941637
2 changed files with 83 additions and 3 deletions
+5 -2
View File
@@ -393,12 +393,15 @@ long WrenchBoardCompleteBalanceTopup(CVars in, CVars &out){
REQ_STRING(in, "transaction_id", 2, 50, "(.*)");
REQ_LONG(in, "status", 1, -1);
res = pgsql_query("SELECT id AS trx_id FROM flutterwave_payments WHERE tx_ref = '%s' AND status=0",in["tx_ref"].c_str());
res = pgsql_query("SELECT id AS trx_id,member_id FROM flutterwave_payments WHERE tx_ref = '%s' AND status=0",in["tx_ref"].c_str());
if (res != NULL && pgsql_num_rows(res) > 0) {
map<const char*, const char*>f = pgsql_fetch_assoc(res, 0);
CVars rec;
map_to_cvars(f, rec);
in["member_id"] = rec["member_id"]; in["member_id"].set_valid( true );
in["trx_id"] = rec["trx_id"]; in["trx_id"].set_valid( true );
pgsql_exec("UPDATE flutterwave_payments SET transaction_id = '%s', " \
"status=%lu,updated=now() WHERE id = %lu AND status=0 AND " \
"tx_ref='%s'", in["transaction_id"].c_str(),in["status"].Long(),rec["trx_id"].Long(), in["tx_ref"].c_str());
+78 -1
View File
@@ -32,7 +32,84 @@ long UpdateMemberWallet(long member_id,long wallet_id,long amount, long payment_
long WrenchMemberTopupPayment( CVars in, CVars &out )
{
logfmt(FLOG_MAX, "long WrenchMemberTopupPayment(CVars in, CVars &out)" );
logfmt(FLOG_MAX, "long WrenchMemberTopupPayment(CVars in, CVars &out)" );
long ret = PHP_API_BAD_PARAM;
ULONG payment_id = 0;
const char * loc = getenv("REMOTE_ADDR");
in["loc"] = loc; in["loc"].set_valid(true);
long member_id = REQ_LONG( in, "member_id", 1, -1 );
REQ_STRING (in, "tx_ref", 4, 50, "(.*)");
long trx_id = REQ_LONG( in, "trx_id", 1, -1 );
// let us make sure you have the wallet
// do we have a wallet for this action
CVars vw;
vw["currency"] = "NAIRA"; // this might become a variable based on the country
vw["currency"].set_valid( true );
long wallet_id = CheckWallet(member_id,vw);
if(!wallet_id || wallet_id == 0 ){
return -1; // no wallet --
}
in["curr_balance"] ="0";
long retDb = load_db_record( out, "SELECT amount AS curr_balance FROM members_wallet WHERE member_id = %lu AND currency='%s' ", member_id, vw["currency"].c_str());
if (retDb)
{ in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true );
logfmt(FLOG_MAX, "Current balance Read ********************" );
}
else { return -1; /* unable to read wallet*/ }
long retDb2 = load_db_record( out, "SELECT * FROM flutterwave_payments WHERE member_id = %lu AND tx_ref ='%s' AND id = %lu AND status = 5", in["member_id"].Long(), in["tx_ref"].c_str(),trx_id );
if (retDb2)
{
in["amount"] =out["amount"]; in["amount"].set_valid( true );
CVars x;
x["member_id"] = member_id; x["member_id"].set_valid( true );
x["code"] = "TOPUP"; x["code"].set_valid( true );
x["dir"] = "1"; x["dir"].set_valid( true );
x["loc"] = in["loc"]; x["loc"].set_valid( true );
x["curr_balance"] = in["curr_balance"]; x["curr_balance"].set_valid( true );
x["amount"] = in["amount"]; x["amount"].set_valid( true );
x["fee"] = "0"; x["fee"].set_valid( true );
// x["what_offer"] = offer_id; x["what_offer"].set_valid( true );
x["what_fluwv"] = trx_id; x["what_fluwv"].set_valid( true ); // assign coupon id
x["flags"] = FLAG_INIT; x["flags"].set_valid( true ); // starting the pprocess
payment_id = insert_db_record( DBS_VALID, "members_payments", "members_payments_id_seq", x );
if (payment_id) {
ret = PHP_CREATED_OK;
x["flags"] = FLAG_START; x["flags"].set_valid( true ); // done not completed yet
// now generate the confirmation
char confirmation[15] = "";
Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call
UpdateMemberWallet( x["member_id"].Long(), wallet_id,x["amount"].Long(), payment_id); // correct this dont send amount
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 );
pgsql_exec("UPDATE flutterwave_payments SET payment_id=%lu, completed = now() WHERE id = %lu AND member_id=%lu ",payment_id,trx_id,member_id );
load_db_record( out, "SELECT * FROM members_payments WHERE id = %lu ", payment_id );
} else {
out["status"] = "Unable to create payment";
}
}
else
{ out["status"] = "Invalid coupon";
ret= PHP_API_BAD_PARAM;
}
logfmt(FLOG_MAX, "/ long WrenchMemberTopupPayment(CVars in, CVars &out)" );
return 0;
}
long WrenchMemberCouponPayment( CVars in, CVars &out )