1
1
mirror of https://github.com/bumi/lntip synced 2026-02-25 10:00:50 +00:00

Use JSON POST request for invoice creation

This commit is contained in:
2019-01-07 21:29:08 +01:00
parent 08d0eee00c
commit a070fe35a0
3 changed files with 30 additions and 19 deletions

View File

@@ -69,17 +69,13 @@ LnTip.prototype.stopWatchingPayment = function () {
}
LnTip.prototype.payWithWebln = function () {
console.log(this.invoice)
if (!webln.isEnabled) {
webln.enable().then((weblnResponse) => {
console.log(this.invoice.PaymentRequest)
return webln.sendPayment({ paymentRequest: this.invoice.PaymentRequest })
}).catch((e) => {
console.log(e);
this.requestPayment();
})
} else {
console.log(this.invoice.PaymentRequest)
return webln.sendPayment({ paymentRequest: this.invoice.PaymentRequest })
}
}
@@ -110,8 +106,16 @@ LnTip.prototype.requestPayment = function () {
}
LnTip.prototype.getInvoice = function () {
return this._request(`${this.host}/payme?memo=${this.memo}&amount=${this.amount}`)
.then((invoice) => {
var args = {
method: 'POST',
mode: 'cors',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ memo: this.memo, amount: this.amount })
};
return this._request(
`${this.host}/invoice`,
args
).then((invoice) => {
this.invoice = invoice;
this.watchPayment();
@@ -123,8 +127,8 @@ LnTip.prototype.getInvoice = function () {
})
}
LnTip.prototype._request = function(url) {
return fetch(url).then((response) => {
LnTip.prototype._request = function(url, args) {
return fetch(url, args).then((response) => {
return response.json();
})
}