From 766ba5973431380b25cbee884d4c1366a9cdc21e Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 5 Apr 2024 10:42:30 +0700 Subject: [PATCH] add new field trx_invoice to tbl_payment_gateway, to know which transaction is for --- install/phpnuxbill.sql | 1 + system/autoload/Package.php | 20 ++++++++++++-------- system/controllers/order.php | 5 ++++- system/lan/indonesia.json | 5 ++++- system/updates.json | 3 +++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index 0d41fd30..2c775428 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -321,3 +321,4 @@ ALTER TABLE `tbl_transactions` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `ty ALTER TABLE `tbl_user_recharges` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `type`; ALTER TABLE `tbl_plans` CHANGE `allow_purchase` `prepaid` ENUM('yes','no') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'yes' COMMENT 'is prepaid'; ALTER TABLE `tbl_transactions` ADD `note` VARCHAR(256) NOT NULL DEFAULT '' COMMENT 'for note' AFTER `type`; +ALTER TABLE `tbl_payment_gateway` ADD `trx_invoice` VARCHAR(25) NOT NULL DEFAULT '' COMMENT 'from tbl_transactions' AFTER `paid_date`; \ No newline at end of file diff --git a/system/autoload/Package.php b/system/autoload/Package.php index a9bdd1a1..28a22ad0 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -15,15 +15,17 @@ class Package * @param int $plan_id plan id for this package * @param string $gateway payment gateway name * @param string $channel channel payment gateway + * @param array $pgids payment gateway ids * @return boolean */ public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel, $note = '') { - global $config, $admin, $c, $p, $b, $t, $d, $zero; + global $config, $admin, $c, $p, $b, $t, $d, $zero, $trx; $date_now = date("Y-m-d H:i:s"); $date_only = date("Y-m-d"); $time_only = date("H:i:s"); $time = date("H:i:s"); + $inv = ""; if ($id_customer == '' or $router_name == '' or $plan_id == '') { return false; @@ -76,9 +78,8 @@ class Package if ($router_name == 'balance') { // insert table transactions - $inv = "INV-" . Package::_raid(); $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = $inv; + $t->invoice = $inv = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; @@ -239,7 +240,7 @@ class Package // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . Package::_raid(); + $t->invoice = $inv = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; if ($p['validity_unit'] == 'Period') { @@ -323,7 +324,7 @@ class Package // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . Package::_raid(); + $t->invoice = $inv = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; if ($p['validity_unit'] == 'Period') { @@ -435,7 +436,7 @@ class Package // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . Package::_raid(); + $t->invoice = $inv = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; if ($p['validity_unit'] == 'Period') { @@ -518,7 +519,7 @@ class Package // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . Package::_raid(); + $t->invoice = $inv = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; if ($p['validity_unit'] == 'Period') { @@ -583,7 +584,10 @@ class Package } run_hook("recharge_user_finish"); Message::sendInvoice($c, $t); - return true; + if($trx){ + $trx->trx_invoice = $inv; + } + return $inv; } public static function changeTo($username, $plan_id, $from_id) diff --git a/system/controllers/order.php b/system/controllers/order.php index 0607297a..cca30dcc 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -221,7 +221,8 @@ switch ($action) { if ($active && $active['plan_id'] != $plan['id']) { r2(U . "order/package", 'e', Lang::T("Target has active plan, different with current plant.") . " [ $active[namebp] ]"); } - if (Package::rechargeUser($target['id'], $router_name, $plan['id'], $user['username'], 'Balance')) { + $result = Package::rechargeUser($target['id'], $router_name, $plan['id'], $user['username'], 'Balance'); + if (!empty($result)) { // if success, then get the balance Balance::min($user['id'], $plan['price']); //sender @@ -239,6 +240,7 @@ switch ($action) { $d->paid_date = date('Y-m-d H:i:s'); $d->expired_date = date('Y-m-d H:i:s'); $d->pg_url_payment = 'balance'; + $d->trx_invoice = $result; $d->status = 2; $d->save(); $trx_id = $d->id(); @@ -257,6 +259,7 @@ switch ($action) { $d->paid_date = date('Y-m-d H:i:s'); $d->expired_date = date('Y-m-d H:i:s'); $d->pg_url_payment = 'balance'; + $d->trx_invoice = $result; $d->status = 2; $d->save(); r2(U . "order/view/$trx_id", 's', Lang::T("Success to send package")); diff --git a/system/lan/indonesia.json b/system/lan/indonesia.json index 21094081..af3cc8ae 100644 --- a/system/lan/indonesia.json +++ b/system/lan/indonesia.json @@ -422,5 +422,8 @@ "success": "Sukses", "Click_Here": "Klik disini", "Your_friend_do_not_have_active_package": "Teman Anda tidak memiliki paket aktif", - "If_your_friend_have_Additional_Cost__you_will_pay_for_that_too": "Jika teman Anda memiliki Biaya Tambahan, Anda juga akan membayarnya" + "If_your_friend_have_Additional_Cost__you_will_pay_for_that_too": "Jika teman Anda memiliki Biaya Tambahan, Anda juga akan membayarnya", + "Select_Payment_Gateway": "Pilih Gerbang Pembayaran", + "Available_Payment_Gateway": "Gerbang Pembayaran yang Tersedia", + "Pay_Now": "Bayar sekarang" } \ No newline at end of file diff --git a/system/updates.json b/system/updates.json index cb0de143..a4eca5a1 100644 --- a/system/updates.json +++ b/system/updates.json @@ -90,5 +90,8 @@ ], "2023.3.20": [ "ALTER TABLE `tbl_customers` CHANGE `pppoe_password` `pppoe_password` VARCHAR(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login';" + ], + "2024.4.5" : [ + "ALTER TABLE `tbl_payment_gateway` ADD `trx_invoice` VARCHAR(25) NOT NULL DEFAULT '' COMMENT 'from tbl_transactions' AFTER `paid_date`;" ] } \ No newline at end of file