feat(payment): add WebLN payment functionality

Implemented functionality to create an invoice and make payment using WebLN. Also added error handling and logging for payment process. Updated UI to display payment information and a button to initiate payment.
This commit is contained in:
fsociety
2024-09-10 21:15:21 +02:00
parent 18032addca
commit cf15c22116
3 changed files with 54 additions and 2 deletions

View File

@@ -2,11 +2,30 @@ import {requestProvider} from "webln";
export default (livewireComponent) => ({
invoice: livewireComponent.entangle('invoice'),
async pay() {
console.log('payment_request: ' + this.invoice.payment_request);
await webln.sendPayment(this.invoice.payment_request)
.then(response => {
console.log('Payment response:', response);
this.$wire.call('logThis', 'Payment response: ' + JSON.stringify(response));
this.$wire.call('reloadMe');
})
.catch(error => {
console.error('Payment failed:', error);
this.$wire.call('logThis', 'Payment failed: ' + error);
this.$wire.call('reloadMe');
});
},
async init() {
console.log('WebLN initialized');
let webln;
try {
console.log(this.invoice);
webln = await requestProvider();
console.log('WebLN provider acquired');
this.$wire.call('logThis', 'WebLN provider acquired');