family transfer
This commit is contained in:
@@ -16,6 +16,7 @@ long CheckWallet(long member_id,CVars in);
|
||||
long DeductMemberWallet(long member_id,long wallet_id,long amount, long payment_id);
|
||||
long WrenchMemberCouponPayment( CVars in, CVars &out );
|
||||
long WrenchMemberTopupPayment( CVars in, CVars &out );
|
||||
long WrenchFamilyPayment( CVars in, CVars &out );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "family_acc.h"
|
||||
#include "common_tool.h"
|
||||
#include "account.h"
|
||||
#include "payments.h"
|
||||
|
||||
long WrenchFamilyList(CVars in, CVars &out);
|
||||
long WrenchFamilyWallet(CVars in, CVars &out);
|
||||
@@ -475,7 +476,13 @@ long WrenchFamilyTransfer(CVars in, CVars &out){
|
||||
out["status"] = "Send Error";
|
||||
return ret;
|
||||
}
|
||||
CVars inx;
|
||||
inx["member_id"] = in["member_id"]; inx["member_id"].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 );
|
||||
|
||||
return WrenchFamilyPayment( inx, out );
|
||||
|
||||
out["status"] = "OK";
|
||||
out["exchange_rate"] ="1";
|
||||
|
||||
@@ -112,6 +112,95 @@ long WrenchMemberTopupPayment( CVars in, CVars &out )
|
||||
logfmt(FLOG_MAX, "/ long WrenchMemberTopupPayment(CVars in, CVars &out)" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
long WrenchFamilyPayment( CVars in, CVars &out )
|
||||
{
|
||||
logfmt(FLOG_MAX, "long WrenchFamilyPayment(CVars in, CVars &out)" );
|
||||
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, "currency", 2, 20, "(.*)");
|
||||
REQ_STRING(in, "origing_wallet_uid", 2, 50, "(.*)");
|
||||
|
||||
// REQ_STRING (in, "code", 4, 15, "(.*)");
|
||||
long code_id = 0; /// REQ_LONG( in, "code_id", 1, -1 );
|
||||
|
||||
// let us make sure you have the wallet
|
||||
// do we have a wallet for this action
|
||||
CVars vw;
|
||||
vw["currency"] = in["currency"];
|
||||
vw["currency"].set_valid( true );
|
||||
long wallet_id = CheckWallet(member_id,vw);
|
||||
if(!wallet_id || wallet_id == 0 ){
|
||||
out["status"] = "wallet_not_found";
|
||||
return ret; // no wallet
|
||||
}
|
||||
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)
|
||||
{ in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true );
|
||||
logfmt(FLOG_MAX, "Current balance Read ********************" );
|
||||
}
|
||||
else {
|
||||
out["status"] = "wallet_balance_not_found";
|
||||
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 );
|
||||
if (retDb2)
|
||||
{
|
||||
in["coupon_amount"] =out["amount"]; in["coupon_amount"].set_valid( true );
|
||||
|
||||
CVars x;
|
||||
x["member_id"] = member_id; x["member_id"].set_valid( true );
|
||||
x["code"] = "COUP"; x["code"].set_valid( true );
|
||||
x["dir"] = "1"; 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["coupon_amount"]; x["amount"].set_valid( true );
|
||||
x["fee"] = "0"; x["fee"].set_valid( true );
|
||||
|
||||
// x["what_offer"] = offer_id; x["what_offer"].set_valid( true );
|
||||
x["what_coupon"] = code_id; x["what_coupon"].set_valid( true ); // assign coupon id
|
||||
|
||||
|
||||
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
|
||||
|
||||
UpdateMemberWallet( x["member_id"].Long(), 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 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 );
|
||||
} else {
|
||||
out["status"] = "Unable to create payment";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{ out["status"] = "Invalid coupon";
|
||||
ret= PHP_API_BAD_PARAM;
|
||||
}
|
||||
|
||||
logfmt(FLOG_MAX, "/long WrenchFamilyPayment(CVars in, CVars &out)" );
|
||||
return ret;
|
||||
}
|
||||
|
||||
long WrenchMemberCouponPayment( CVars in, CVars &out )
|
||||
{
|
||||
logfmt(FLOG_MAX, "long WrenchMemberCouponPayment(CVars in, CVars &out)" );
|
||||
|
||||
Reference in New Issue
Block a user