diff --git a/controllers/payinvoice.ctrl.go b/controllers/payinvoice.ctrl.go index 5d84c18..99f3174 100644 --- a/controllers/payinvoice.ctrl.go +++ b/controllers/payinvoice.ctrl.go @@ -56,7 +56,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error { } */ - invoice, err := controller.svc.AddOutgoingInvoice(userID, paymentRequest, *decodedPaymentRequest) + invoice, err := controller.svc.AddOutgoingInvoice(userID, paymentRequest, decodedPaymentRequest) if err != nil { c.Logger().Errorf("Error creating invoice: %v", err) // TODO: sentry notification diff --git a/db/models/invoice.go b/db/models/invoice.go index 0456d5a..2b5d86c 100644 --- a/db/models/invoice.go +++ b/db/models/invoice.go @@ -16,7 +16,7 @@ type Invoice struct { UserID int64 `json:"user_id" validate:"required"` User *User `bun:"rel:belongs-to,join:user_id=id"` Amount int64 `json:"amount" validate:"gte=0"` - Memo string `json:"memo"` + Memo string `json:"memo" bun:",nullzero"` DescriptionHash string `json:"description_hash" bun:",nullzero"` PaymentRequest string `json:"payment_request" bun:",nullzero"` DestinationPubkeyHex string `json:"destination_pubkey_hex" bun:",notnull"` diff --git a/lib/service/invoices.go b/lib/service/invoices.go index 662c7ad..9efa355 100644 --- a/lib/service/invoices.go +++ b/lib/service/invoices.go @@ -220,19 +220,21 @@ func (svc *LndhubService) PayInvoice(invoice *models.Invoice) (*SendPaymentRespo return &paymentResponse, err } -func (svc *LndhubService) AddOutgoingInvoice(userID int64, paymentRequest string, decodedInvoice zpay32.Invoice) (*models.Invoice, error) { +func (svc *LndhubService) AddOutgoingInvoice(userID int64, paymentRequest string, decodedInvoice *zpay32.Invoice) (*models.Invoice, error) { // Initialize new DB invoice destinationPubkeyHex := hex.EncodeToString(decodedInvoice.Destination.SerializeCompressed()) expiresAt := decodedInvoice.Timestamp.Add(decodedInvoice.Expiry()) invoice := models.Invoice{ Type: "outgoing", UserID: userID, - Memo: *decodedInvoice.Description, PaymentRequest: paymentRequest, State: "initialized", DestinationPubkeyHex: destinationPubkeyHex, ExpiresAt: bun.NullTime{Time: expiresAt}, } + if decodedInvoice.Description != nil { + invoice.Memo = *decodedInvoice.Description + } if decodedInvoice.DescriptionHash != nil { dh := *decodedInvoice.DescriptionHash invoice.DescriptionHash = hex.EncodeToString(dh[:])