1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

Update BTC interface

This commit is contained in:
Daniel Neto 2025-03-17 13:48:18 -03:00
parent 12a836fb05
commit 64ae7240dc
9 changed files with 205 additions and 33 deletions

View file

@ -310,4 +310,13 @@ class BTCPayments extends PluginAbstract
$resp->error = false;
return $resp;
}
public function getHeadCode()
{
global $global, $config;
$js = '';
$js .= '<script src="' . getURL('plugin/BTCPayments/script.js') . '" type="text/javascript"></script>';
return $js;
}
}

View file

@ -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;
}
}

View file

@ -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']);

View file

@ -0,0 +1,42 @@
<?php
require_once __DIR__ . '/../../../videos/configuration.php';
if (!User::isLogged()) {
forbiddenPage(__("You cannot do this"));
exit;
}
// Get the parameters from the request
$value = isset($_GET['value']) ? $_GET['value'] : '0';
$description = isset($_GET['description']) ? $_GET['description'] : 'New Payment';
$redirectUrl = isset($_GET['redirectUrl']) ? $_GET['redirectUrl'] : $global['webSiteRootURL'];
$url = $global['webSiteRootURL'].'plugin/BTCPayments/invoice.php';
$url = addQueryStringParameter($url, 'value', $value);
$url = addQueryStringParameter($url, 'description', $description);
$url = addQueryStringParameter($url, 'redirectUrl', $redirectUrl);
$_page = new Page(array(__('BTC Payments')));
$_page->setExtraScripts(array('view/css/DataTables/datatables.min.js'));
$_page->setExtraStyles(array('view/css/DataTables/datatables.min.css'));
?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<a href="<?php echo $url; ?>" onclick="modal.showPleaseWait();"
class="btn btn-warning btn-block btn-lg">
<i class="fab fa-bitcoin"></i> <?php echo __("Make a New Payment"); ?>
</a>
</div>
<div class="col-md-12">
<?php require_once __DIR__ . '/profileTabContent.php'; ?>
</div>
</div>
</div>
<?php $_page->print(); ?>

View file

