234 lines
8.3 KiB
C++
234 lines
8.3 KiB
C++
#include "smoney.h"
|
|
#include "clog.h"
|
|
#include "cgi.h"
|
|
#include "input.h"
|
|
#include "wrenchboard_api.h"
|
|
#include "interswitch_sendmoney.h"
|
|
#include "safestring.h"
|
|
#include "cfg.h"
|
|
#include <string>
|
|
#include "pgsql.h"
|
|
#include "pgsql_wrapper.h"
|
|
#include <curl/curl.h>
|
|
|
|
long smoney_calls(CVars in, CVars &out) {
|
|
logfmt(logINFO, "smoney_calls()");
|
|
out["result"] = "YES I GET TO BACK END";
|
|
long action = REQ_LONG(in, "action", 0, -1);
|
|
switch (action) {
|
|
|
|
|
|
case WRENCHBOARD_SMONEY_ADDRECIPIENT:
|
|
return member_addrecipient(in, out);
|
|
break;
|
|
|
|
case WRENCHBOARD_SMONEY_MEMBER:
|
|
return member_sendmoney(in, out);
|
|
break;
|
|
|
|
case WRENCHBOARD_SMONEY_PROCFEE:
|
|
return member_sendmoney_fee(in, out);
|
|
break;
|
|
|
|
case WRENCHBOARD_SMONEY_BKOPROC:
|
|
REQ_LONG(in, "action_mode", 0, -1);
|
|
return bko_process_sendmoney(in, out);
|
|
break;
|
|
|
|
// case WRENCHBOARD_GROUP_CREATEGROUP:
|
|
// return CreateWrenchBoardGroup( in, out);
|
|
// break;
|
|
}
|
|
logfmt(logINFO, "/smoney_calls()");
|
|
return 0;
|
|
}
|
|
|
|
long bko_process_sendmoney(CVars in, CVars &out) {
|
|
long ret = PHP_API_BAD_PARAM;
|
|
const PGresult *res1;
|
|
|
|
logfmt(logINFO, "long bko_process_sendmoney(CVars in, CVars out)");
|
|
try {
|
|
|
|
REQ_LONG(in, "sendmoney_id", 1, -1);
|
|
long action_mode = REQ_LONG(in, "action_mode", 1, -1); // receive the amount in cents
|
|
|
|
|
|
|
|
REQ_STRING(in, "trans_tref", 2, 49, "(.*)");
|
|
REQ_STRING(in, "trans_code", 2, 49, "(.*)");
|
|
|
|
const PGresult *res = pgsql_query("SELECT * FROM money_transfer WHERE status = 1 AND completed IS NULL AND id = %lu", in["sendmoney_id"].Long());
|
|
if (res != NULL && pgsql_num_rows(res) > 0) {
|
|
|
|
switch (action_mode) {
|
|
|
|
case SMONEY_PROCC_MANUAL:
|
|
|
|
res1 = pgsql_query("SELECT * FROM money_transfer_transaction WHERE transfer_code IS NULL AND responsecode IS NULL AND detail_id = %lu", in["sendmoney_id"].Long());
|
|
if (res1 != NULL && pgsql_num_rows(res1) > 0) {
|
|
map<const char*, const char*>f = pgsql_fetch_assoc(res1, 0);
|
|
logfmt(logINFO, "HERE - 1");
|
|
if (!f.empty()) {
|
|
logfmt(logINFO, "HERE - 2");
|
|
CVars rec;
|
|
map_to_cvars(f, rec);
|
|
out = rec;
|
|
logfmt(logINFO, "HERE - 3");
|
|
|
|
// out["status"] = "You have sent or completed a request for this task already.";
|
|
pgsql_exec("UPDATE money_transfer_transaction SET transfer_code='SID:%09lu',responsecode='%s',transactionref='%s' WHERE id=%lu", in["sendmoney_id"].Long(), in["trans_code"].c_str(), in["trans_tref"].c_str(), out["id"].Long());
|
|
pgsql_exec("UPDATE money_transfer SET status=5,completed=now() WHERE status = 1 AND completed IS NULL AND id=%lu", in["sendmoney_id"].Long());
|
|
out["status"] = "Completed";
|
|
// send email
|
|
}
|
|
}
|
|
|
|
break;
|
|
|
|
case SMONEY_PROCC_INTERSWITCH:
|
|
logfmt(logINFO, "***** INTERSWITCH CALL long bko_process_sendmoney(CVars in, CVars out)");
|
|
return INTW_doCompleteSavedTransfer(in, out);
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
} else {
|
|
out["status"] = "Invalid Status";
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (bad_parameter) {
|
|
out["log_status"] = "Invalid Log Action";
|
|
}
|
|
logfmt(logINFO, "/long bko_process_sendmoney(CVars in, CVars out)");
|
|
|
|
return ret;
|
|
}
|
|
|
|
long member_sendmoney_fee(CVars in, CVars &out) {
|
|
logfmt(logINFO, "long member_sendmoney_rate(CVars in, CVars out)");
|
|
out["processing_fee"] = "0";
|
|
try {
|
|
|
|
REQ_LONG(in, "member_id", 1, -1);
|
|
REQ_LONG(in, "amount", 1, -1); // receive the amount in cents
|
|
|
|
// this will use database and policy in full design
|
|
out["processing_fee"] = in["amount"].Long()*0.01 + 12000; // note we have to work in cents
|
|
out["total_amount"] = out["processing_fee"].Long() + in["amount"].Long();
|
|
|
|
} catch (bad_parameter) {
|
|
out["log_status"] = "Invalid Log Action";
|
|
}
|
|
logfmt(logINFO, "/long member_sendmoney_rate(CVars in, CVars out)");
|
|
return out["processing_fee"].Long();
|
|
}
|
|
|
|
long member_sendmoney(CVars in, CVars &out) {
|
|
//plog->SetFileName( PREFIX"/logs/member_sendmoney.log" );
|
|
return INTW_doServiceTransfer(in, out);
|
|
//return 0;
|
|
}
|
|
|
|
long member_addrecipient(CVars in, CVars &out) {
|
|
|
|
logfmt(logINFO, "long member_addrecipient(CVars in, CVars out)");
|
|
long ret = PHP_API_BAD_PARAM;
|
|
const char * loc = getenv("REMOTE_ADDR");
|
|
try {
|
|
REQ_LONG(in, "member_id", 1, -1);
|
|
|
|
REQ_STRING(in, "bank_code", 2, 3, "(.*)");
|
|
REQ_STRING(in, "firstname", 2, 49, "(.*)");
|
|
REQ_STRING(in, "lastname", 2, 49, "(.*)");
|
|
REQ_STRING(in, "account_no", 2, 15, "(.*)");
|
|
REQ_LONG(in, "account_type", 1, -1);
|
|
|
|
|
|
REQ_STRING(in, "country", 2, 3, "(.*)");
|
|
REQ_STRING(in, "state", 2, 49, "(.*)");
|
|
REQ_STRING(in, "city", 2, 49, "(.*)");
|
|
|
|
CVars x, xx;
|
|
|
|
if (load_db_record(x, "SELECT count(id) AS count_duplicate FROM sendmoney_recipient WHERE member_id = %lu AND account_no='%s' AND status = 1 ", in["member_id"].Long(), in["account_no"].c_str())) {
|
|
if (x["count_duplicate"].Long() > 0) {
|
|
out["error"] = "Duplicate Account Detected";
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
if (load_db_record(x, "SELECT count(id) AS count_duplicate FROM sendmoney_recipient WHERE account_no='%s' AND status IN ( 1, 7 ) ", in["account_no"].c_str())) {
|
|
if (x["count_duplicate"].Long() > 2) {
|
|
out["error"] = "Account used too many times";
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
xx["member_id"] = in["member_id"];
|
|
xx["member_id"].set_valid(true);
|
|
xx["bank_code"] = in["bank_code"];
|
|
xx["bank_code"].set_valid(true);
|
|
xx["loc"] = loc;
|
|
xx["loc"].set_valid(true);
|
|
xx["firstname"] = in["firstname"];
|
|
xx["firstname"].set_valid(true);
|
|
xx["lastname"] = in["lastname"];
|
|
xx["lastname"].set_valid(true);
|
|
xx["account_no"] = in["account_no"];
|
|
xx["account_no"].set_valid(true);
|
|
xx["account_type"] = in["account_type"];
|
|
xx["account_type"].set_valid(true);
|
|
xx["country"] = in["country"];
|
|
xx["country"].set_valid(true);
|
|
xx["state"] = in["state"];
|
|
xx["state"].set_valid(true);
|
|
|
|
out["recipient_id"] = insert_db_record(DBS_VALID, "sendmoney_recipient", "sendmoney_recipient_id_seq", xx);
|
|
|
|
if (out["recipient_id"].Long() > 0) {
|
|
ret = out["recipient_id"].Long(); //PHP_API_OK;
|
|
}
|
|
|
|
} catch (bad_parameter) {
|
|
out["log_status"] = "Invalid Log Action";
|
|
}
|
|
logfmt(logINFO, "/long member_addrecipient(CVars in, CVars out)");
|
|
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
Column | Type | Modifiers
|
|
--------------+-----------------------------+------------------------------------------------------------------
|
|
id | integer | not null default nextval('sendmoney_recipient_id_seq'::regclass)
|
|
member_id | integer |
|
|
bank_code | character varying(3) |
|
|
firstname | character varying(50) | not null
|
|
lastname | character varying(50) | not null
|
|
account_no | character varying(20) | not null
|
|
added | timestamp without time zone | default now()
|
|
updated | timestamp without time zone | default now()
|
|
status | integer | default 1
|
|
account_type | integer | default 20
|
|
Indexes:
|
|
"sendmoney_recipient_id_key" UNIQUE CONSTRAINT, btree (id)
|
|
Foreign-key constraints:
|
|
"sendmoney_recipient_member_id_fkey" FOREIGN KEY (member_id) REFERENCES members(id)
|
|
Referenced by:
|
|
TABLE "money_transfer" CONSTRAINT "money_transfer_recipientid_fkey" FOREIGN KEY (recipientid) REFERENCES sendmoney_recipient(id)
|
|
|
|
*/
|
|
|
|
|
|
|