Browse Source

fix: LNbits backend wallet

Login
Eneko Illarramendi 5 years ago
parent
commit
ab190454f4
  1. 20
      lnbits/wallets/lnbits.py

20
lnbits/wallets/lnbits.py

@ -1,7 +1,9 @@
from requests import get, post
from os import getenv from os import getenv
from requests import get, post
from .base import InvoiceResponse, PaymentResponse, PaymentStatus, Wallet from .base import InvoiceResponse, PaymentResponse, PaymentStatus, Wallet
class LnbitsWallet(Wallet): class LnbitsWallet(Wallet):
def __init__(self): def __init__(self):
@ -22,6 +24,7 @@ class LnbitsWallet(Wallet):
checking_id, payment_request = data["checking_id"], data["payment_request"] checking_id, payment_request = data["checking_id"], data["payment_request"]
else: else:
error_message = r.json()["message"] error_message = r.json()["message"]
return InvoiceResponse(ok, checking_id, payment_request, error_message) return InvoiceResponse(ok, checking_id, payment_request, error_message)
def pay_invoice(self, bolt11: str) -> PaymentResponse: def pay_invoice(self, bolt11: str) -> PaymentResponse:
@ -37,12 +40,21 @@ class LnbitsWallet(Wallet):
checking_id = data["checking_id"] checking_id = data["checking_id"]
else: else:
error_message = r.json()["message"] error_message = r.json()["message"]
return InvoiceResponse(ok, checking_id, fee_msat, error_message)
return PaymentResponse(ok, checking_id, fee_msat, error_message)
def get_invoice_status(self, checking_id: str) -> PaymentStatus: def get_invoice_status(self, checking_id: str) -> PaymentStatus:
r = get(url=f"{self.endpoint}/api/v1/payments/{checking_id}", headers=self.auth_invoice) r = get(url=f"{self.endpoint}/api/v1/payments/{checking_id}", headers=self.auth_invoice)
return PaymentStatus(r['paid'])
if not r.ok:
return PaymentStatus(None)
return PaymentStatus(r.json()['paid'])
def get_payment_status(self, checking_id: str) -> PaymentStatus: def get_payment_status(self, checking_id: str) -> PaymentStatus:
r = get(url=f"{self.endpoint}/api/v1/payments/{checking_id}", headers=self.auth_invoice) r = get(url=f"{self.endpoint}/api/v1/payments/{checking_id}", headers=self.auth_invoice)
return PaymentStatus(r['paid'])
if not r.ok:
return PaymentStatus(None)
return PaymentStatus(r.json()['paid'])

Loading…
Cancel
Save