diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..06be902
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.env
+.vscode
+node_modules
\ No newline at end of file
diff --git a/client/app.js b/client/app.js
index 5dd93b8..4595b66 100644
--- a/client/app.js
+++ b/client/app.js
@@ -1,15 +1,42 @@
+let currentInvoice = null;
+
document.getElementById('pay-button').onclick = async () => {
- const amount = document.getElementById('amount').value;
- if (!amount) return alert("Enter an amount!");
+ const amount = document.getElementById('amount').value;
+ if (!amount) return alert("Enter an amount!");
+
+ const res = await fetch('http://localhost:3000/invoices/create', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ amount })
+ });
+
+ const invoice = await res.json();
+ currentInvoice = invoice;
+
+ const qrURL = `https://api.qrserver.com/v1/create-qr-code/?data=lightning:${invoice.payment_request}`;
+ document.getElementById('qrcode').innerHTML = ``;
+
+ // Show payment section
+ document.querySelector('.payment-section').style.display = 'block';
+ document.getElementById('payment-status').textContent = '';
+};
+
+document.getElementById('pay-invoice-button').onclick = async () => {
+ if (!currentInvoice) return alert("No invoice to pay.");
- const res = await fetch('http://localhost:3000/create-invoice', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ amount })
- });
+ const res = await fetch('http://localhost:3000/invoices/pay', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ payment_request: currentInvoice.payment_request })
+ });
- const invoice = await res.json();
- const qrURL = `https://api.qrserver.com/v1/create-qr-code/?data=lightning:${invoice.payment_request}`;
+ const result = await res.json();
- document.getElementById('qrcode').innerHTML = `
`;
+ if (res.ok) {
+ document.getElementById('payment-status').textContent =
+ `Payment successful: ${result.amount} sats`;
+ } else {
+ document.getElementById('payment-status').textContent =
+ `Payment failed: ${result.details || result.error}`;
+ }
};
diff --git a/client/index.html b/client/index.html
index ff3c2b2..70369bd 100644
--- a/client/index.html
+++ b/client/index.html
@@ -4,15 +4,25 @@