diff --git a/wrenchboard/src/include/payments.h b/wrenchboard/src/include/payments.h index 895fc6a0..8c15ea04 100644 --- a/wrenchboard/src/include/payments.h +++ b/wrenchboard/src/include/payments.h @@ -15,6 +15,7 @@ long WrenchCardRechargePayment( CVars in, CVars &out ); 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 ); #endif diff --git a/wrenchboard/src/shared_tool/account.cc b/wrenchboard/src/shared_tool/account.cc index 9cb08339..cefd04c1 100644 --- a/wrenchboard/src/shared_tool/account.cc +++ b/wrenchboard/src/shared_tool/account.cc @@ -384,24 +384,32 @@ long account_calls(CVars in, CVars &out) { #define PHP_API_TRANSFER_COMPLETE 200 long WrenchBoardCompleteBalanceTopup(CVars in, CVars &out){ - logfmt(logINFO, "WrenchBoardStartBalanceTopup()"); + logfmt(logINFO, "WrenchBoardCompleteBalanceTopup()"); long trx_id = 0; + const PGresult *res; + try { REQ_STRING(in, "tx_ref", 2, 50, "(.*)"); REQ_STRING(in, "transaction_id", 2, 50, "(.*)"); - REQ_STRING(in, "status", 2, 50, "(.*)"); - - /* - - $in['tx_ref'] = $this->input->get('tx_ref'); - $in['transaction_id'] = $this->input->get('transaction_id'); - $in['status'] = $this->input->get('status'); - - */ + 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()); + if (res != NULL && pgsql_num_rows(res) > 0) { + mapf = pgsql_fetch_assoc(res, 0); + CVars rec; + map_to_cvars(f, rec); + + 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()); + + if ( in["status"].Long() == 5){ + return WrenchMemberTopupPayment( in, out ); // This start the actual crediting + } + } out["status"] = "OK"; } catch (bad_parameter) { - logfmt(logINFO, "ERROR CALL long WrenchBoardStartBalanceTopup(CVars in, CVars &out)"); + logfmt(logINFO, "ERROR CALL long WrenchBoardCompleteBalanceTopup(CVars in, CVars &out)"); } return trx_id; } diff --git a/wrenchboard/src/shared_tool/payments.cc b/wrenchboard/src/shared_tool/payments.cc index 6752217f..a8dff9d6 100644 --- a/wrenchboard/src/shared_tool/payments.cc +++ b/wrenchboard/src/shared_tool/payments.cc @@ -30,6 +30,11 @@ INSERT INTO payment_types(type_code,code,dir) VALUES('OFFER_PYM_REFUND','OFRFD', */ long UpdateMemberWallet(long member_id,long wallet_id,long amount, long payment_id); +long WrenchMemberTopupPayment( CVars in, CVars &out ) +{ + logfmt(FLOG_MAX, "long WrenchMemberTopupPayment(CVars in, CVars &out)" ); + return 0; +} long WrenchMemberCouponPayment( CVars in, CVars &out ) { logfmt(FLOG_MAX, "long WrenchMemberCouponPayment(CVars in, CVars &out)" );