Buy Package with Balance

This commit is contained in:
Ibnu Maksum
2023-08-18 14:01:59 +07:00
parent 2c7d0a321e
commit ac4c98ca63
4 changed files with 53 additions and 8 deletions

View File

@ -97,7 +97,7 @@ switch ($action) {
}
}
if (empty($trx)) {
r2(U . "home", 'e', Lang::T("Transaction Not found"));
r2(U . "order", 'e', Lang::T("Transaction Not found"));
}
$router = ORM::for_table('tbl_routers')->find_one($trx['routers_id']);
$plan = ORM::for_table('tbl_plans')->find_one($trx['plan_id']);
@ -109,6 +109,30 @@ switch ($action) {
$ui->assign('_title', 'TRX #' . $trxid);
$ui->display('user-orderView.tpl');
break;
case 'pay':
if ($_c['enable_balance'] != 'yes'){
r2(U . "order", 'e', Lang::T("Balance not enabled"));
}
$plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3']);
$router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2']);
if (empty($router) || empty($plan)) {
r2(U . "order/package", 'e', Lang::T("Plan Not found"));
}
if ($plan && $plan['enabled'] && $user['balance'] >= $plan['price']) {
if (Package::rechargeUser($user['id'], $plan['routers'], $plan['id'], 'Customer', 'Balance')) {
// if success, then get the balance
Balance::min($user['id'], $plan['price']);
r2(U . "home", 's', Lang::T("Success to buy package"));
} else {
r2(U . "order/package", 'e', Lang::T("Failed to buy package"));
Message::sendTelegram("Buy Package with Balance Failed\n\n#u$c[username] #buy \n" . $plan['name_plan'] .
"\nRouter: " . $router_name .
"\nPrice: " . $p['price']);
}
}else{
echo "no renewall | plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n";
}
break;
case 'buy':
if (strpos($user['email'], '@') === false) {
r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address"));

View File

@ -142,7 +142,7 @@ foreach ($d as $ds) {
// if success, then get the balance
Balance::min($ds['customer_id'], $p['price']);
} else {
Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] .
Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #PPPOE \n" . $p['name_plan'] .
"\nRouter: " . $router_name .
"\nPrice: " . $p['price']);
}

View File

@ -365,3 +365,6 @@ $_L['Enable_auto_renewal'] = 'Enable auto renewal?';
$_L['Auto_Renewal_Off'] = 'Auto Renewal Off';
$_L['Refill_Balance'] = 'Refill Balance';
$_L['Invoice_Footer'] = 'Invoice Footer';
$_L['Pay_With_Balance'] = 'Pay With Balance';
$_L['Pay_this_with_Balance_your_active_package_will_be_overwrite'] = 'Pay this with Balance? your active package will be overwrite';
$_L['Success_to_buy_package'] = 'Success to buy package';