From 64ae7240dc55717cbe494e808de9cdcc23c11be0 Mon Sep 17 00:00:00 2001 From: Daniel Neto Date: Mon, 17 Mar 2025 13:48:18 -0300 Subject: [PATCH] Update BTC interface --- plugin/BTCPayments/BTCPayments.php | 9 ++ plugin/BTCPayments/Objects/Btc_invoices.php | 30 ++++- .../View/Btc_invoices/list.json.php | 9 +- plugin/BTCPayments/View/payments.php | 42 +++++++ plugin/BTCPayments/View/profileTabContent.php | 110 ++++++++++++++---- plugin/BTCPayments/script.js | 18 +++ plugin/BTCPayments/webhook.php | 2 +- .../plugins/YPTWalletBTC/confirmButton.php | 12 +- view/css/main.css | 6 +- 9 files changed, 205 insertions(+), 33 deletions(-) create mode 100644 plugin/BTCPayments/View/payments.php create mode 100644 plugin/BTCPayments/script.js diff --git a/plugin/BTCPayments/BTCPayments.php b/plugin/BTCPayments/BTCPayments.php index 2518f0a949..915fe022a5 100644 --- a/plugin/BTCPayments/BTCPayments.php +++ b/plugin/BTCPayments/BTCPayments.php @@ -310,4 +310,13 @@ class BTCPayments extends PluginAbstract $resp->error = false; return $resp; } + + public function getHeadCode() + { + global $global, $config; + $js = ''; + + $js .= ''; + return $js; + } } diff --git a/plugin/BTCPayments/Objects/Btc_invoices.php b/plugin/BTCPayments/Objects/Btc_invoices.php index 0cf9b6c684..41db5b2535 100644 --- a/plugin/BTCPayments/Objects/Btc_invoices.php +++ b/plugin/BTCPayments/Objects/Btc_invoices.php @@ -151,18 +151,42 @@ class Btc_invoices extends ObjectYPT return 0; } - public static function getAll() + public static function getAllFromUser($users_id) { global $global; if (!static::isTableInstalled()) { return false; } - $sql = "SELECT p.*, i.* FROM " . static::getTableName() . " i LEFT JOIN btc_payments p ON i.id = btc_invoices_id WHERE 1=1 "; + $sql = "SELECT p.*, i.* FROM " . static::getTableName() . " i LEFT JOIN btc_payments p ON i.id = btc_invoices_id WHERE i.users_id = ? "; $sql .= self::getSqlFromPost('i.'); - $res = sqlDAL::readSql($sql); + $res = sqlDAL::readSql($sql, 'i', [$users_id]); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); return $fullData; } + + public static function getTotalFromUser($users_id) + { + //will receive + //current=1&rowCount=10&sort[sender]=asc&searchPhrase= + global $global; + if (!static::isTableInstalled()) { + return 0; + } + $sql = "SELECT id FROM " . static::getTableName() . " WHERE users_id = ? "; + $sql .= self::getSqlSearchFromPost(); + $res = sqlDAL::readSql($sql, 'i', [$users_id]); + $countRow = sqlDAL::num_rows($res); + sqlDAL::close($res); + return $countRow; + } + + public function save($notifySocket = false){ + $save = parent::save(); + if($save && $notifySocket){ + sendSocketMessageToUsers_id(json_decode($this->json), $this->users_id,'BTCPayments'); + } + return $save; + } } diff --git a/plugin/BTCPayments/View/Btc_invoices/list.json.php b/plugin/BTCPayments/View/Btc_invoices/list.json.php index 24f4954780..d0f8a52584 100644 --- a/plugin/BTCPayments/View/Btc_invoices/list.json.php +++ b/plugin/BTCPayments/View/Btc_invoices/list.json.php @@ -3,8 +3,13 @@ require_once '../../../../videos/configuration.php'; require_once $global['systemRootPath'] . 'plugin/BTCPayments/Objects/Btc_invoices.php'; header('Content-Type: application/json'); -$rows = Btc_invoices::getAll(); -$total = Btc_invoices::getTotal(); +if (!User::isLogged()) { + forbiddenPage(__("You cannot do this")); + exit; +} + +$rows = Btc_invoices::getAllFromUser(User::getId()); +$total = Btc_invoices::getTotalFromUser(User::getId()); foreach ($rows as $key => $value) { $rows[$key]['json_object'] = json_decode($value['json']); diff --git a/plugin/BTCPayments/View/payments.php b/plugin/BTCPayments/View/payments.php new file mode 100644 index 0000000000..b4d3ae6c88 --- /dev/null +++ b/plugin/BTCPayments/View/payments.php @@ -0,0 +1,42 @@ +setExtraScripts(array('view/css/DataTables/datatables.min.js')); +$_page->setExtraStyles(array('view/css/DataTables/datatables.min.css')); + +?> + +
+
+
+ + + +
+
+ + +
+
+
+ + +print(); ?> diff --git a/plugin/BTCPayments/View/profileTabContent.php b/plugin/BTCPayments/View/profileTabContent.php index 800207cd5d..c973a0b1d2 100644 --- a/plugin/BTCPayments/View/profileTabContent.php +++ b/plugin/BTCPayments/View/profileTabContent.php @@ -5,14 +5,14 @@ - - - + + + - - + + @@ -24,43 +24,107 @@ diff --git a/plugin/BTCPayments/script.js b/plugin/BTCPayments/script.js new file mode 100644 index 0000000000..aaaca9c728 --- /dev/null +++ b/plugin/BTCPayments/script.js @@ -0,0 +1,18 @@ +document.addEventListener('BTCPayments', function (event) { + console.log('BTCPayments', event.detail); + + switch (event.detail.status) { + case "Processing": + avideoToast('Your payment of ' + event.detail.totalBTCPaid + ' BTC is currently being processed. Please wait while we confirm the transaction.'); + break; + case "Settled": + avideoToastSuccess('Your payment of ' + event.detail.totalBTCPaid + ' BTC has been successfully completed. Thank you for your transaction!'); + break; + default: + console.log('No action required for status: ' + event.detail.status); + break; + } + if (typeof Btc_invoicestableVar !== 'undefined') { + Btc_invoicestableVar.ajax.reload(null, false); // false keeps pagination + } +}); diff --git a/plugin/BTCPayments/webhook.php b/plugin/BTCPayments/webhook.php index 629330f2c2..75991513aa 100644 --- a/plugin/BTCPayments/webhook.php +++ b/plugin/BTCPayments/webhook.php @@ -48,7 +48,7 @@ $btcInvoice->setStatus('a'); $btcInvoice->setUsers_id($invoice->metadata->users_id); $btcInvoice->setJson($invoice); -$resp->btc_invoices_id = $btcInvoice->save(); +$resp->btc_invoices_id = $btcInvoice->save(true); $resp->status = $invoice->status; if ($resp->btc_invoices_id) { switch ($invoice->status) { diff --git a/plugin/YPTWallet/plugins/YPTWalletBTC/confirmButton.php b/plugin/YPTWallet/plugins/YPTWalletBTC/confirmButton.php index 1b71b1de0c..5d7235b207 100644 --- a/plugin/YPTWallet/plugins/YPTWalletBTC/confirmButton.php +++ b/plugin/YPTWallet/plugins/YPTWalletBTC/confirmButton.php @@ -3,13 +3,19 @@ $obj = AVideoPlugin::getObjectData('BTCPayments'); $uid = uniqid(); $redirectUrl = urlencode($_SERVER['REQUEST_URI']); ?> - + + diff --git a/view/css/main.css b/view/css/main.css index 7b7c64c606..4b55631c24 100644 --- a/view/css/main.css +++ b/view/css/main.css @@ -2124,4 +2124,8 @@ body.ypt-is-compressed #videoCol { .galleryVideoButtons div.dropdown.text-center.open > ul button{ width: 100%; -} \ No newline at end of file +} + +body > div.jq-toast-wrap{ + z-index: 99999 !important; +}
#Invoice Description BTC Amount Amount Created Date Paid Date Status Action