diff --git a/lnurl.go b/lnurl.go index 40edd6a..81f1073 100644 --- a/lnurl.go +++ b/lnurl.go @@ -166,8 +166,10 @@ func handleLNURL(w http.ResponseWriter, r *http.Request) { return } } - comment = zapEvent.Content - log.Debug().Str("NIP57 Comment received", comment).Msg("Comment") + if len(zapEvent.Content) > 0 { + comment = zapEvent.Content + log.Debug().Str("NIP57 Comment received", comment).Msg("Comment") + } } @@ -269,12 +271,16 @@ func serveLNURLpSecond(w http.ResponseWriter, params *Params, username string, a awaitPaid = true } + decoded_invoice, _ := decodepay.Decodepay(invoice) return LNURLPayValuesCustom{ LNURLResponse: lnurl.LNURLResponse{Status: "OK"}, PR: invoice, Routes: make([]struct{}, 0), SuccessAction: &lnurl.SuccessAction{Message: "Payment Received!", Tag: "message"}, Comment: comment, + Paid: false, + CreatedAt: time.Now(), + ParsedInvoice: decoded_invoice, Nip57Receipt: nip57Receipt, Nip57ReceiptRelays: nip57ReceiptRelays, AwaitInvoicePaid: awaitPaid, diff --git a/waitforinvoice.go b/waitforinvoice.go index 5224e29..c5e62ed 100644 --- a/waitforinvoice.go +++ b/waitforinvoice.go @@ -181,9 +181,8 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) { case <-ticker.C: bolt11, _ := decodepay.Decodepay(payvalues.PR) - var isPaid bool = false - switch backend := mip.Backend.(type) { + case LNDParams: req, err := http.NewRequest("GET", backend.Host+"/v1/invoice/"+bolt11.PaymentHash, @@ -210,7 +209,8 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) { } if gjson.ParseBytes(b).Get("settled").String() == "true" { - isPaid = true + payvalues.PaidAt = time.Now() + payvalues.Paid = true } case LNBitsParams: @@ -229,15 +229,16 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) { json.Unmarshal([]byte(string(responseData)), &jsonMap) if jsonMap["paid"].(bool) { - isPaid = true + payvalues.PaidAt = time.Now() + payvalues.Paid = true } - case SparkoParams: - //TODO case LNPayParams: //TODO case EclairParams: //TODO + case SparkoParams: + //TODO case CommandoParams: //TODO @@ -249,7 +250,7 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) { } //If invoice is paid and DescriptionHash matches Nip57 DescriptionHash, publish Zap Nostr Event. This is rather a sanity check. - if isPaid { + if payvalues.Paid { var descriptionTag = *payvalues.Nip57Receipt.Tags.GetFirst([]string{"description"}) if bolt11.DescriptionHash == Nip57DescriptionHash(descriptionTag.Value()) { publishNostrEvent(payvalues.Nip57Receipt, payvalues.Nip57ReceiptRelays)