mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-09-02 19:28:55 +00:00
Add mycelium gear btc payment support
This commit is contained in:
+6
-2
@@ -1153,7 +1153,7 @@ class Users
|
||||
*
|
||||
* @return false|int|string
|
||||
*/
|
||||
public function addRole($name, $apirequests, $downloadrequests, $defaultinvites, $canpreview, $hideads)
|
||||
public function addRole($name, $apirequests, $downloadrequests, $defaultinvites, $canpreview, $hideads, $donation, $addYear)
|
||||
{
|
||||
return UserRole::query()->insertGetId(
|
||||
[
|
||||
@@ -1163,6 +1163,8 @@ class Users
|
||||
'defaultinvites' => $defaultinvites,
|
||||
'canpreview' => $canpreview,
|
||||
'hideads' => $hideads,
|
||||
'donation' => $donation,
|
||||
'addyears' => $addYear,
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -1179,7 +1181,7 @@ class Users
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function updateRole($id, $name, $apirequests, $downloadrequests, $defaultinvites, $isdefault, $canpreview, $hideads)
|
||||
public function updateRole($id, $name, $apirequests, $downloadrequests, $defaultinvites, $isdefault, $canpreview, $hideads, $donation, $addYear)
|
||||
{
|
||||
if ((int) $isdefault === 1) {
|
||||
UserRole::query()->update(['isdefault' => 0]);
|
||||
@@ -1194,6 +1196,8 @@ class Users
|
||||
'isdefault' => $isdefault,
|
||||
'canpreview' => $canpreview,
|
||||
'hideads' => $hideads,
|
||||
'donation' => $donation,
|
||||
'addyears' => $addYear,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ switch ($_REQUEST['action'] ?? 'view') {
|
||||
'defaultinvites' => '',
|
||||
'canpreview' => 0,
|
||||
'hideads' => 0,
|
||||
'donation' => 0,
|
||||
'addyears' => 0,
|
||||
];
|
||||
$page->smarty->assign('role', $role);
|
||||
break;
|
||||
@@ -32,12 +34,12 @@ switch ($_REQUEST['action'] ?? 'view') {
|
||||
case 'submit':
|
||||
if ($_POST['id'] === '') {
|
||||
$role = $page->users->addRole($_POST['name'], $_POST['apirequests'], $_POST['downloadrequests'],
|
||||
$_POST['defaultinvites'], $_POST['canpreview'], $_POST['hideads']
|
||||
$_POST['defaultinvites'], $_POST['canpreview'], $_POST['hideads'], $_POST['donation'], $_POST['addyears']
|
||||
);
|
||||
header('Location:'.WWW_TOP.'/role-list.php');
|
||||
} else {
|
||||
$role = $page->users->updateRole($_POST['id'], $_POST['name'], $_POST['apirequests'],
|
||||
$_POST['downloadrequests'], $_POST['defaultinvites'], $_POST['isdefault'], $_POST['canpreview'], $_POST['hideads']
|
||||
$_POST['downloadrequests'], $_POST['defaultinvites'], $_POST['isdefault'], $_POST['canpreview'], $_POST['hideads'], $_POST['donation'], $_POST['addyears']
|
||||
);
|
||||
header('Location:'.WWW_TOP.'/role-list.php');
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ switch ($page->page) {
|
||||
case 'books':
|
||||
case 'browse':
|
||||
case 'browsegroup':
|
||||
case 'btc_payment':
|
||||
case 'btc_payment_callback':
|
||||
case 'cart':
|
||||
case 'console':
|
||||
case 'consolemodal':
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use App\Models\UserRole;
|
||||
use nntmux\libraries\Geary;
|
||||
|
||||
$page = new Page();
|
||||
|
||||
if (! $page->users->isLoggedIn()) {
|
||||
$page->show403();
|
||||
}
|
||||
|
||||
|
||||
$gateway_id = env('MYCELIUM_GATEWAY_ID');
|
||||
$gateway_secret = env('MYCELIUM_GATEWAY_SECRET');
|
||||
|
||||
$userId = $page->users->currentUserId();
|
||||
$user = (new \nntmux\Users())->getById($userId);
|
||||
$action = $_REQUEST['action'] ?? 'view';
|
||||
$donation = UserRole::query()->where('donation', '>', 0)->get(['id', 'name', 'donation', 'addyears']);
|
||||
$page->smarty->assign('donation', $donation);
|
||||
|
||||
switch ($action) {
|
||||
case 'submit':
|
||||
$price = $_POST['price'];
|
||||
$role = $_POST['role'];
|
||||
$addYears = $_POST['addyears'];
|
||||
$data = ['user_id' => $userId, 'username' => $user->username,'price' => $price, 'role' => $role, 'addyears' => $addYears];
|
||||
$keychain_id = random_int(0, 19);
|
||||
$callback_data = json_encode($data);
|
||||
|
||||
$geary = new Geary($gateway_id, $gateway_secret);
|
||||
$order = $geary->create_order($price, $keychain_id, $callback_data);
|
||||
|
||||
if ($order->payment_id) {
|
||||
// Redirect to a payment gateway
|
||||
$url = 'https://gateway.gear.mycelium.com/pay/'. $order->payment_id;
|
||||
header('Location: ' . $url);
|
||||
die();
|
||||
}
|
||||
break;
|
||||
case 'view':
|
||||
default:
|
||||
$userId = $page->users->currentUserId();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$page->title = 'Become a supporter';
|
||||
$page->meta_title = 'Become a supporter';
|
||||
$page->meta_description = 'Become a supporter';
|
||||
|
||||
$page->content = $page->smarty->fetch('btc_payment.tpl');
|
||||
$page->render();
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
use nntmux\libraries\Geary;
|
||||
|
||||
use nntmux\Users;
|
||||
|
||||
$gateway_id = env('MYCELIUM_GATEWAY_ID');
|
||||
$gateway_secret = env('MYCELIUM_GATEWAY_SECRET');
|
||||
|
||||
$users = new Users();
|
||||
$geary = new Geary($gateway_id, $gateway_secret);
|
||||
$order = $geary->check_order_callback();
|
||||
|
||||
// Order status was received
|
||||
if ($order !== false) {
|
||||
$callback_data = json_decode($order['callback_data'], true);
|
||||
$newRole = $callback_data['role'];
|
||||
$amount = $callback_data['price'];
|
||||
$addYear = $callback_data['addyears'];
|
||||
// If order was paid in full (2) or overpaid (4)
|
||||
if ((int) $order['status'] === 2 || (int) $order['status'] === 4) {
|
||||
$users->updateUserRole($callback_data['user_id'], $newRole);
|
||||
$users->updateUserRoleChangeDate($callback_data['user_id'], \Carbon\Carbon::now()->addYears($addYear));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<div class="panel">
|
||||
<div class="panel-body pagination2">
|
||||
<div class="row">
|
||||
<div class="alert alert-info">
|
||||
<span style="align-content: center"> This page will redirect you to site outside of {$site->title} to make your payment
|
||||
<br>
|
||||
If, for some reason, your account isn't updated automaticaly, please send us an email or use our contact form to inform us so we can fix the issue.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="data table table-condensed responsive-utilities jambo-table">
|
||||
{foreach $donation as $donate}
|
||||
<form method="post" action="btc_payment?action=submit">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{$donate->name} ({$donate->donation}$)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<td>
|
||||
<input type="hidden" name="price" value="{$donate->donation}">
|
||||
<input type="hidden" name="role" value="{$donate->id}">
|
||||
<input type="hidden" name="addyears" value="{$donate->addyears}">
|
||||
<input type="submit" class="btn btn-primary" value="Pay by BTC">
|
||||
</td>
|
||||
</form>
|
||||
{/foreach}
|
||||
</form>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
<div class="panel">
|
||||
<div class="panel-body pagination2">
|
||||
<div class="row">
|
||||
<div class="alert alert-info">
|
||||
<span style="align-content: center"> This page will redirect you to site outside of {$site->title} to make your payment
|
||||
<br>
|
||||
If, for some reason, your account isn't updated automaticaly, please send us an email or use our contact form to inform us so we can fix the issue.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="data table table-condensed responsive-utilities jambo-table">
|
||||
{foreach $donation as $donate}
|
||||
<form method="post" action="btc_payment?action=submit">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{$donate->name} ({$donate->donation}$)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<td>
|
||||
<input type="hidden" name="price" value="{$donate->donation}">
|
||||
<input type="hidden" name="role" value="{$donate->id}">
|
||||
<input type="hidden" name="addyears" value="{$donate->addyears}">
|
||||
<input type="submit" class="btn btn-primary" value="Pay by BTC">
|
||||
</td>
|
||||
</form>
|
||||
{/foreach}
|
||||
</form>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
<div class="panel">
|
||||
<div class="panel-body pagination2">
|
||||
<div class="row">
|
||||
<div class="alert alert-info">
|
||||
<span style="align-content: center"> This page will redirect you to site outside of {$site->title} to make your payment
|
||||
<br>
|
||||
If, for some reason, your account isn't updated automaticaly, please send us an email or use our contact form to inform us so we can fix the issue.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="data table table-condensed responsive-utilities jambo-table">
|
||||
{foreach $donation as $donate}
|
||||
<form method="post" action="btc_payment?action=submit">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{$donate->name} ({$donate->donation}$)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<td>
|
||||
<input type="hidden" name="price" value="{$donate->donation}">
|
||||
<input type="hidden" name="role" value="{$donate->id}">
|
||||
<input type="hidden" name="addyears" value="{$donate->addyears}">
|
||||
<input type="submit" class="btn btn-primary" value="Pay by BTC">
|
||||
</td>
|
||||
</form>
|
||||
{/foreach}
|
||||
</form>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
<div class="panel">
|
||||
<div class="panel-body pagination2">
|
||||
<div class="row">
|
||||
<div class="alert alert-info">
|
||||
<span style="align-content: center"> This page will redirect you to site outside of {$site->title} to make your payment
|
||||
<br>
|
||||
If, for some reason, your account isn't updated automaticaly, please send us an email or use our contact form to inform us so we can fix the issue.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="data table table-condensed responsive-utilities jambo-table">
|
||||
{foreach $donation as $donate}
|
||||
<form method="post" action="btc_payment?action=submit">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{$donate->name} ({$donate->donation}$)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<td>
|
||||
<input type="hidden" name="price" value="{$donate->donation}">
|
||||
<input type="hidden" name="role" value="{$donate->id}">
|
||||
<input type="hidden" name="addyears" value="{$donate->addyears}">
|
||||
<input type="submit" class="btn btn-primary" value="Pay by BTC">
|
||||
</td>
|
||||
</form>
|
||||
{/foreach}
|
||||
</form>
|
||||
</table>
|
||||
</div>
|
||||
@@ -53,6 +53,18 @@
|
||||
<div class="hint">Whether ad's are hidden</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Donation amount:</td>
|
||||
<td>
|
||||
<input name="donation" type="text" value="{$role.donation}" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Years Added:</td>
|
||||
<td>
|
||||
<input name="addyears" type="text" value="{$role.addyears}" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{if $role.id != ''}
|
||||
<tr>
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
<th>invites</th>
|
||||
<th>can preview</th>
|
||||
<th>hide ads</th>
|
||||
<th>donation</th>
|
||||
<th>add years</th>
|
||||
<th>default roles</th>
|
||||
<th>options</th>
|
||||
</tr>
|
||||
@@ -23,6 +25,8 @@
|
||||
<td>{$role.defaultinvites}</td>
|
||||
<td>{if $role.canpreview == 1}Yes{else}No{/if}</td>
|
||||
<td>{if $role.hideads == 1}Yes{else}No{/if}</td>
|
||||
<td>{$role.donation}</td>
|
||||
<td>{$role.addyears}</td>
|
||||
<td>{if $role.isdefault=="1"}Yes{else}No{/if}</td>
|
||||
<td><a href="{$smarty.const.WWW_TOP}/role-edit.php?id={$role.id}">edit</a> {if $role.id>"3"}<a class="confirm_action" href="{$smarty.const.WWW_TOP}/role-delete.php?id={$role.id}">delete</a>{/if}</td>
|
||||
</tr>
|
||||
|
||||
@@ -1312,6 +1312,8 @@ CREATE TABLE user_roles (
|
||||
isdefault TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
|
||||
canpreview TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
|
||||
hideads TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
|
||||
donation INT(10) NOT NULL DEFAULT '0',
|
||||
addyears INT(2) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
|
||||
Reference in New Issue
Block a user