2 Commits

Author SHA1 Message Date
ameye ea4f941637 fix 2022-08-08 07:32:09 -04:00
ameye 7aa911b1f7 fix 2022-08-08 07:32:05 -04:00
4 changed files with 95 additions and 21 deletions
+5 -2
View File
@@ -393,12 +393,15 @@ long WrenchBoardCompleteBalanceTopup(CVars in, CVars &out){
REQ_STRING(in, "transaction_id", 2, 50, "(.*)");
REQ_LONG(in, "status", 1, -1);
res = pgsql_query("SELECT id AS trx_id FROM flutterwave_payments WHERE tx_ref = '%s' AND status=0",in["tx_ref"].c_str());
res = pgsql_query("SELECT id AS trx_id,member_id FROM flutterwave_payments WHERE tx_ref = '%s' AND status=0",in["tx_ref"].c_str());
if (res != NULL && pgsql_num_rows(res) > 0) {
map<const char*, const char*>f = pgsql_fetch_assoc(res, 0);
CVars rec;
map_to_cvars(f, rec);
in["member_id"] = rec["member_id"]; in["member_id"].set_valid( true );
in["trx_id"] = rec["trx_id"]; in["trx_id"].set_valid( true );
pgsql_exec("UPDATE flutterwave_payments SET transaction_id = '%s', " \
"status=%lu,updated=now() WHERE id = %lu AND status=0 AND " \
"tx_ref='%s'", in["transaction_id"].c_str(),in["status"].Long(),rec["trx_id"].Long(), in["tx_ref"].c_str());
+78 -1
View File
@@ -32,7 +32,84 @@ long UpdateMemberWallet(long member_id,long wallet_id,long amount, long payment_
long WrenchMemberTopupPayment( CVars in, CVars &out )
{
logfmt(FLOG_MAX, "long WrenchMemberTopupPayment(CVars in, CVars &out)" );
logfmt(FLOG_MAX, "long WrenchMemberTopupPayment(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, "tx_ref", 4, 50, "(.*)");
long trx_id = REQ_LONG( in, "trx_id", 1, -1 );
// let us make sure you have the wallet
// do we have a wallet for this action
CVars vw;
vw["currency"] = "NAIRA"; // this might become a variable based on the country
vw["currency"].set_valid( true );
long wallet_id = CheckWallet(member_id,vw);
if(!wallet_id || wallet_id == 0 ){
return -1; // 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' ", member_id, vw["currency"].c_str());
if (retDb)
{ in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true );
logfmt(FLOG_MAX, "Current balance Read ********************" );
}
else { return -1; /* unable to read wallet*/ }
long retDb2 = load_db_record( out, "SELECT * FROM flutterwave_payments WHERE member_id = %lu AND tx_ref ='%s' AND id = %lu AND status = 5", in["member_id"].Long(), in["tx_ref"].c_str(),trx_id );
if (retDb2)
{
in["amount"] =out["amount"]; in["amount"].set_valid( true );
CVars x;
x["member_id"] = member_id; x["member_id"].set_valid( true );
x["code"] = "TOPUP"; 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["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_fluwv"] = trx_id; x["what_fluwv"].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 flutterwave_payments SET payment_id=%lu, completed = now() WHERE id = %lu AND member_id=%lu ",payment_id,trx_id,member_id );
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 WrenchMemberTopupPayment(CVars in, CVars &out)" );
return 0;
}
long WrenchMemberCouponPayment( CVars in, CVars &out )
+11 -17
View File
@@ -644,28 +644,21 @@ class Member extends Users_Controller {
//*************GET MOST OF THESE DATA FROM BACKEND */
$in=[];
$in['amount'] = $data['amount'];
$in=[];
$out = array();
$res = -1;
$in['amount'] = $data['amount']*100;
$in['member_id'] = $_SESSION['member_id']; // just maing sure
$in['currency'] = "NGN";
$in['action'] = WRENCHBOARD_ACCOUNT_PREPARE_TOPUP;
$this->load->model('backend_model');
$out = array();
$res = $this->backend_model->wrenchboard_api($in, $out);
if ($in['amount'] > 0 ){
$in['action'] = WRENCHBOARD_ACCOUNT_PREPARE_TOPUP;
$this->load->model('backend_model');
$res = $this->backend_model->wrenchboard_api($in, $out);
}
if ($res > 0) {
// prepare the fullter parameters
/*
*
* 12:16:52.238 INFO [237499]: RET: consumer_id=1
- 12:16:52.238 INFO [237499]: RET: consumer_mac=3119b744-42ad-4834-bb83-b737588754ca
- 12:16:52.238 INFO [237499]: RET: currency=NGN
- 12:16:52.238 INFO [237499]: RET: phone=
- 12:16:52.238 INFO [237499]: RET: result=YES I GET TO BACK END
- 12:16:52.238 INFO [237499]: RET: status=OK
- 12:16:52.238 INFO [237499]: RET: tx_ref=c30b3a20-b7f2-4324-b733-a9afa29dc7d1
* *
*/
$data['tx_ref'] = $out['tx_ref'];
$data['currency'] =$out['currency'];
$data['customer_email'] = $_SESSION['username'];
@@ -677,6 +670,7 @@ class Member extends Users_Controller {
$data['public_key'] = $out["public_key"]; //"FLWPUBK_TEST-54c90141b028789d671067bd72f781a9-X";
} else {
// very bad here
redirect('member/addfund');
}
@@ -8,7 +8,7 @@
<div class="card-header border-0 cursor-pointer" role="button" data-bs-toggle="collapse" data-bs-target="#kt_account_profile_details" aria-expanded="true" aria-controls="kt_account_profile_details">
<!--begin::Card title-->
<div class="card-title m-0">
<h3 class="fw-bolder m-0">Add Credit with Account Deposit</h3>
<h3 class="fw-bolder m-0">Confirm Credit with Account Deposit</h3>
</div>
<!--end::Card title-->
</div>