From cc725eea288e1cea8be748e01d478c4e61ce9994 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Mon, 23 Sep 2024 12:13:08 -0400 Subject: [PATCH] WrenchZeroRefundOffer --- wrenchboard/src/include/payments.h | 1 + wrenchboard/src/shared_tool/jobs.cc | 3 + wrenchboard/src/shared_tool/payments.cc | 76 ++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/wrenchboard/src/include/payments.h b/wrenchboard/src/include/payments.h index 27a31923..6a3fd31a 100644 --- a/wrenchboard/src/include/payments.h +++ b/wrenchboard/src/include/payments.h @@ -6,6 +6,7 @@ long WrenchOfferPayment( CVars in, CVars &out ); long WrenchSendMoneyPayment( CVars in, CVars &out ); long WrenchRefundoffer( CVars in, CVars &out ); +long WrenchZeroRefundOffer( CVars in, CVars &out ); long WrenchContractPayment( CVars in, CVars &out ); long WrenchCanceContractPayment( CVars in, CVars &out ); diff --git a/wrenchboard/src/shared_tool/jobs.cc b/wrenchboard/src/shared_tool/jobs.cc index 4bc2556e..ba67c65c 100644 --- a/wrenchboard/src/shared_tool/jobs.cc +++ b/wrenchboard/src/shared_tool/jobs.cc @@ -1218,8 +1218,11 @@ long WrenchConcludeJobsOffer(CVars in, CVars &out) { } } if ( offer_result == OFFER_NOREFU){ + + if (WrenchZeroRefundOffer(y, out) == PHP_CREATED_OK) { logfmt(logINFO, "********* NO REFUND ************* NO REFUND WrenchConcludeJobsOffer() rc=FOUND"); pgsql_exec("UPDATE members_jobs_offer SET status = 4 WHERE id = %lu AND offer_code='%s' ", offer_id, in["offer_code"].c_str()); + } } diff --git a/wrenchboard/src/shared_tool/payments.cc b/wrenchboard/src/shared_tool/payments.cc index 9f14bab5..1d8f8539 100644 --- a/wrenchboard/src/shared_tool/payments.cc +++ b/wrenchboard/src/shared_tool/payments.cc @@ -930,12 +930,86 @@ Foreign-key constraints: return ret; } +long WrenchZeroRefundOffer( CVars in, CVars &out ) +{ + logfmt( logINFO, "WrenchZeroRefundOffer" ); + 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, "code", 4, 5, "(.*)"); + 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 ); + + + long retDb2 = load_db_record( out, "SELECT id AS current_payment_id, * FROM members_payments WHERE id =%lu AND what_offer = %lu AND member_id=%lu AND code = 'OFDPS' AND status = 1 AND flags = 4 AND confirmation IS NOT NULL",payment_id,offer_id,member_id); + if (retDb2) + { + long current_payment_id = out["current_payment_id"].Long(); + + + CVars vw; + vw["currency"] = out["currency"]; // 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 amount AS curr_balance FROM members_wallet WHERE member_id = %lu AND id = %lu", in["member_id"].Long(),wallet_id); + + if (retDb > 0) + { in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true ); // get this one LIVE + } + else + { out["status"] = "Invalid user"; + return PHP_API_BAD_PARAM; + } + + CVars x; + x["member_id"] = in["member_id"]; x["member_id"].set_valid( true ); + x["code"] = in["code"]; x["code"].set_valid( true ); + x["dir"] = in["dir"]; 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"] = out["amount"]; x["amount"].set_valid( true ); + x["fee"] = out["fee"]; x["fee"].set_valid( true ); + + x["what_offer"] = out["what_offer"]; x["what_offer"].set_valid( true ); + 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 + // DO NOT UPDATE WALLET 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 ); + pgsql_exec("UPDATE members_payments SET flags = 7 WHERE id = %lu",current_payment_id ); + //pgsql_exec("UPDATE members_jobs_offer SET payment_id = %lu WHERE id = %lu",x["payment_id"].Long(),x["what_offer"].Long() ); + load_db_record( out, "SELECT * FROM members_payments WHERE id = %lu ", payment_id ); + } else { + out["status"] = "Unable to Refund Payment"; + } + + } + + logfmt( logINFO, "/WrenchZeroRefundOffer" ); + return ret; +} + long WrenchRefundoffer( CVars in, CVars &out ) { logfmt( logINFO, "WrenchRefundoffer" ); long ret = PHP_API_BAD_PARAM; //ULONG payment_id = 0; - + const char * loc = getenv("REMOTE_ADDR"); in["loc"] = loc; in["loc"].set_valid(true);