Buy Package with Balance

This commit is contained in:
Ibnu Maksum 2023-08-18 14:01:59 +07:00
parent 2c7d0a321e
commit ac4c98ca63
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
4 changed files with 53 additions and 8 deletions

View File

@ -97,7 +97,7 @@ switch ($action) {
} }
} }
if (empty($trx)) { 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']); $router = ORM::for_table('tbl_routers')->find_one($trx['routers_id']);
$plan = ORM::for_table('tbl_plans')->find_one($trx['plan_id']); $plan = ORM::for_table('tbl_plans')->find_one($trx['plan_id']);
@ -109,6 +109,30 @@ switch ($action) {
$ui->assign('_title', 'TRX #' . $trxid); $ui->assign('_title', 'TRX #' . $trxid);
$ui->display('user-orderView.tpl'); $ui->display('user-orderView.tpl');
break; 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': case 'buy':
if (strpos($user['email'], '@') === false) { if (strpos($user['email'], '@') === false) {
r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address")); 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 // if success, then get the balance
Balance::min($ds['customer_id'], $p['price']); Balance::min($ds['customer_id'], $p['price']);
} else { } 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 . "\nRouter: " . $router_name .
"\nPrice: " . $p['price']); "\nPrice: " . $p['price']);
} }

View File

@ -365,3 +365,6 @@ $_L['Enable_auto_renewal'] = 'Enable auto renewal?';
$_L['Auto_Renewal_Off'] = 'Auto Renewal Off'; $_L['Auto_Renewal_Off'] = 'Auto Renewal Off';
$_L['Refill_Balance'] = 'Refill Balance'; $_L['Refill_Balance'] = 'Refill Balance';
$_L['Invoice_Footer'] = 'Invoice Footer'; $_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';

View File

@ -33,6 +33,10 @@
{/foreach} {/foreach}
</div> </div>
</div> </div>
<div class="box box-solid box-success">
<div class="box-header text-center text-bold">{Lang::T('Balance')} {Lang::moneyFormat($_user['balance'])}</div>
</div>
{/if} {/if}
{foreach $routers as $router} {foreach $routers as $router}
<div class="box box-solid box-info"> <div class="box box-solid box-info">
@ -69,9 +73,16 @@
</table> </table>
</div> </div>
<div class="box-body"> <div class="box-body">
<a href="{$_url}order/buy/{$router['id']}/{$plan['id']}" <div class="btn-group btn-group-justified" role="group" aria-label="...">
onclick="return confirm('{Lang::T('Buy this? your active package will be overwrite')}')" <a href="{$_url}order/buy/{$router['id']}/{$plan['id']}"
class="btn btn-sm btn-block btn-primary">Buy</a> onclick="return confirm('{Lang::T('Buy this? your active package will be overwrite')}')"
class="btn btn-sm btn-block btn-warning text-black">Buy</a>
{if $_c['enable_balance'] == 'yes' && $_user['balance']>=$plan['price']}
<a href="{$_url}order/pay/{$router['id']}/{$plan['id']}"
onclick="return confirm('{Lang::T('Pay this with Balance? your active package will be overwrite')}')"
class="btn btn-sm btn-block btn-success">{Lang::T('Pay With Balance')}</a>
{/if}
</div>
</div> </div>
</div> </div>
</div> </div>
@ -106,9 +117,16 @@
</table> </table>
</div> </div>
<div class="box-body"> <div class="box-body">
<a href="{$_url}order/buy/{$router['id']}/{$plan['id']}" <div class="btn-group btn-group-justified" role="group" aria-label="...">
onclick="return confirm('{Lang::T('Buy this? your active package will be overwrite')}')" <a href="{$_url}order/buy/{$router['id']}/{$plan['id']}"
class="btn btn-sm btn-block btn-primary">Buy</a> onclick="return confirm('{Lang::T('Buy this? your active package will be overwrite')}')"
class="btn btn-sm btn-block btn-warning text-black">Buy</a>
{if $_c['enable_balance'] == 'yes' && $_user['balance']>=$plan['price']}
<a href="{$_url}order/pay/{$router['id']}/{$plan['id']}"
onclick="return confirm('{Lang::T('Pay this with Balance? your active package will be overwrite')}')"
class="btn btn-sm btn-block btn-success">{Lang::T('Pay With Balance')}</a>
{/if}
</div>
</div> </div>
</div> </div>
</div> </div>