From b67f736f047ab149c902cf93ce1d5c24cd9b22f8 Mon Sep 17 00:00:00 2001 From: Olusesan Ameye Date: Sat, 19 Mar 2022 11:05:21 -0400 Subject: [PATCH] fix --- wrenchboard/src/shared_tool/payments.cc | 41 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/wrenchboard/src/shared_tool/payments.cc b/wrenchboard/src/shared_tool/payments.cc index 01c57d03..c86edfbb 100644 --- a/wrenchboard/src/shared_tool/payments.cc +++ b/wrenchboard/src/shared_tool/payments.cc @@ -278,7 +278,11 @@ long WrenchCanceContractPayment( CVars in, CVars &out ) - + 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); + /* // TEST FOR DUPLICATE @@ -316,9 +320,12 @@ long WrenchCanceContractPayment( CVars in, CVars &out ) 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",x["amount"].Long(),x["member_id"].Long() ); // pay attention to who you pay here + //- Retired this method pgsql_exec("UPDATE members SET balance=balance + %lu WHERE id = %lu",x["amount"].Long(),x["member_id"].Long() ); // pay attention to who you pay here char confirmation[15] = ""; - Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call + 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 ); @@ -438,7 +445,7 @@ 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 @@ -468,7 +475,12 @@ long WrenchRefundoffer( CVars in, CVars &out ) REQ_LONG( in, "dir", 1, -1 ); long offer_id = REQ_LONG( in, "offer_id", 1, -1 ); long payment_id = REQ_LONG( in, "payment_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()); if (retDb) @@ -500,9 +512,10 @@ long WrenchRefundoffer( CVars in, CVars &out ) 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",x["amount"].Long() + x["fee"].Long(),in["member_id"].Long() ); + // pgsql_exec("UPDATE members SET balance=balance + %lu WHERE id = %lu",x["amount"].Long() + x["fee"].Long(),in["member_id"].Long() ); char confirmation[15] = ""; - Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call + Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call + UpdateMemberWallet( member_id, 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 ); @@ -581,8 +594,11 @@ long WrenchContractPayment( CVars in, CVars &out ) return PHP_API_BAD_PARAM; } - - + 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); + /* // TEST FOR DUPLICATE @@ -620,9 +636,12 @@ long WrenchContractPayment( CVars in, CVars &out ) 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",x["amount"].Long(),x["member_id"].Long() ); // pay attention to who you pay here + //pgsql_exec("UPDATE members SET balance=balance + %lu WHERE id = %lu",x["amount"].Long(),x["member_id"].Long() ); // pay attention to who you pay here char confirmation[15] = ""; - Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call + 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 );