plugin system for payment gateway

This commit is contained in:
Ibnu Maksum
2022-09-16 11:05:33 +07:00
parent 0bd6c9e3c7
commit 061224b469
17 changed files with 598 additions and 815 deletions

View File

@ -5,206 +5,51 @@
_admin();
$ui->assign('_system_menu', 'paymentgateway');
$action = $routes['1'];
$action = alphanumeric($routes['1']);
$admin = Admin::_info();
$ui->assign('_admin', $admin);
switch ($action) {
case 'xendit':
$ui->assign('_title', 'Xendit - Payment Gateway - '. $config['CompanyName']);
$ui->assign('channels', json_decode(file_get_contents('system/paymentgateway/channel_xendit.json'), true));
$ui->display('pg-xendit.tpl');
break;
case 'xendit-post':
$xendit_secret_key = _post('xendit_secret_key');
$xendit_verification_token = _post('xendit_verification_token');
$d = ORM::for_table('tbl_appconfig')->where('setting', 'xendit_secret_key')->find_one();
if($d){
$d->value = $xendit_secret_key;
$d->save();
if(file_exists('system/paymentgateway/'.$action.'.php')){
include 'system/paymentgateway/'.$action.'.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if(function_exists($action.'_save_config')){
call_user_func($action.'_save_config');
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'xendit_secret_key';
$d->value = $xendit_secret_key;
$d->save();
$ui->display('a404.tpl');
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'xendit_verification_token')->find_one();
if($d){
$d->value = $xendit_verification_token;
$d->save();
}else{
if(function_exists($action.'_show_config')){
call_user_func($action.'_show_config');
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'xendit_verification_token';
$d->value = $xendit_verification_token;
$d->save();
$ui->display('a404.tpl');
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'xendit_channel')->find_one();
if($d){
$d->value = implode(',',$_POST['xendit_channel']);
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'xendit_channel';
$d->value = implode(',',$_POST['xendit_channel']);
$d->save();
}
}else{
if(!empty($action)){
r2(U . 'paymentgateway', 'w', Lang::T('Payment Gateway Not Found'));
}else{
$files = scandir('system/paymentgateway/');
foreach($files as $file){
if(pathinfo($file, PATHINFO_EXTENSION)=='php'){
$pgs[] = str_replace('.php','',$file);
}
}
_log('[' . $admin['username'] . ']: Xendit ' . $_L['Settings_Saved_Successfully'], 'Admin', $admin['id']);
r2(U . 'paymentgateway/xendit', 's', $_L['Settings_Saved_Successfully']);
break;
case 'midtrans':
$ui->assign('_title', 'Midtrans - Payment Gateway - '. $config['CompanyName']);
$ui->assign('channels', json_decode(file_get_contents('system/paymentgateway/channel_midtrans.json'), true));
$ui->display('pg-midtrans.tpl');
break;
case 'midtrans-post':
$midtrans_merchant_id = _post('midtrans_merchant_id');
$midtrans_client_key = _post('midtrans_client_key');
$midtrans_server_key = _post('midtrans_server_key');
$d = ORM::for_table('tbl_appconfig')->where('setting', 'midtrans_merchant_id')->find_one();
if($d){
$d->value = $midtrans_merchant_id;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'midtrans_merchant_id';
$d->value = $midtrans_merchant_id;
$d->save();
if(isset($_POST['payment_gateway'])){
$payment_gateway = _post('payment_gateway');
$d = ORM::for_table('tbl_appconfig')->where('setting', 'payment_gateway')->find_one();
if($d){
$d->value = $payment_gateway;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'payment_gateway';
$d->value = $payment_gateway;
$d->save();
}
r2(U . 'paymentgateway', 's', Lang::T('Payment Gateway saved successfully'));
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'midtrans_client_key')->find_one();
if($d){
$d->value = $midtrans_client_key;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'midtrans_client_key';
$d->value = $midtrans_client_key;
$d->save();
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'midtrans_server_key')->find_one();
if($d){
$d->value = $midtrans_server_key;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'midtrans_server_key';
$d->value = $midtrans_server_key;
$d->save();
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'midtrans_channel')->find_one();
if($d){
$d->value = implode(',',$_POST['midtrans_channel']);
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'midtrans_channel';
$d->value = implode(',',$_POST['midtrans_channel']);
$d->save();
}
_log('[' . $admin['username'] . ']: Midtrans ' . $_L['Settings_Saved_Successfully'], 'Admin', $admin['id']);
r2(U . 'paymentgateway/midtrans', 's', $_L['Settings_Saved_Successfully']);
break;
case 'tripay':
$ui->assign('_title', 'Tripay - Payment Gateway - '. $config['CompanyName']);
$ui->assign('channels', json_decode(file_get_contents('system/paymentgateway/channel_tripay.json'), true));
$ui->display('pg-tripay.tpl');
break;
case 'tripay-post':
$tripay_merchant = _post('tripay_merchant');
$tripay_api_key = _post('tripay_api_key');
$tripay_secret_key = _post('tripay_secret_key');
$d = ORM::for_table('tbl_appconfig')->where('setting', 'tripay_merchant')->find_one();
if($d){
$d->value = $tripay_merchant;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'tripay_merchant';
$d->value = $tripay_merchant;
$d->save();
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'tripay_api_key')->find_one();
if($d){
$d->value = $tripay_api_key;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'tripay_api_key';
$d->value = $tripay_api_key;
$d->save();
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'tripay_secret_key')->find_one();
if($d){
$d->value = $tripay_secret_key;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'tripay_secret_key';
$d->value = $tripay_secret_key;
$d->save();
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'tripay_channel')->find_one();
if($d){
$d->value = implode(',',$_POST['tripay_channel']);
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'tripay_channel';
$d->value = implode(',',$_POST['tripay_channel']);
$d->save();
}
_log('[' . $admin['username'] . ']: Tripay ' . $_L['Settings_Saved_Successfully'].json_encode($_POST['tripay_channel']), 'Admin', $admin['id']);
r2(U . 'paymentgateway/tripay', 's', $_L['Settings_Saved_Successfully']);
break;
case 'duitku':
$ui->assign('_title', 'Duitku - Payment Gateway - '. $config['CompanyName']);
$ui->assign('channels', json_decode(file_get_contents('system/paymentgateway/channel_duitku.json'), true));
$ui->display('pg-duitku.tpl');
break;
case 'duitku-post':
$duitku_merchant_id = _post('duitku_merchant_id');
$duitku_merchant_key = _post('duitku_merchant_key');
$d = ORM::for_table('tbl_appconfig')->where('setting', 'duitku_merchant_id')->find_one();
if($d){
$d->value = $duitku_merchant_id;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'duitku_merchant_id';
$d->value = $duitku_merchant_id;
$d->save();
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'duitku_merchant_key')->find_one();
if($d){
$d->value = $duitku_merchant_key;
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'duitku_merchant_key';
$d->value = $duitku_merchant_key;
$d->save();
}
$d = ORM::for_table('tbl_appconfig')->where('setting', 'duitku_channel')->find_one();
if($d){
$d->value = implode(',',$_POST['duitku_channel']);
$d->save();
}else{
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'duitku_channel';
$d->value = implode(',',$_POST['duitku_channel']);
$d->save();
}
_log('[' . $admin['username'] . ']: Duitku ' . $_L['Settings_Saved_Successfully'], 'Admin', $admin['id']);
r2(U . 'paymentgateway/duitku', 's', $_L['Settings_Saved_Successfully']);
break;
default:
$ui->display('a404.tpl');
}
$ui->assign('_title', 'Payment Gateway Settings - '. $config['CompanyName']);
$ui->assign('pgs', $pgs);
$ui->display('paymentgateway.tpl');
}
}