payment id
This commit is contained in:
@@ -920,133 +920,105 @@ long WrenchContractPayment( CVars in, CVars &out )
|
|||||||
}
|
}
|
||||||
long WrenchSendMoneyPayment( CVars in, CVars &out )
|
long WrenchSendMoneyPayment( CVars in, CVars &out )
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
wrenchboard=> \d members_payments;
|
|
||||||
Table "public.members_payments"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
----------------+-----------------------------+---------------------------------------------------------------
|
|
||||||
id | integer | not null default nextval('members_payments_id_seq'::regclass)
|
|
||||||
member_id | integer |
|
|
||||||
code | character varying(5) |
|
|
||||||
dir | integer | not null
|
|
||||||
curr_balance | integer | default 0
|
|
||||||
amount | integer | default 0
|
|
||||||
fee | integer | default 0
|
|
||||||
confirmation | character varying(15) |
|
|
||||||
status | integer | default 1
|
|
||||||
flags | integer | default 1
|
|
||||||
added | timestamp without time zone | default now()
|
|
||||||
updated | timestamp without time zone | default now()
|
|
||||||
loc | inet |
|
|
||||||
what_offer | integer |
|
|
||||||
what_contract | integer |
|
|
||||||
what_sendmoney | integer |
|
|
||||||
Indexes:
|
|
||||||
"members_payments_confirmation_key" UNIQUE CONSTRAINT, btree (confirmation)
|
|
||||||
"members_payments_id_key" UNIQUE CONSTRAINT, btree (id)
|
|
||||||
Foreign-key constraints:
|
|
||||||
"members_payments_code_fkey" FOREIGN KEY (code) REFERENCES payment_types(code)
|
|
||||||
"members_payments_member_id_fkey" FOREIGN KEY (member_id) REFERENCES members(id)
|
|
||||||
"members_payments_what_contract_fkey" FOREIGN KEY (what_contract) REFERENCES members_jobs_contract(id)
|
|
||||||
"members_payments_what_offer_fkey" FOREIGN KEY (what_offer) REFERENCES members_jobs_offer(id)
|
|
||||||
"members_payments_what_sendmoney_fkey" FOREIGN KEY (what_sendmoney) REFERENCES money_transfer(id)
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
long ret = PHP_API_BAD_PARAM;
|
long ret = PHP_API_BAD_PARAM;
|
||||||
logfmt( logINFO, "WrenchSendMoneyPayment()************************************ ****" );
|
logfmt( logINFO, "WrenchSendMoneyPayment()************************************ ****" );
|
||||||
ULONG payment_id = 0;
|
ULONG payment_id = 0;
|
||||||
|
|
||||||
const char * loc = getenv("REMOTE_ADDR");
|
try {
|
||||||
in["loc"] = loc; in["loc"].set_valid(true);
|
const char * loc = getenv("REMOTE_ADDR");
|
||||||
|
in["loc"] = loc; in["loc"].set_valid(true);
|
||||||
REQ_LONG( in, "member_id", 1, -1 );
|
|
||||||
REQ_STRING (in, "code", 4, 5, "(.*)");
|
|
||||||
REQ_LONG( in, "dir", 1, -1 );
|
|
||||||
REQ_LONG( in, "sendmoney_id", 1, -1 );
|
|
||||||
REQ_LONG( in, "wallet_id", 1, -1 );
|
|
||||||
|
|
||||||
CVars vw;
|
REQ_LONG( in, "member_id", 1, -1 );
|
||||||
vw["currency"] = "NAIRA"; // this might become a variable based on the country
|
REQ_STRING (in, "code", 4, 5, "(.*)");
|
||||||
vw["currency"].set_valid( true );
|
REQ_LONG( in, "dir", 1, -1 );
|
||||||
long wallet_id = CheckWallet(in["member_id"].Long(),vw);
|
REQ_LONG( in, "sendmoney_id", 1, -1 );
|
||||||
|
REQ_LONG( in, "wallet_id", 1, -1 );
|
||||||
|
|
||||||
long retDb = load_db_record( out, "SELECT amount AS new_balance FROM members_wallet WHERE id = %lu AND member_id = %lu",wallet_id, in["member_id"].Long());
|
// CVars vw;
|
||||||
|
// vw["currency"] = "NAIRA"; // this might become a variable based on the country
|
||||||
if (retDb)
|
// vw["currency"].set_valid( true );
|
||||||
{ in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true ); // get this one LIVE
|
//long wallet_id = CheckWallet(in["member_id"].Long(),vw);
|
||||||
}
|
|
||||||
else
|
|
||||||
{ out["status"] = "Invalid user";
|
|
||||||
return PHP_API_BAD_PARAM; }
|
|
||||||
|
|
||||||
long retDb2 = load_db_record( out, "SELECT id,initiatingamount AS amount,fee from money_transfer WHERE member_id= %lu AND id = %lu",in["member_id"].Long(), in["sendmoney_id"].Long());
|
|
||||||
if (retDb2)
|
|
||||||
{ in["amount"] =out["amount"]; in["amount"].set_valid( true ); // get this one LIVE
|
|
||||||
in["fee"] =out["fee"]; in["fee"].set_valid( true ); // get this one LIVE
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ out["status"] = "Invalid offer";
|
|
||||||
return PHP_API_BAD_PARAM;
|
|
||||||
}
|
|
||||||
long totalAmount = in["amount"].Long() + in["fee"].Long();
|
|
||||||
if ( in["curr_balance"] < in["amount"].Long() + in["fee"].Long())
|
|
||||||
{
|
|
||||||
out["status"] = "Insufficient balance for this offer";
|
|
||||||
return PHP_API_BAD_PARAM;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if you have enough money for this offer
|
|
||||||
|
|
||||||
// flags //
|
|
||||||
|
|
||||||
|
long retDb = load_db_record( out, "SELECT amount AS curr_balance FROM members_wallet WHERE id = %lu AND member_id = %lu",wallet_id, in["member_id"].Long());
|
||||||
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 );
|
if (retDb)
|
||||||
x["amount"] = in["amount"]; x["amount"].set_valid( true );
|
{ in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true ); // get this one LIVE
|
||||||
x["fee"] = in["fee"]; x["fee"].set_valid( true );
|
}
|
||||||
|
else
|
||||||
|
{ out["status"] = "Invalid user";
|
||||||
|
return PHP_API_BAD_PARAM; }
|
||||||
|
|
||||||
x["what_sendmoney"] = in["sendmoney_id"]; x["what_sendmoney"].set_valid( true );
|
long retDb2 = load_db_record( out, "SELECT id,initiatingamount AS amount,fee from money_transfer WHERE member_id= %lu AND id = %lu",in["member_id"].Long(), in["sendmoney_id"].Long());
|
||||||
x["flags"] = FLAG_INIT; x["flags"].set_valid( true ); // starting the pprocess
|
if (retDb2)
|
||||||
payment_id = insert_db_record( DBS_VALID, "members_payments", "members_payments_id_seq", x );
|
{ in["amount"] =out["amount"]; in["amount"].set_valid( true ); // get this one LIVE
|
||||||
|
in["fee"] =out["fee"]; in["fee"].set_valid( true ); // get this one LIVE
|
||||||
// return if not good
|
}
|
||||||
|
else
|
||||||
const PGresult *res = pgsql_query("SELECT * FROM members_payments WHERE id=%lu AND member_id = %lu",payment_id, x["member_id"].Long() );
|
{ out["status"] = "Invalid offer";
|
||||||
if (res!=NULL && pgsql_num_rows(res)>0)
|
return PHP_API_BAD_PARAM;
|
||||||
{
|
}
|
||||||
|
long totalAmount = in["amount"].Long() + in["fee"].Long();
|
||||||
|
if ( in["curr_balance"] < in["amount"].Long() + in["fee"].Long())
|
||||||
|
{
|
||||||
|
out["status"] = "Insufficient balance for this offer";
|
||||||
|
return PHP_API_BAD_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
else
|
CVars x;
|
||||||
{
|
x["member_id"] = in["member_id"]; x["member_id"].set_valid( true );
|
||||||
out["status"] = "Failure to create";
|
x["code"] = in["code"]; x["code"].set_valid( true );
|
||||||
return PHP_API_BAD_PARAM;
|
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"] = in["amount"]; x["amount"].set_valid( true );
|
||||||
|
x["fee"] = in["fee"]; x["fee"].set_valid( true );
|
||||||
|
x["what_sendmoney"] = in["sendmoney_id"]; x["what_sendmoney"].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 );
|
||||||
|
logfmt(logINFO, "long WrenchSendMoneyPayment(CVars in, CVars &out) payment_id = %lu",payment_id);
|
||||||
|
// return if not good
|
||||||
|
if (payment_id <=0 ){
|
||||||
|
logfmt(logINFO, "ERROR WrenchSendMoneyPayment(CVars in, CVars &out) payment_id = %lu",payment_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const PGresult *res = pgsql_query("SELECT * FROM members_payments WHERE id=%lu AND member_id = %lu",payment_id, x["member_id"].Long() );
|
||||||
|
if (res!=NULL && pgsql_num_rows(res)>0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out["status"] = "Failure to create";
|
||||||
|
return PHP_API_BAD_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
out["payment_id"] = payment_id; out["payment_id"].set_valid( true );
|
||||||
|
if (payment_id) {
|
||||||
|
|
||||||
|
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() );
|
||||||
|
DeductMemberWallet(in["member_id"].Long(), wallet_id,in["amount"].Long() + in["fee"].Long(), payment_id);
|
||||||
|
char confirmation[15] = "";
|
||||||
|
Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call
|
||||||
|
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 );
|
||||||
|
load_db_record( out, "SELECT * FROM members_payments WHERE id = %lu ", payment_id );
|
||||||
|
ret = PHP_CREATED_OK;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
out["status"] = "Unable to create payment";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (bad_parameter) {
|
||||||
|
logfmt(logINFO, "ERROR CALL long WrenchSendMoneyPayment(CVars in, CVars &out)");
|
||||||
}
|
}
|
||||||
|
|
||||||
out["payment_id"] = payment_id; out["payment_id"].set_valid( true );
|
|
||||||
if (payment_id) {
|
|
||||||
|
|
||||||
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() );
|
|
||||||
DeductMemberWallet(in["member_id"].Long(), wallet_id,in["amount"].Long() + in["fee"].Long(), payment_id);
|
|
||||||
char confirmation[15] = "";
|
|
||||||
Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call
|
|
||||||
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 );
|
|
||||||
load_db_record( out, "SELECT * FROM members_payments WHERE id = %lu ", payment_id );
|
|
||||||
ret = PHP_CREATED_OK;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
out["status"] = "Uanble to create payment";
|
|
||||||
}
|
|
||||||
|
|
||||||
logfmt( logINFO, "/WrenchSendMoneyPayment()" );
|
logfmt( logINFO, "/WrenchSendMoneyPayment()" );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,8 +423,6 @@ long do_transferPayment(CVars in) {
|
|||||||
//*****************************************************************************/
|
//*****************************************************************************/
|
||||||
|
|
||||||
long WRB_doServiceTransferComplete(CVars in, CVars &out) {
|
long WRB_doServiceTransferComplete(CVars in, CVars &out) {
|
||||||
//plog->SetFileName( PREFIX"/logs/send_money.log" );
|
|
||||||
|
|
||||||
logfmt(logINFO, "long WRB_doServiceTransferComplete(CVars in, CVars &out)");
|
logfmt(logINFO, "long WRB_doServiceTransferComplete(CVars in, CVars &out)");
|
||||||
long ret = PHP_API_BAD_PARAM;
|
long ret = PHP_API_BAD_PARAM;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user