diff --git a/internal/api/lightning.go b/internal/api/lightning.go index 232c89d..47f5cbe 100644 --- a/internal/api/lightning.go +++ b/internal/api/lightning.go @@ -7,6 +7,7 @@ import ( "github.com/LightningTipBot/LightningTipBot/internal" "github.com/LightningTipBot/LightningTipBot/internal/lnbits" "github.com/LightningTipBot/LightningTipBot/internal/telegram" + "github.com/gorilla/mux" ) type Service struct { @@ -80,9 +81,10 @@ func (s Service) PayInvoice(w http.ResponseWriter, r *http.Request) { return } - payment, err := s.Bot.Client.Payment(*user.Wallet, invoice.PaymentHash) + payment, _ := s.Bot.Client.Payment(*user.Wallet, invoice.PaymentHash) if err != nil { - RespondError(w, "could not get payment") + // we assume that it's paid since thre was no error earlier + payment.Paid = true } w.Header().Set("Content-Type", "application/json") @@ -92,9 +94,11 @@ func (s Service) PayInvoice(w http.ResponseWriter, r *http.Request) { func (s Service) PaymentStatus(w http.ResponseWriter, r *http.Request) { user := telegram.LoadUser(r.Context()) - payment, err := s.Bot.Client.Payment(*user.Wallet, "") + payment_hash := mux.Vars(r)["payment_hash"] + payment, err := s.Bot.Client.Payment(*user.Wallet, payment_hash) if err != nil { RespondError(w, "could not get payment") + return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) @@ -104,10 +108,12 @@ func (s Service) PaymentStatus(w http.ResponseWriter, r *http.Request) { // InvoiceStatus func (s Service) InvoiceStatus(w http.ResponseWriter, r *http.Request) { user := telegram.LoadUser(r.Context()) + payment_hash := mux.Vars(r)["payment_hash"] user.Wallet = &lnbits.Wallet{} - payment, err := s.Bot.Client.Payment(*user.Wallet, "") + payment, err := s.Bot.Client.Payment(*user.Wallet, payment_hash) if err != nil { - RespondError(w, "could not get payment") + RespondError(w, "could not get invoice") + return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) diff --git a/internal/lnbits/lnbits.go b/internal/lnbits/lnbits.go index e8db8f4..1419af7 100644 --- a/internal/lnbits/lnbits.go +++ b/internal/lnbits/lnbits.go @@ -157,7 +157,7 @@ func (c Client) Payments(w Wallet) (wtx Payments, err error) { } // Payment state of a payment -func (c Client) Payment(w Wallet, payment_hash string) (payment Payment, err error) { +func (c Client) Payment(w Wallet, payment_hash string) (payment LNbitsPayment, err error) { // custom header with invoice key invoiceHeader := req.Header{ "Content-Type": "application/json", diff --git a/internal/lnbits/types.go b/internal/lnbits/types.go index 52aa4c7..770359a 100644 --- a/internal/lnbits/types.go +++ b/internal/lnbits/types.go @@ -134,6 +134,12 @@ type Payment struct { WebhookStatus interface{} `json:"webhook_status"` } +type LNbitsPayment struct { + Paid bool `json:"paid"` + Preimage string `json:"preimage"` + Details Payment `json:"details,omitempty"` +} + type Payments []Payment type Invoice struct {