This commit is contained in:
CHIEFSOFT\ameye
2023-07-27 09:06:40 -04:00
parent 30187feaf1
commit 8f5e81a9d1
+112 -120
View File
@@ -139,13 +139,17 @@ long INTW_configure(CVars in, CVars &out) ;
long member_sendmoney(CVars in, CVars &out) {
logfmt(logINFO, "************************ E****** member_sendmoney START");
REQ_LONG(in, "member_id", 1, -1);
REQ_LONG(in, "senderid", 1, -1);
long ret = WRB_doServiceTransferComplete(in, out);
logfmt(logINFO, "************************ E****** member_sendmoney(CVars in, CVars out) =%lu",ret);
logfmt(logINFO, "************************ E****** member_sendmoney END");
try {
REQ_LONG(in, "member_id", 1, -1);
REQ_LONG(in, "senderid", 1, -1);
long ret = WRB_doServiceTransferComplete(in, out);
logfmt(logINFO, "************************ E****** member_sendmoney(CVars in, CVars out) =%lu",ret);
logfmt(logINFO, "************************ E****** member_sendmoney END");
} catch (bad_parameter) {
out["log_status"] = "Error - member_sendmoney *******";
}
logfmt(logINFO, "/long member_sendmoney(CVars in, CVars out)");
return ret;
}
@@ -287,140 +291,128 @@ long do_transferPayment(CVars in) {
logfmt(logINFO, "START ***** long do_transferPayment(CVars in, CVars &out)");
long ret = PHP_API_BAD_PARAM;
CVars out;
long member_id = REQ_LONG(in, "member_id", 1, -1);
long customer_id = REQ_LONG(in, "customer_id", 1, -1);
long transfer_id = REQ_LONG(in, "transfer_id", 1, -1);
long payMode = REQ_LONG(in, "mode", 1, -1);
long payment_id = 0;
long amount = 0;
long fee = 0;
long total = 0;
long wallet_id = 0;
REQ_STRING(in, "wallet_uid", 3, 150, "(.*)");
REQ_STRING(in, "terminating_country_code", 2, 2, "(.*)");
/*
CREATE TABLE sendmoney_payment
(
id serial NOT NULL,
transfer_mode integer NOT NULL,
customer_id INT REFERENCES customer(id),
transfer_id INT REFERENCES interswitch_money_transfer(id),
amount integer DEFAULT 0,
fee integer DEFAULT 0,
total integer DEFAULT 0,
current_balance integer DEFAULT 0,
new_balance integer DEFAULT 0,
status integer DEFAULT 1,
added TIMESTAMP DEFAULT NOW()
);
*/
ret = load_db_record(out, "SELECT balance FROM members WHERE id = %lu AND status = 1", member_id);
if (ret < 1L) {
throw new bad_parameter(out, "senderid");
}
if (payMode == PAYMENT_MODE) {
amount = REQ_LONG(in, "amount", 1, -1);
fee = REQ_LONG(in, "fee", 1, -1);
total = amount + fee; // make sure you are cent here
try {
long member_id = REQ_LONG(in, "member_id", 1, -1);
long customer_id = REQ_LONG(in, "customer_id", 1, -1);
long transfer_id = REQ_LONG(in, "transfer_id", 1, -1);
long payMode = REQ_LONG(in, "mode", 1, -1);
long payment_id = 0;
long amount = 0;
long fee = 0;
long total = 0;
long wallet_id = 0;
CVars wl;
if ( load_db_record(wl, "SELECT w.*,c.country,w.amount,w.id AS wallet_id from members_wallet w LEFT join currency c ON c.code=w.currency"
" WHERE c.country='%s' AND w.member_id=%lu AND w.uid='%s' ",in["terminating_country_code"].c_str(), in["member_id"].Long(),in["wallet_uid"].c_str())> 0){
if ( total > wl["amount"].Long() )
{
out["status_message"] = "insufficient_balance_error";
out["status_text"] = "insufficient balance for transaction";
return ret;
REQ_STRING(in, "wallet_uid", 3, 150, "(.*)");
REQ_STRING(in, "terminating_country_code", 2, 2, "(.*)");
ret = load_db_record(out, "SELECT balance FROM members WHERE id = %lu AND status = 1", member_id);
if (ret < 1L) {
throw new bad_parameter(out, "senderid");
}
wallet_id = wl["wallet_id"].Long();
}
else
{
out["status_message"] = "wallet_not_found_error";
throw new bad_parameter(out, "senderid");
// return ret;
}
if (payMode == PAYMENT_MODE) {
amount = REQ_LONG(in, "amount", 1, -1);
fee = REQ_LONG(in, "fee", 1, -1);
total = amount + fee; // make sure you are cent here
CVars wl;
if ( load_db_record(wl, "SELECT w.*,c.country,w.amount,w.id AS wallet_id from members_wallet w LEFT join currency c ON c.code=w.currency"
" WHERE c.country='%s' AND w.member_id=%lu AND w.uid='%s' ",in["terminating_country_code"].c_str(), in["member_id"].Long(),in["wallet_uid"].c_str())> 0){
if ( total > wl["amount"].Long() )
{
out["status_message"] = "insufficient_balance_error";
out["status_text"] = "insufficient balance for transaction";
return ret;
}
wallet_id = wl["wallet_id"].Long();
}
else
{
out["status_message"] = "wallet_not_found_error";
throw new bad_parameter(out, "senderid");
// return ret;
}
if (wl["amount"].Long() >= total && wallet_id > 0) // do you have this money
{
CVars x;
x["transfer_mode"] = PAYMENT_MODE;
x["transfer_mode"].set_valid(true);
x["member_id"] = customer_id;
x["member_id"].set_valid(true);
x["transfer_id"] = transfer_id;
x["transfer_id"].set_valid(true);
x["amount"] = amount;
x["amount"].set_valid(true);
x["fee"] = fee;
x["fee"].set_valid(true);
x["total"] = total;
x["total"].set_valid(true);
x["current_balance"] = wl["amount"];
x["current_balance"].set_valid(true);
payment_id = 0;
if (wl["amount"].Long() >= total && wallet_id > 0) // do you have this money
{
CVars x;
x["transfer_mode"] = PAYMENT_MODE;
x["transfer_mode"].set_valid(true);
x["member_id"] = customer_id;
x["member_id"].set_valid(true);
x["transfer_id"] = transfer_id;
x["transfer_id"].set_valid(true);
x["amount"] = amount;
x["amount"].set_valid(true);
x["fee"] = fee;
x["fee"].set_valid(true);
x["total"] = total;
x["total"].set_valid(true);
x["current_balance"] = wl["amount"];
x["current_balance"].set_valid(true);
payment_id = 0;
out["sendmoney_payment_id"] = insert_db_record(DBS_VALID, "sendmoney_payment", "sendmoney_payment_id_seq", x);
char confirmation[20] = "";
// payment_id = out["payment_id"].Long();
out["sendmoney_payment_id"] = insert_db_record(DBS_VALID, "sendmoney_payment", "sendmoney_payment_id_seq", x);
char confirmation[20] = "";
// payment_id = out["payment_id"].Long();
// Confirmation(payment_id, confirmation, sizeof (confirmation));
ret = PHP_API_BAD_PARAM; // it is still a failure if we get here and did not take the money out of the balance
// Confirmation(payment_id, confirmation, sizeof (confirmation));
ret = PHP_API_BAD_PARAM; // it is still a failure if we get here and did not take the money out of the balance
CVars y;
y["member_id"] = x["member_id"];
y["member_id"].set_valid(true);
y["sendmoney_id"] = x["transfer_id"];
y["sendmoney_id"].set_valid(true);
y["code"] = "SMPAY";
y["code"].set_valid(true);
y["dir"] = DIR_TARGET;
y["dir"].set_valid(true);
y["wallet_id"] = wallet_id;
y["wallet_id"].set_valid(true);
CVars y;
y["member_id"] = x["member_id"];
y["member_id"].set_valid(true);
y["sendmoney_id"] = x["transfer_id"];
y["sendmoney_id"].set_valid(true);
y["code"] = "SMPAY";
y["code"].set_valid(true);
y["dir"] = DIR_TARGET;
y["dir"].set_valid(true);
y["wallet_id"] = wallet_id;
y["wallet_id"].set_valid(true);
//y["payment_id"] = out["payment_id"]; y["payment_id"].set_valid( true );
//y["payment_id"] = out["payment_id"]; y["payment_id"].set_valid( true );
ret = WrenchSendMoneyPayment(y, out);
ret = WrenchSendMoneyPayment(y, out);
if (ret == PHP_CREATED_OK) {
load_db_record(out, "SELECT amount AS new_balance FROM members_wallet WHERE id = %lu", wallet_id);
pgsql_exec("UPDATE sendmoney_payment SET new_balance=%lu WHERE id=%lu", out["new_balance"].Long(), out["sendmoney_payment_id"].Long());
ret = PHP_API_OK;
if (ret == PHP_CREATED_OK) {
load_db_record(out, "SELECT amount AS new_balance FROM members_wallet WHERE id = %lu", wallet_id);
pgsql_exec("UPDATE sendmoney_payment SET new_balance=%lu WHERE id=%lu", out["new_balance"].Long(), out["sendmoney_payment_id"].Long());
ret = PHP_API_OK;
}
}
}
}
}
if (payMode == REFUND_MODE) {
if (load_db_record(out, "SELECT * FROM sendmoney_payment WHERE transfer_id = %lu AND member_id = %lu", transfer_id, customer_id)) {
logfmt(logINFO, "*****WE RE DO VERIFICATION and NO DUPLICATES)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
CVars out;
/*REQ_STRING( in, "TransferCode", 3, 30, "(.*)" );
REQ_STRING( in, "requestReference", 3, 30, "(.*)" );*/
if (payMode == REFUND_MODE) {
if (load_db_record(out, "SELECT * FROM sendmoney_payment WHERE transfer_id = %lu AND member_id = %lu", transfer_id, customer_id)) {
logfmt(logINFO, "*****WE RE DO VERIFICATION and NO DUPLICATES)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
logfmt(logINFO, "**)");
CVars out;
/*REQ_STRING( in, "TransferCode", 3, 30, "(.*)" );
REQ_STRING( in, "requestReference", 3, 30, "(.*)" );*/
//int vRet = INTW_querySendMoneyTransaction(in, out);
ret = PHP_API_OK;
}
//int vRet = INTW_querySendMoneyTransaction(in, out);
ret = PHP_API_OK;
}
}
}
} catch (bad_parameter) {
logfmt(logINFO, "ERROR CALL long do_transferPayment(CVars in, CVars &out***");
}
//PAYMENT_MODE
//REFUND_MODE
logfmt(logINFO, "END ***** long do_transferPayment(CVars in, CVars &out)");