@ -5,14 +5,14 @@
<table id="Btc_invoicesTable" class="table table-bordered table-striped table-hover" width="100%" cellspacing="0">
<thead>
<tr>
<th>#</th>
<th>Invoice</th>
<th><i class="fas fa-info-circle"></i> Description</th>
<th class="hidden-sm hidden-xs">#</th>
<th class="hidden-sm hidden-xs">Invoice</th>
<th class="hidden-xs"><i class="fas fa-info-circle"></i> Description</th>
<th><i class="fab fa-bitcoin"></i> BTC Amount</th>
<th><i class="fas fa-dollar-sign"></i> Amount</th>
<th><i class="fas fa-calendar-alt"></i> Created Date</th>
<th><i class="fas fa-calendar-check"></i> Paid Date</th>
<th><i class="fas fa-receipt"></i> Status</th>
<th class="hidden-sm hidden-xs"><i class="fas fa-calendar-check"></i> Paid Date</th>
<th class="hidden-sm hidden-xs"><i class="fas fa-receipt"></i> Status</th>
<th><i class="fas fa-link"></i> Action</th>
</tr>
</thead>
@ -24,43 +24,107 @@
</div>
<script type="text/javascript">
var Btc_invoicestableVar;
$(document).ready(function() {
var Btc_invoicestableVar = $('#Btc_invoicesTable').DataTable({
Btc_invoicestableVar = $('#Btc_invoicesTable').DataTable({
serverSide: true,
"ajax": webSiteRootURL + "plugin/BTCPayments/View/Btc_invoices/list.json.php",
"order": [[0, "desc"]],
"columns": [
{ "data": "id" },
{ "data": "json_object.id", "defaultContent": "-" },
{ "data": "json_object.metadata.description", "defaultContent": "-" },
{ "data": "amount_btc", "render": function(data) { return data + ' BTC'; } },
{ "data": "amount_currency", "render": function(data, type, row) {
"order": [
[0, "desc"]
],
"columns": [{
"data": "id",
"className": "hidden-sm hidden-xs",
},
{
"data": "json_object.id",
"defaultContent": "-",
"className": "hidden-sm hidden-xs",
},
{
"data": "json_object.metadata.description",
"defaultContent": "-",
"className": "hidden-xs",
},
{
"data": "amount_btc",
"render": function(data) {
return data + ' BTC';
}
},
{
"data": "amount_currency",
"render": function(data, type, row) {
var currency = row.currency || 'USD';
return currency + ' ' + parseFloat(data).toFixed(2);
}
},
{ "data": "created_php_time", "render": function(data) {
{
"data": "created_php_time",
"render": function(data) {
return new Date(data * 1000).toLocaleString();
}
},
{ "data": "modified_php_time", "render": function(data, type, row) {
{
"data": "modified_php_time",
"render": function(data, type, row) {
return row.json_object.status === "Settled" ? new Date(data * 1000).toLocaleString() : '-';
}
},
"className": "hidden-sm hidden-xs",
},
{ "data": "json_object.status", "render": function(data) {
return data === "Settled"
? '<span class="label label-success"><i class="fas fa-check-circle"></i> Paid</span>'
: '<span class="label label-warning"><i class="fas fa-clock"></i> Pending</span>';
}
{
"data": "json_object.status",
"render": function(data) {
return data === "Settled" ?
'<span class="label label-success"><i class="fas fa-check-circle"></i> Paid</span>' :
'<span class="label label-warning"><i class="fas fa-clock"></i> Pending</span>';
},
"className": "hidden-sm hidden-xs",
},
{ "data": "json_object.checkoutLink", "render": function(data, type, row) {
{
"data": "json_object.checkoutLink",
"render": function(data, type, row) {
var status = row.json_object.status;
var buttonText = status === "Settled" ? '<i class="fas fa-receipt"></i> View Receipt' : '<i class="fas fa-credit-card"></i> Pay Now';
return '<a href="' + data + '" class="btn ' + (status === "Settled" ? 'btn-success' : 'btn-primary') + ' btn-sm" target="_blank">' + buttonText + '</a>';
return '<button onclick="avideoModalIframeSmall(\'' + data + '\');" class="btn ' + (status === "Settled" ? 'btn-success' : 'btn-primary') + ' btn-sm" target="_blank">' + buttonText + '</button>';
}
}
],
select: true,
"drawCallback": function(settings) {
var api = this.api();
var hasPending = false;
var pendingPayment = null;
// Check for pending payments
api.rows().every(function() {
var rowData = this.data();
if (rowData.json_object && (rowData.json_object.status !== "Settled")) {
hasPending = true;
pendingPayment = rowData;
return false; // Exit loop early if a pending payment is found
}
});
if (hasPending) {
let message =
"⚠️ You have a pending payment of <strong>" + pendingPayment.amount_btc +
" BTC</strong>.<br>" +
"If you want to make a new payment, you can proceed, but please ensure it will not be a duplicate transaction.";
console.warn(message);
avideoAlertInfo(message);
} else {
handleNoPendingInvoices(); // Call function if no pending invoices exist
}
}
});
});
// Function to call when no pending invoices exist
function handleNoPendingInvoices() {
console.log("No pending BTC invoices found.");
// You can replace this with another action, like displaying a message or redirecting.
}
</script>

View file

@ -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
}
});

View file

@ -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) {

View file

@ -3,13 +3,19 @@ $obj = AVideoPlugin::getObjectData('BTCPayments');
$uid = uniqid();
$redirectUrl = urlencode($_SERVER['REQUEST_URI']);
?>
<button type="submit" class="btn btn-primary" id="YPTWalletBTCButton"><i class="fab fa-bitcoin"></i> Bitcoin</button>
<button type="submit" class="btn btn-primary" id="YPTWalletBTCButton">
<i class="fab fa-bitcoin"></i> Bitcoin
</button>
<script>
$(document).ready(function () {
$('#YPTWalletBTCButton').click(function (evt) {
evt.preventDefault();
modal.showPleaseWait();
document.location = webSiteRootURL+'plugin/BTCPayments/invoice.php?value='+$('#value<?php echo @$_GET['plans_id']; ?>').val()+'&description=Wallet+add+funds&redirectUrl=<?php echo $redirectUrl; ?>';
let invoiceUrl = webSiteRootURL + 'plugin/BTCPayments/View/payments.php?value=' +
$('#value<?php echo @$_GET['plans_id']; ?>').val() +
'&description=Wallet+add+funds&redirectUrl=<?php echo $redirectUrl; ?>';
avideoModalIframe(invoiceUrl);
});
});
</script>

View file

@ -2125,3 +2125,7 @@ body.ypt-is-compressed #videoCol {
.galleryVideoButtons div.dropdown.text-center.open > ul button{
width: 100%;
}
body > div.jq-toast-wrap{
z-index: 99999 !important;
}