mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
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.
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
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');
|
|
|
|
// getInfo
|
|
const info = await webln.getInfo();
|
|
console.log('WebLN getInfo:', info);
|
|
this.$wire.call('logThis', 'WebLN getInfo: ' + JSON.stringify(info));
|
|
|
|
} catch (err) {
|
|
// Handle users without WebLN
|
|
console.error('WebLN provider request failed:', err);
|
|
this.$wire.call('logThis', 'WebLN provider request failed: ' + err);
|
|
}
|
|
},
|
|
|
|
});
|