try catch added

This commit is contained in:
HolgerHatGarKeineNode
2023-03-14 20:30:47 +01:00
parent ed3c05d342
commit 4350429bed
2 changed files with 24 additions and 7 deletions

View File

@@ -9,9 +9,11 @@ use Illuminate\Support\Facades\Log;
use Livewire\Component; use Livewire\Component;
use RalphJSmit\Laravel\SEO\Support\SEOData; use RalphJSmit\Laravel\SEO\Support\SEOData;
use SimpleSoftwareIO\QrCode\Facades\QrCode; use SimpleSoftwareIO\QrCode\Facades\QrCode;
use WireUi\Traits\Actions;
class InternArticleView extends Component class InternArticleView extends Component
{ {
use Actions;
use LNBitsTrait; use LNBitsTrait;
public LibraryItem $libraryItem; public LibraryItem $libraryItem;
@@ -44,11 +46,18 @@ class InternArticleView extends Component
public function pay() public function pay()
{ {
$invoice = $this->createInvoice( try {
sats: $this->libraryItem->sats, $invoice = $this->createInvoice(
memo: 'Payment for: "'.$this->libraryItem->slug.'" on Einundzwanzig Portal.', sats: $this->libraryItem->sats,
lnbits: $this->libraryItem->createdBy->lnbits, memo: 'Payment for: "'.$this->libraryItem->slug.'" on Einundzwanzig Portal.',
); lnbits: $this->libraryItem->createdBy->lnbits,
);
} catch (\Exception $e) {
$this->notification()
->error('LNBits error: '.$e->getMessage());
return;
}
session('payment_hash_article_'.$this->libraryItem->id, $invoice['payment_hash']); session('payment_hash_article_'.$this->libraryItem->id, $invoice['payment_hash']);
$this->paymentHash = $invoice['payment_hash']; $this->paymentHash = $invoice['payment_hash'];
$this->qrCode = base64_encode(QrCode::format('png') $this->qrCode = base64_encode(QrCode::format('png')
@@ -71,7 +80,15 @@ class InternArticleView extends Component
public function checkPaymentHash() public function checkPaymentHash()
{ {
$invoice = $this->check($this->checkid ?? $this->checkThisPaymentHash, $this->libraryItem->createdBy->lnbits); try {
$invoice = $this->check($this->checkid ?? $this->checkThisPaymentHash,
$this->libraryItem->createdBy->lnbits);
} catch (\Exception $e) {
$this->notification()
->error('LNBits error: '.$e->getMessage());
return;
}
if (isset($invoice['paid']) && $invoice['paid']) { if (isset($invoice['paid']) && $invoice['paid']) {
$this->invoicePaid = true; $this->invoicePaid = true;
if (auth()->check()) { if (auth()->check()) {

View File

@@ -25,7 +25,7 @@ trait LNBitsTrait
'out' => false, 'out' => false,
'amount' => $sats, 'amount' => $sats,
'memo' => $memo, 'memo' => $memo,
]); ])->throw();
return $response->json(); return $response->json();
} }