diff --git a/wrenchboard/src/shared_tool/family_acc.cc b/wrenchboard/src/shared_tool/family_acc.cc index a930e2a6..f09ccfcf 100644 --- a/wrenchboard/src/shared_tool/family_acc.cc +++ b/wrenchboard/src/shared_tool/family_acc.cc @@ -497,10 +497,7 @@ long WrenchFamilyTransfer(CVars in, CVars &out){ CVars trx; if ( load_db_record(trx, "SELECT * FROM family_transfer WHERE id =%lu",family_transfer_id) > 0 ){ trx["transfer_id"] = family_transfer_id; trx["transfer_id"].set_valid( true ); - return WrenchFamilyPayment( trx, out ); - out["status"] = "OK"; - out["exchange_rate"] ="1"; - ret = PHP_API_OK; + return WrenchFamilyPayment( trx, out ); } else{ out["status"] = "System Error 02"; diff --git a/wrenchboard/src/shared_tool/payments.cc b/wrenchboard/src/shared_tool/payments.cc index 6a34a1ad..be224b40 100644 --- a/wrenchboard/src/shared_tool/payments.cc +++ b/wrenchboard/src/shared_tool/payments.cc @@ -176,7 +176,7 @@ long WrenchFamilyPayment( CVars in, CVars &out ) x["dir"] = "0"; 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["amount"] = out["amount"]; x["amount"].set_valid( true ); x["fee"] = "0"; x["fee"].set_valid( true ); x["what_family_transfer"] = transfer_id; x["what_family_transfer"].set_valid( true ); x["flags"] = FLAG_INIT; x["flags"].set_valid( true ); // starting the pprocess @@ -195,7 +195,7 @@ long WrenchFamilyPayment( CVars in, CVars &out ) pgsql_exec("UPDATE family_transfer SET pay_confirm = now() WHERE id = %lu ",confirmation, transfer_id ); CVars xrx; load_db_record( xrx, "SELECT id AS transfer_id, * FROM family_transfer WHERE id = %lu ", payment_id ); - return WrenchFamilyTransferCredit( xrx, out ); // let us try credit + return WrenchFamilyTransferCredit( xrx, out ); // let us try credit } else { out["status"] = "Unable to create payment"; } @@ -219,6 +219,63 @@ long WrenchFamilyTransferCredit( CVars in, CVars &out ){ in["loc"] = loc; in["loc"].set_valid(true); long transfer_id = REQ_LONG( in, "transfer_id", 1, -1 ); + long retDb2 = load_db_record( out, "SELECT * FROM family_transfer " + " WHERE member_id = %lu " + " AND currency ='%s' " + " AND pay_confirm IS NOT NULL AND credit_confirm IS NULL " + " AND id = %lu AND status = 1 ", in["member_id"].Long(), in["currency"].c_str(),transfer_id ); + + if (retDb2>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'", out["recipient"].Long(), out["currency"].c_str(), out["target_wallet"].c_str()); + if (retDb > 0 ) + { 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*/ } + + + CVars x; + x["member_id"] = out["recipient"]; x["member_id"].set_valid( true ); // the recipient on family table + x["code"] = "FAMCR"; 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"] = out["amount"]; x["amount"].set_valid( true ); + x["fee"] = "0"; x["fee"].set_valid( true ); + x["what_family_transfer"] = transfer_id; x["what_family_transfer"].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 ); + + 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 family_transfer SET credit_confirm = now() WHERE id = %lu ",confirmation, transfer_id ); + CVars xrx; + load_db_record( xrx, "SELECT id AS transfer_id, * FROM family_transfer WHERE id = %lu ", payment_id ); + out["status"] = "OK"; + out["status_message"] = "trasnfer_completed"; + ret = PHP_API_OK; + } else { + out["status"] = "Unable to create payment"; + } + + } + else + { out["status"] = "error_invalid_credit"; + ret= PHP_API_BAD_PARAM; + } logfmt(FLOG_MAX, "OUT *** long WrenchFamilyTransferCredit(CVars in, CVars &out)" );