family transfer
This commit is contained in:
@@ -459,7 +459,7 @@ long WrenchFamilyTransfer(CVars in, CVars &out){
|
||||
if( load_db_record(out,"SELECT w.amount AS origing_current_balance,w.uid AS origing_wallet_uid,"
|
||||
" w.transfer_limit AS origing_transfer_limit, w.currency as origing_currency "
|
||||
" FROM members_wallet w "
|
||||
" WHERE w.member_id = %lu AND w.currency='%s' AND w.uid='%s'", in["member_id"].Long(), out["currency"].c_str(), in["origing_wallet_uid"].c_str()) ){
|
||||
" WHERE w.member_id = %lu AND w.currency='%s' AND w.uid='%s'", in["member_id"].Long(), out["currency"].c_str(), in["origing_wallet_uid"].c_str()) >0 ){
|
||||
|
||||
|
||||
if (in["amount"].Long() > out["origing_transfer_limit"].Long() ){
|
||||
@@ -467,6 +467,11 @@ long WrenchFamilyTransfer(CVars in, CVars &out){
|
||||
out["error_limit"] = "amount_greater_than_limit";
|
||||
}
|
||||
|
||||
if (in["amount"].Long() <= 0 > ){
|
||||
err_count++;
|
||||
out["error_balance"] = "amount_inavlid";
|
||||
}
|
||||
|
||||
if (in["amount"].Long() > out["origing_current_balance"].Long() ){
|
||||
err_count++;
|
||||
out["error_balance"] = "amount_greater_than_balance";
|
||||
@@ -478,15 +483,57 @@ long WrenchFamilyTransfer(CVars in, CVars &out){
|
||||
}
|
||||
CVars inx;
|
||||
inx["member_id"] = in["member_id"]; inx["member_id"].set_valid( true );
|
||||
inx["recipient"] = rec0["family_member_id"]; inx["recipient"].set_valid( true );
|
||||
inx["uid"] = in["uid"]; inx["uid"].set_valid( true );
|
||||
inx["currency"] = in["currency"]; inx["currency"].set_valid( true );
|
||||
inx["origing_wallet_uid"] = in["origing_wallet_uid"]; inx["origing_wallet_uid"].set_valid( true );
|
||||
inx["origing_wallet"] = in["origing_wallet_uid"]; inx["origing_wallet"].set_valid( true );
|
||||
inx["target_wallet"] = out["recipient_wallet_uid"]; inx["target_wallet"].set_valid( true );
|
||||
inx["amount"] = in["amount"]; inx["amount"].set_valid( true );
|
||||
inx["description"] = in["description"]; inx["description"].set_valid( true );
|
||||
|
||||
return WrenchFamilyPayment( inx, out );
|
||||
long family_transfer_id = insert_db_record(DBS_VALID, "family_transfer", "family_transfer_id_seq", inx);
|
||||
|
||||
if ( family_transfer_id > 0 ){
|
||||
CVars trx;
|
||||
if ( load_db_record(trx, "SELECT * FROM family_transfer WHERE id =%lu",family_transfer_id) > 0 ){
|
||||
return WrenchFamilyPayment( trx, out );
|
||||
out["status"] = "OK";
|
||||
out["exchange_rate"] ="1";
|
||||
ret = PHP_API_OK;
|
||||
}
|
||||
else{
|
||||
out["status"] = "System Error 02";
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
out["status"] = "System Error 01";
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
CREATE TABLE family_transfer (
|
||||
id SERIAL,
|
||||
uid uuid DEFAULT uuid_generate_v4(),
|
||||
member_id INT REFERENCES members(id) NOT NULL,
|
||||
recipient INT REFERENCES members(id) NOT NULL,
|
||||
origing_wallet VARCHAR(150) NOT NULL,
|
||||
target_wallet VARCHAR(150) NOT NULL,
|
||||
amount INT Default 0,
|
||||
currency VARCHAR(5) REFERENCES currency(code),
|
||||
description VARCHAR(150),
|
||||
status INT DEFAULT 1,
|
||||
flags INT DEFAULT 0,
|
||||
added timestamp without time zone DEFAULT now(),
|
||||
updated timestamp without time zone DEFAULT now()
|
||||
);
|
||||
ALTER TABLE ONLY family_transfer
|
||||
ADD CONSTRAINT family_transfer_id_key UNIQUE (id);
|
||||
*/
|
||||
|
||||
out["status"] = "OK";
|
||||
out["exchange_rate"] ="1";
|
||||
ret = PHP_API_OK;
|
||||
}
|
||||
else{
|
||||
out["status"] = "Originating wallet not found";
|
||||
|
||||
@@ -141,8 +141,8 @@ long WrenchFamilyPayment( CVars in, CVars &out )
|
||||
in["curr_balance"] ="0";
|
||||
|
||||
long retDb = load_db_record( out, "SELECT amount AS curr_balance FROM members_wallet "
|
||||
" WHERE member_id = %lu AND currency='%s' AND uid = '%s'", member_id, vw["currency"].c_str(), in["origing_wallet_uid"].c_str());
|
||||
if (retDb)
|
||||
" WHERE member_id = %lu AND currency='%s' AND uid = '%s'", member_id, vw["currency"].c_str(), in["origing_wallet"].c_str());
|
||||
if (retDb > 0 )
|
||||
{ in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true );
|
||||
logfmt(FLOG_MAX, "Current balance Read ********************" );
|
||||
}
|
||||
@@ -151,7 +151,8 @@ long WrenchFamilyPayment( CVars in, CVars &out )
|
||||
return ret; /* unable to read wallet*/ }
|
||||
|
||||
|
||||
long retDb2 = load_db_record( out, "SELECT * FROM family_transfer WHERE member_id = %lu AND code ='%s' AND id = %lu AND active IS NULL", in["member_id"].Long(), in["code"].c_str(),code_id );
|
||||
long retDb2 = load_db_record( out, "SELECT * FROM family_transfer "
|
||||
" WHERE member_id = %lu AND code ='%s' AND id = %lu AND active IS NULL", in["member_id"].Long(), in["code"].c_str(),code_id );
|
||||
if (retDb2>0)
|
||||
{
|
||||
in["coupon_amount"] =out["amount"]; in["coupon_amount"].set_valid( true );
|
||||
@@ -171,7 +172,7 @@ long WrenchFamilyPayment( CVars in, CVars &out )
|
||||
|
||||
|
||||
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 );
|
||||
payment_id = 0; // insert_db_record( DBS_VALID, "members_payments", "members_payments_id_seq", x );
|
||||
|
||||
if (payment_id) {
|
||||
ret = PHP_CREATED_OK;
|
||||
@@ -185,15 +186,15 @@ long WrenchFamilyPayment( CVars in, CVars &out )
|
||||
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 coupons_allocation SET active = now() WHERE id = %lu AND CODE='%s' ",code_id,in["code"].c_str() );
|
||||
load_db_record( out, "SELECT * FROM members_payments WHERE id = %lu ", payment_id );
|
||||
pgsql_exec("UPDATE family_transfer SET active = now() WHERE id = %lu AND CODE='%s' ",code_id,in["code"].c_str() );
|
||||
load_db_record( out, "SELECT * FROM family_transfer WHERE id = %lu ", payment_id );
|
||||
} else {
|
||||
out["status"] = "Unable to create payment";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{ out["status"] = "Invalid coupon";
|
||||
{ out["status"] = "error_invalid_transfer";
|
||||
ret= PHP_API_BAD_PARAM;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user