File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Http \Livewire \Test ;
4
4
5
+ use App \Traits \LNBitsTrait ;
5
6
use Illuminate \Support \Facades \Log ;
6
7
use Livewire \Component ;
7
8
8
9
class WebLN extends Component
9
10
{
11
+ use LNBitsTrait;
12
+
13
+ public $ invoice ;
14
+
15
+ public function mount ()
16
+ {
17
+ $ this ->invoice = $ this ->createInvoice (
18
+ sats: 1 ,
19
+ memo: 'Test Payment from WebLN ' ,
20
+ lnbits: [
21
+ 'read_key ' => '97f6120563e3498b8be4c67023c912ae ' ,
22
+ 'url ' => 'https://bits.codingarena.top ' ,
23
+ ]
24
+ );
25
+ }
26
+
27
+ public function reloadMe ()
28
+ {
29
+ // full reload current page
30
+ return redirect ()->route ('webln ' );
31
+ }
32
+
10
33
public function logThis ($ text )
11
34
{
12
35
Log::info ('WEBLN: ' . $ text );
Original file line number Diff line number Diff line change @@ -2,11 +2,30 @@ import {requestProvider} from "webln";
2
2
3
3
export default ( livewireComponent ) => ( {
4
4
5
+ invoice : livewireComponent . entangle ( 'invoice' ) ,
6
+
7
+ async pay ( ) {
8
+ console . log ( 'payment_request: ' + this . invoice . payment_request ) ;
9
+ await webln . sendPayment ( this . invoice . payment_request )
10
+ . then ( response => {
11
+ console . log ( 'Payment response:' , response ) ;
12
+ this . $wire . call ( 'logThis' , 'Payment response: ' + JSON . stringify ( response ) ) ;
13
+ this . $wire . call ( 'reloadMe' ) ;
14
+ } )
15
+ . catch ( error => {
16
+ console . error ( 'Payment failed:' , error ) ;
17
+ this . $wire . call ( 'logThis' , 'Payment failed: ' + error ) ;
18
+ this . $wire . call ( 'reloadMe' ) ;
19
+ } ) ;
20
+ } ,
21
+
5
22
async init ( ) {
6
23
console . log ( 'WebLN initialized' ) ;
7
24
8
25
let webln ;
9
26
try {
27
+ console . log ( this . invoice ) ;
28
+
10
29
webln = await requestProvider ( ) ;
11
30
console . log ( 'WebLN provider acquired' ) ;
12
31
this . $wire . call ( 'logThis' , 'WebLN provider acquired' ) ;
Original file line number Diff line number Diff line change 1
- <div x-data =" webln(@this )" >
2
- <webview id =" webln-webview" src =" https://webln-capable-site.com" style =" width :100% ; height :100% ;" ></webview >
1
+ <div x-data =" webln(@this )" class =" p-2 sm:p-4" wire:ignore >
2
+ <div class =" font-mono space-y-1 p-2 sm:p-4 text-white break-words" >
3
+ <div class =" text-xs sm:text-base break-words" >Test Payment from WebLN to The Ben</div >
4
+ <div class =" text-xs sm:text-base break-words" >1 sat</div >
5
+ <div class =" text-xs sm:text-base break-words" >hash: {{ $invoice [' payment_hash' ] } } </div >
6
+ <div class =" text-xs sm:text-base break-words" >payment_request: {{ $invoice [' payment_request' ] } } </div >
7
+ <div class =" mt-6" >
8
+ <div class =" flex justify-center" >
9
+ <button x-on:click =" pay" class =" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" >Pay Invoice</button >
10
+ </div >
11
+ </div >
12
+ </div >
3
13
</div >
You can’t perform that action at this time.
0 commit comments