From 3c218d9ec9830b43c3b8d7ffab19b0a4864fed09 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 7 Aug 2024 09:51:37 +0700 Subject: [PATCH] Change UI and code payment gateway audit --- system/autoload/Lang.php | 12 -- system/autoload/Text.php | 26 ++++ system/controllers/paymentgateway.php | 164 +++++++++++++------------- ui/ui/paymentgateway-audit-view.tpl | 22 +++- 4 files changed, 127 insertions(+), 97 deletions(-) diff --git a/system/autoload/Lang.php b/system/autoload/Lang.php index 5b3f42ed..c6328293 100644 --- a/system/autoload/Lang.php +++ b/system/autoload/Lang.php @@ -259,16 +259,4 @@ class Lang } } - // echo Json array to text - public static function jsonArray2text($array, $start = '', $result = '') - { - foreach ($array as $k => $v) { - if (is_array($v)) { - $result .= self::jsonArray2text($v, "$start$k.", ''); - } else { - $result .= "$start$k = " . strval($v) . "\n"; - } - } - return $result; - } } diff --git a/system/autoload/Text.php b/system/autoload/Text.php index 92867869..45793b26 100644 --- a/system/autoload/Text.php +++ b/system/autoload/Text.php @@ -83,4 +83,30 @@ class Text return $datalimit; } } + + // echo Json array to text + public static function jsonArray2text($array, $start = '', $result = '') + { + foreach ($array as $k => $v) { + if (is_array($v)) { + $result .= self::jsonArray2text($v, "$start$k.", ''); + } else { + $result .= "$start$k = " . strval($v) . "\n"; + } + } + return $result; + } + + public static function jsonArray21Array($array){ + $text = self::jsonArray2text($array); + $lines = explode("\n", $text); + $result = []; + foreach($lines as $line){ + $parts = explode(' = ', $line); + if(count($parts) == 2){ + $result[trim($parts[0])] = trim($parts[1]); + } + } + return $result; + } } diff --git a/system/controllers/paymentgateway.php b/system/controllers/paymentgateway.php index a22f848b..7183551f 100644 --- a/system/controllers/paymentgateway.php +++ b/system/controllers/paymentgateway.php @@ -10,93 +10,91 @@ $ui->assign('_system_menu', 'paymentgateway'); $action = alphanumeric($routes[1]); $ui->assign('_admin', $admin); - -if ($action == 'delete') { - $pg = alphanumeric($routes[2]); - if (file_exists($PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $pg . '.php')) { - deleteFile($PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR, $pg); - } - r2(U . 'paymentgateway', 's', Lang::T('Payment Gateway Deleted')); -} - -if ($action == 'audit') { - $pg = alphanumeric($routes[2]); - $q = alphanumeric(_req('q'),'-._ '); - $query = ORM::for_table('tbl_payment_gateway')->order_by_desc("id"); - $query->selects('id', 'username', 'gateway', 'gateway_trx_id', 'plan_id', 'plan_name', 'routers_id', 'routers', 'price', 'pg_url_payment', 'payment_method', 'payment_channel', 'expired_date', 'created_date', 'paid_date', 'trx_invoice', 'status'); - $query->where('gateway', $pg); - if(!empty($q)) { - $query->whereRaw("(gateway_trx_id LIKE '%$q%' OR username LIKE '%$q%' OR routers LIKE '%$q%' OR plan_name LIKE '%$q%')"); - $append_url = 'q='. urlencode($q); - } - $pgs = Paginator::findMany($query, ["search" => $search], 50, $append_url); - - $ui->assign('_title', 'Payment Gateway Audit'); - $ui->assign('pgs', $pgs); - $ui->assign('pg', $pg); - $ui->assign('q', $q); - $ui->display('paymentgateway-audit.tpl'); - die(); -} - -if ($action == 'auditview') { - $pg = alphanumeric($routes[2]); - - $d = ORM::for_table('tbl_payment_gateway')->find_one($pg); - $ui->assign('_title', 'Payment Gateway Audit View'); - $ui->assign('pg', $d); - $ui->display('paymentgateway-audit-view.tpl'); - die(); -} - -if (_post('save') == 'actives') { - $pgs = ''; - if(is_array($_POST['pgs'])){ - $pgs = implode(',', $_POST['pgs']); - } - $d = ORM::for_table('tbl_appconfig')->where('setting', 'payment_gateway')->find_one(); - if ($d) { - $d->value = $pgs; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'payment_gateway'; - $d->value = $pgs; - $d->save(); - } - r2(U . 'paymentgateway', 's', Lang::T('Payment Gateway saved successfully')); -} - -if (file_exists($PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $action . '.php')) { - include $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $action . '.php'; - if ($_SERVER['REQUEST_METHOD'] === 'POST') { - if (function_exists($action . '_save_config')) { - call_user_func($action . '_save_config'); - } else { - $ui->display('a404.tpl'); +switch ($action) { + case 'delete': + $pg = alphanumeric($routes[2]); + if (file_exists($PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $pg . '.php')) { + deleteFile($PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR, $pg); } - } else { - if (function_exists($action . '_show_config')) { - call_user_func($action . '_show_config'); - } else { - $ui->display('a404.tpl'); + r2(U . 'paymentgateway', 's', Lang::T('Payment Gateway Deleted')); + + case 'audit': + $pg = alphanumeric($routes[2]); + $q = alphanumeric(_req('q'), '-._ '); + $query = ORM::for_table('tbl_payment_gateway')->order_by_desc("id"); + $query->selects('id', 'username', 'gateway', 'gateway_trx_id', 'plan_id', 'plan_name', 'routers_id', 'routers', 'price', 'pg_url_payment', 'payment_method', 'payment_channel', 'expired_date', 'created_date', 'paid_date', 'trx_invoice', 'status'); + $query->where('gateway', $pg); + if (!empty($q)) { + $query->whereRaw("(gateway_trx_id LIKE '%$q%' OR username LIKE '%$q%' OR routers LIKE '%$q%' OR plan_name LIKE '%$q%')"); + $append_url = 'q=' . urlencode($q); } - } -} else { - if (!empty($action)) { - r2(U . 'paymentgateway', 'w', Lang::T('Payment Gateway Not Found')); - } else { - $files = scandir($PAYMENTGATEWAY_PATH); - foreach ($files as $file) { - if (pathinfo($file, PATHINFO_EXTENSION) == 'php') { - $pgs[] = str_replace('.php', '', $file); + $pgs = Paginator::findMany($query, ["search" => $search], 50, $append_url); + + $ui->assign('_title', 'Payment Gateway Audit'); + $ui->assign('pgs', $pgs); + $ui->assign('pg', $pg); + $ui->assign('q', $q); + $ui->display('paymentgateway-audit.tpl'); + break; + case 'auditview': + $pg = alphanumeric($routes[2]); + $d = ORM::for_table('tbl_payment_gateway')->find_one($pg); + $d['pg_request'] = (!empty($d['pg_request']))? Text::jsonArray21Array(json_decode($d['pg_request'], true)) : []; + $d['pg_paid_response'] = (!empty($d['pg_paid_response']))? Text::jsonArray21Array(json_decode($d['pg_paid_response'], true)) : []; + $ui->assign('_title', 'Payment Gateway Audit View'); + $ui->assign('pg', $d); + $ui->display('paymentgateway-audit-view.tpl'); + break; + default: + if (_post('save') == 'actives') { + $pgs = ''; + if (is_array($_POST['pgs'])) { + $pgs = implode(',', $_POST['pgs']); + } + $d = ORM::for_table('tbl_appconfig')->where('setting', 'payment_gateway')->find_one(); + if ($d) { + $d->value = $pgs; + $d->save(); + } else { + $d = ORM::for_table('tbl_appconfig')->create(); + $d->setting = 'payment_gateway'; + $d->value = $pgs; + $d->save(); + } + r2(U . 'paymentgateway', 's', Lang::T('Payment Gateway saved successfully')); + } + + if (file_exists($PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $action . '.php')) { + include $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR . $action . '.php'; + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (function_exists($action . '_save_config')) { + call_user_func($action . '_save_config'); + } else { + $ui->display('a404.tpl'); + } + } else { + if (function_exists($action . '_show_config')) { + call_user_func($action . '_show_config'); + } else { + $ui->display('a404.tpl'); + } + } + } else { + if (!empty($action)) { + r2(U . 'paymentgateway', 'w', Lang::T('Payment Gateway Not Found')); + } else { + $files = scandir($PAYMENTGATEWAY_PATH); + foreach ($files as $file) { + if (pathinfo($file, PATHINFO_EXTENSION) == 'php') { + $pgs[] = str_replace('.php', '', $file); + } + } + $ui->assign('_title', 'Payment Gateway Settings'); + $ui->assign('pgs', $pgs); + $ui->assign('actives', explode(',', $config['payment_gateway'])); + $ui->display('paymentgateway.tpl'); } } - $ui->assign('_title', 'Payment Gateway Settings'); - $ui->assign('pgs', $pgs); - $ui->assign('actives', explode(',', $config['payment_gateway'])); - $ui->display('paymentgateway.tpl'); - } } diff --git a/ui/ui/paymentgateway-audit-view.tpl b/ui/ui/paymentgateway-audit-view.tpl index 844f6fb0..a72838a7 100644 --- a/ui/ui/paymentgateway-audit-view.tpl +++ b/ui/ui/paymentgateway-audit-view.tpl @@ -67,13 +67,31 @@
Response when request payment
-
{if $pg['pg_request'] != null}{Lang::jsonArray2text(json_decode($pg['pg_request'], true))}{/if}
+
+ + {foreach $pg['pg_request'] as $k => $v} + + + + + {/foreach} +
{$k}{$v}
+
Response when payment PAID
-
{if $pg['pg_request'] != null}{Lang::jsonArray2text(json_decode($pg['pg_paid_response'], true))}{/if}
+
+ + {foreach $pg['pg_paid_response'] as $k => $v} + + + + + {/foreach} +
{$k}{$v}
+
{include file="sections/footer.tpl"} \ No newline at end of file