mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
lnbits paid articles added
This commit is contained in:
@@ -24,8 +24,9 @@ class NewsArticleForm extends Component
|
||||
public array $temporaryUrls = [];
|
||||
|
||||
public ?string $fromUrl = '';
|
||||
public bool $paid = false;
|
||||
|
||||
protected $queryString = ['fromUrl' => ['except' => '']];
|
||||
protected $queryString = ['fromUrl' => ['except' => ''], 'paid' => ['except' => false]];
|
||||
|
||||
public function rules()
|
||||
{
|
||||
@@ -37,6 +38,7 @@ class NewsArticleForm extends Component
|
||||
'libraryItem.type' => 'required',
|
||||
'libraryItem.language_code' => 'required',
|
||||
'libraryItem.value' => 'required',
|
||||
'libraryItem.sats' => 'required',
|
||||
'libraryItem.subtitle' => 'string|nullable',
|
||||
'libraryItem.excerpt' => 'required',
|
||||
'libraryItem.main_image_caption' => 'string|nullable',
|
||||
@@ -50,12 +52,14 @@ class NewsArticleForm extends Component
|
||||
{
|
||||
if ($this->libraryItem === null) {
|
||||
$this->libraryItem = new LibraryItem([
|
||||
'type' => 'markdown_article',
|
||||
'value' => '',
|
||||
'read_time' => 1,
|
||||
'news' => true,
|
||||
'language_code' => 'de',
|
||||
'approved' => auth()
|
||||
'type' => 'markdown_article',
|
||||
'value' => '',
|
||||
'value_to_be_paid' => '',
|
||||
'read_time' => 1,
|
||||
'sats' => 21,
|
||||
'news' => true,
|
||||
'language_code' => 'de',
|
||||
'approved' => auth()
|
||||
->user()
|
||||
->hasRole('news-editor'),
|
||||
]);
|
||||
|
||||
@@ -3,23 +3,72 @@
|
||||
namespace App\Http\Livewire\News;
|
||||
|
||||
use App\Models\LibraryItem;
|
||||
use App\Traits\LNBitsTrait;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
use RalphJSmit\Laravel\SEO\Support\SEOData;
|
||||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||||
|
||||
class InternArticleView extends Component
|
||||
{
|
||||
use LNBitsTrait;
|
||||
|
||||
public LibraryItem $libraryItem;
|
||||
|
||||
public $qrCode = '';
|
||||
public $invoice = '';
|
||||
public $paymentHash = '';
|
||||
public $checkid = null;
|
||||
public $checkThisPaymentHash = '';
|
||||
public bool $invoicePaid = false;
|
||||
public bool $alreadyPaid = false;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->libraryItem->load([
|
||||
'libraries',
|
||||
]);
|
||||
if ($this->libraryItem->libraries->where('is_public', false)
|
||||
->count() > 0 && ! auth()->check()) {
|
||||
->count() > 0 && !auth()->check()) {
|
||||
abort(403, __('Sorry! You are not authorized to perform this action.'));
|
||||
}
|
||||
if (auth()
|
||||
->user()
|
||||
->paidArticles()
|
||||
->where('library_item_id', $this->libraryItem->id)
|
||||
->count() > 0) {
|
||||
$this->invoicePaid = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function pay()
|
||||
{
|
||||
$invoice = $this->createInvoice(
|
||||
sats: $this->libraryItem->sats,
|
||||
memo: 'Payment for: "'.$this->libraryItem->slug.'" on Einundzwanzig Portal.'
|
||||
);
|
||||
session('payment_hash_article_'.$this->libraryItem->id, $invoice['payment_hash']);
|
||||
$this->paymentHash = $invoice['payment_hash'];
|
||||
$this->qrCode = base64_encode(QrCode::format('png')
|
||||
->size(300)
|
||||
->merge($this->libraryItem->lecturer->getFirstMedia('avatar') ? $this->libraryItem->lecturer->getFirstMediaPath('avatar') : '/public/img/einundzwanzig.png',
|
||||
.3)
|
||||
->errorCorrection('H')
|
||||
->generate($invoice['payment_request']));
|
||||
$this->invoice = $invoice['payment_request'];
|
||||
$this->checkid = $invoice['checking_id'];
|
||||
}
|
||||
|
||||
public function checkPaymentHash()
|
||||
{
|
||||
$invoice = $this->check($this->checkid ?? $this->checkThisPaymentHash);
|
||||
if ($invoice['paid']) {
|
||||
$this->invoicePaid = true;
|
||||
auth()
|
||||
->user()
|
||||
->paidArticles()
|
||||
->syncWithoutDetaching($this->libraryItem->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
49
app/Http/Livewire/Profile/LNBits.php
Normal file
49
app/Http/Livewire/Profile/LNBits.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Profile;
|
||||
|
||||
use Livewire\Component;
|
||||
use WireUi\Traits\Actions;
|
||||
|
||||
class LNBits extends Component
|
||||
{
|
||||
use Actions;
|
||||
|
||||
public array $settings = [
|
||||
'url' => 'https://legend.lnbits.com',
|
||||
'wallet_id' => '',
|
||||
'read_key' => '',
|
||||
];
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'settings.url' => 'required|url',
|
||||
'settings.wallet_id' => 'required',
|
||||
'settings.read_key' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
if (auth()->user()->lnbits) {
|
||||
$this->settings = auth()->user()->lnbits;
|
||||
}
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
$user = auth()->user();
|
||||
$user->lnbits = $this->settings;
|
||||
$user->save();
|
||||
|
||||
$this->notification()
|
||||
->success(__('LNBits settings saved successfully!'));
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.profile.l-n-bits');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user