Fix Logic Multiple Payment gateway

This commit is contained in:
Ibnu Maksum 2024-03-12 09:33:45 +07:00
parent 8f0ff3e786
commit e1f7b324cb
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -114,7 +114,7 @@ switch ($action) {
run_hook('customer_check_payment_status'); #HOOK run_hook('customer_check_payment_status'); #HOOK
include $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $trx['gateway'] . '.php'; include $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $trx['gateway'] . '.php';
call_user_func($trx['gateway'] . '_validate_config'); call_user_func($trx['gateway'] . '_validate_config');
call_user_func($config['payment_gateway'] . '_get_status', $trx, $user); call_user_func($trx['gateway'] . '_get_status', $trx, $user);
} else if ($routes['3'] == 'cancel') { } else if ($routes['3'] == 'cancel') {
run_hook('customer_cancel_payment'); #HOOK run_hook('customer_cancel_payment'); #HOOK
$trx->pg_paid_response = '{}'; $trx->pg_paid_response = '{}';
@ -266,16 +266,12 @@ switch ($action) {
$ui->assign('plan', $plan); $ui->assign('plan', $plan);
$ui->display('user-sendPlan.tpl'); $ui->display('user-sendPlan.tpl');
break; break;
case 'buy': case 'gateway':
$ui->assign('_title', Lang::T('Select Payment Gateway')); $ui->assign('_title', Lang::T('Select Payment Gateway'));
$ui->assign('_system_menu', 'package'); $ui->assign('_system_menu', 'package');
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"));
} }
if (!file_exists($PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $config['payment_gateway'] . '.php')) {
r2(U . 'home', 'e', Lang::T("No Payment Gateway Available"));
}
require_once $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $config['payment_gateway'] . '.php';
$files = scandir($PAYMENTGATEWAY_PATH); $files = scandir($PAYMENTGATEWAY_PATH);
foreach ($files as $file) { foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) == 'php') { if (pathinfo($file, PATHINFO_EXTENSION) == 'php') {
@ -290,12 +286,15 @@ switch ($action) {
$ui->display('user-selectGateway.tpl'); $ui->display('user-selectGateway.tpl');
break; break;
case 'pay_now': case 'buy':
$gateway = $_POST['gateway']; $gateway = _post('gateway');
//$routes[2] = $_GET['route2']; if (empty($gateway) && !empty($_SESSION['gateway'])) {
//$routes[3] = $_GET['route3']; $gateway = $_SESSION['gateway'];
if ($gateway == 'none') { } else if (!empty($gateway)) {
r2(U . 'order/buy/' . $routes[2] . '/' . $routes[3], 'e', Lang::T("No Payment Gateway Selected")); $_SESSION['gateway'] = $gateway;
}
if (empty($gateway)) {
r2(U . 'order/gateway/' . $routes[2] . '/' . $routes[3], 'w', Lang::T("Please select Payment Gateway"));
} }
run_hook('customer_buy_plan'); #HOOK run_hook('customer_buy_plan'); #HOOK
include $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $gateway . '.php'; include $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $gateway . '.php';
@ -322,7 +321,7 @@ switch ($action) {
if ($d['pg_url_payment']) { if ($d['pg_url_payment']) {
r2(U . "order/view/" . $d['id'], 'w', Lang::T("You already have unpaid transaction, cancel it or pay it.")); r2(U . "order/view/" . $d['id'], 'w', Lang::T("You already have unpaid transaction, cancel it or pay it."));
} else { } else {
if ($config['payment_gateway'] == $d['gateway']) { if ($gateway == $d['gateway']) {
$id = $d['id']; $id = $d['id'];
} else { } else {
$d->status = 4; $d->status = 4;
@ -333,7 +332,7 @@ switch ($action) {
if (empty($id)) { if (empty($id)) {
$d = ORM::for_table('tbl_payment_gateway')->create(); $d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $user['username']; $d->username = $user['username'];
$d->gateway = $config['payment_gateway']; $d->gateway = $gateway;
$d->plan_id = $plan['id']; $d->plan_id = $plan['id'];
$d->plan_name = $plan['name_plan']; $d->plan_name = $plan['name_plan'];
$d->routers_id = $router['id']; $d->routers_id = $router['id'];
@ -345,7 +344,7 @@ switch ($action) {
$id = $d->id(); $id = $d->id();
} else { } else {
$d->username = $user['username']; $d->username = $user['username'];
$d->gateway = $config['payment_gateway']; $d->gateway = $gateway;
$d->plan_id = $plan['id']; $d->plan_id = $plan['id'];
$d->plan_name = $plan['name_plan']; $d->plan_name = $plan['name_plan'];
$d->routers_id = $router['id']; $d->routers_id = $router['id'];
@ -358,7 +357,7 @@ switch ($action) {
if (!$id) { if (!$id) {
r2(U . "order/package/" . $d['id'], 'e', Lang::T("Failed to create Transaction..")); r2(U . "order/package/" . $d['id'], 'e', Lang::T("Failed to create Transaction.."));
} else { } else {
call_user_func($config['payment_gateway'] . '_create_transaction', $d, $user); call_user_func($gateway . '_create_transaction', $d, $user);
} }
break; break;
default: default: