phpnuxbill/system/controllers/order.php

168 lines
6.7 KiB
PHP
Raw Normal View History

2022-09-07 15:44:04 +08:00
<?php
2022-09-08 18:09:21 +08:00
2022-09-07 15:44:04 +08:00
/**
2022-09-08 18:09:21 +08:00
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
**/
2022-09-07 15:44:04 +08:00
_auth();
$ui->assign('_system_menu', 'order');
$action = $routes['1'];
$user = User::_info();
$ui->assign('_user', $user);
switch ($action) {
case 'voucher':
2022-10-13 15:00:54 +08:00
$ui->assign('_title', $_L['Order_Voucher']);
2022-09-18 01:00:40 +08:00
run_hook('customer_view_order'); #HOOK
2022-09-07 15:44:04 +08:00
$ui->display('user-order.tpl');
break;
2022-09-11 12:02:55 +08:00
case 'history':
$d = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->find_many();
2022-09-16 12:05:33 +08:00
$paginator = Paginator::bootstrap('tbl_payment_gateway', 'username', $user['username']);
$ui->assign('paginator', $paginator);
2022-09-11 12:02:55 +08:00
$ui->assign('d', $d);
2022-10-13 15:00:54 +08:00
$ui->assign('_title', Lang::T('Order History'));
2022-09-18 01:00:40 +08:00
run_hook('customer_view_order_history'); #HOOK
2022-09-11 12:02:55 +08:00
$ui->display('user-orderHistory.tpl');
break;
2022-09-10 13:17:38 +08:00
case 'package':
2022-10-13 15:00:54 +08:00
$ui->assign('_title', 'Order Plan');
2022-09-08 18:09:21 +08:00
$routers = ORM::for_table('tbl_routers')->find_many();
2022-09-10 13:17:38 +08:00
$plans = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many();
2022-09-08 18:09:21 +08:00
$ui->assign('routers', $routers);
2022-09-07 15:44:04 +08:00
$ui->assign('plans', $plans);
2022-09-18 01:00:40 +08:00
run_hook('customer_view_order_plan'); #HOOK
$ui->display('user-orderPlan.tpl');
2022-09-07 15:44:04 +08:00
break;
2022-09-10 13:17:38 +08:00
case 'unpaid':
$d = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->where('status', 1)
->find_one();
2022-09-18 01:00:40 +08:00
run_hook('customer_find_unpaid'); #HOOK
2022-09-16 12:05:33 +08:00
if ($d) {
2022-09-10 13:17:38 +08:00
if (empty($d['pg_url_payment'])) {
2022-09-16 12:05:33 +08:00
r2(U . "order/buy/" . $trx['routers_id'] . '/' . $trx['plan_id'], 'w', Lang::T("Checking payment"));
} else {
r2(U . "order/view/" . $d['id'] . '/check/', 's', Lang::T("You have unpaid transaction"));
2022-09-10 13:17:38 +08:00
}
2022-09-16 12:05:33 +08:00
} else {
2022-09-10 13:17:38 +08:00
r2(U . "order/package/", 's', Lang::T("You have no unpaid transaction"));
}
2022-09-08 18:09:21 +08:00
case 'view':
$trxid = $routes['2'] * 1;
$trx = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->find_one($trxid);
2022-09-18 01:00:40 +08:00
run_hook('customer_view_payment'); #HOOK
2022-09-16 12:05:33 +08:00
// jika tidak ditemukan, berarti punya orang lain
if (empty($trx)) {
r2(U . "order/package", 'w', Lang::T("Payment not found"));
}
2022-09-10 13:17:38 +08:00
// jika url kosong, balikin ke buy
if (empty($trx['pg_url_payment'])) {
2022-09-16 12:05:33 +08:00
r2(U . "order/buy/" . $trx['routers_id'] . '/' . $trx['plan_id'], 'w', Lang::T("Checking payment"));
2022-09-10 13:17:38 +08:00
}
2022-09-08 18:09:21 +08:00
if ($routes['3'] == 'check') {
2022-09-16 12:05:33 +08:00
if (!file_exists('system/paymentgateway/' . $trx['gateway'] . '.php')) {
r2(U . 'order/view/' . $trxid, 'e', Lang::T("No Payment Gateway Available"));
2022-09-08 18:09:21 +08:00
}
2022-09-18 01:00:40 +08:00
run_hook('customer_check_payment_status'); #HOOK
2022-09-16 12:05:33 +08:00
include 'system/paymentgateway/' . $trx['gateway'] . '.php';
call_user_func($trx['gateway'] . '_validate_config');
2022-09-21 15:15:00 +08:00
call_user_func($config['payment_gateway'] . '_get_status', $trx, $user);
2022-09-16 12:05:33 +08:00
2022-09-08 18:09:21 +08:00
} else if ($routes['3'] == 'cancel') {
2022-09-18 01:00:40 +08:00
run_hook('customer_cancel_payment'); #HOOK
2022-09-10 13:17:38 +08:00
$trx->pg_paid_response = '{}';
2022-09-08 18:09:21 +08:00
$trx->status = 4;
2022-09-10 13:17:38 +08:00
$trx->paid_date = date('Y-m-d H:i:s');
2022-09-08 18:09:21 +08:00
$trx->save();
$trx = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->find_one($trxid);
2022-09-16 12:05:33 +08:00
if ('midtrans' == $trx['gateway']) {
2022-09-10 13:17:38 +08:00
//Hapus invoice link
}
2022-09-08 18:09:21 +08:00
}
if (empty($trx)) {
r2(U . "home", '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']);
$bandw = ORM::for_table('tbl_bandwidth')->find_one($plan['id_bw']);
$ui->assign('trx', $trx);
$ui->assign('router', $router);
$ui->assign('plan', $plan);
$ui->assign('bandw', $bandw);
2022-10-13 15:00:54 +08:00
$ui->assign('_title', 'TRX #' . $trxid);
2022-09-08 18:09:21 +08:00
$ui->display('user-orderView.tpl');
break;
2022-09-10 13:17:38 +08:00
case 'buy':
2022-09-21 15:15:00 +08:00
if ($config['payment_gateway'] == 'none') {
2022-09-10 17:01:51 +08:00
r2(U . 'home', 'e', Lang::T("No Payment Gateway Available"));
}
2022-09-21 15:15:00 +08:00
if (!file_exists('system/paymentgateway/' . $config['payment_gateway'] . '.php')) {
2022-09-16 12:05:33 +08:00
r2(U . 'home', 'e', Lang::T("No Payment Gateway Available"));
}
2022-09-18 01:00:40 +08:00
run_hook('customer_buy_plan'); #HOOK
2022-09-21 15:15:00 +08:00
include 'system/paymentgateway/' . $config['payment_gateway'] . '.php';
call_user_func($config['payment_gateway'] . '_validate_config');
2022-09-16 12:05:33 +08:00
2022-09-08 18:09:21 +08:00
$router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2'] * 1);
$plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3'] * 1);
if (empty($router) || empty($plan)) {
2022-09-09 17:46:39 +08:00
r2(U . $back, 'e', Lang::T("Plan Not found"));
2022-09-08 18:09:21 +08:00
}
2022-09-09 17:46:39 +08:00
$d = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->where('status', 1)
->find_one();
2022-09-16 12:05:33 +08:00
if ($d) {
2022-09-10 13:17:38 +08:00
if ($d['pg_url_payment']) {
r2(U . "order/view/" . $d['id'], 'w', Lang::T("You already have unpaid transaction, cancel it or pay it."));
2022-09-16 12:05:33 +08:00
} else {
2022-09-21 15:15:00 +08:00
if ($config['payment_gateway'] == $d['gateway']) {
2022-09-10 13:17:38 +08:00
$id = $d['id'];
2022-09-16 12:05:33 +08:00
} else {
2022-09-10 13:17:38 +08:00
$d->status = 4;
$d->save();
}
2022-09-09 17:46:39 +08:00
}
}
2022-09-16 12:05:33 +08:00
if (empty($id)) {
2022-09-09 17:46:39 +08:00
$d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $user['username'];
2022-09-21 15:15:00 +08:00
$d->gateway = $config['payment_gateway'];
2022-09-09 17:46:39 +08:00
$d->plan_id = $plan['id'];
$d->plan_name = $plan['name_plan'];
$d->routers_id = $router['id'];
$d->routers = $router['name'];
$d->price = $plan['price'];
$d->created_date = date('Y-m-d H:i:s');
$d->status = 1;
$d->save();
$id = $d->id();
2022-09-16 12:05:33 +08:00
} else {
2022-09-14 17:54:29 +08:00
$d->username = $user['username'];
2022-09-21 15:15:00 +08:00
$d->gateway = $config['payment_gateway'];
2022-09-14 17:54:29 +08:00
$d->plan_id = $plan['id'];
$d->plan_name = $plan['name_plan'];
$d->routers_id = $router['id'];
$d->routers = $router['name'];
$d->price = $plan['price'];
$d->created_date = date('Y-m-d H:i:s');
$d->status = 1;
$d->save();
2022-09-09 17:46:39 +08:00
}
2022-09-16 12:05:33 +08:00
if (!$id) {
r2(U . "order/package/" . $d['id'], 'e', Lang::T("Failed to create Transaction.."));
} else {
2022-09-21 15:15:00 +08:00
call_user_func($config['payment_gateway'] . '_create_transaction', $d, $user);
2022-09-08 18:09:21 +08:00
}
break;
2022-09-07 15:44:04 +08:00
default:
$ui->display('404.tpl');
2022-09-16 12:05:33 +08:00
}