Add configurable LNbits invoice memos and pubkey metadata

Read INVOICE_MEMO_YEARLY and INVOICE_MEMO_LIFETIME from the environment
and pass the user pubkey in LNbits payment extra for invoice creation.
This commit is contained in:
2026-05-06 19:52:07 +00:00
parent fe2b95258d
commit 43d78862e3
5 changed files with 33 additions and 24 deletions

View File

@@ -26,10 +26,11 @@ func NewLNbits(baseURL, invoiceKey string) *LNbitsClient {
}
type createReq struct {
Out bool `json:"out"`
Amount int64 `json:"amount"`
Memo string `json:"memo"`
Expiry int `json:"expiry,omitempty"`
Out bool `json:"out"`
Amount int64 `json:"amount"`
Memo string `json:"memo"`
Expiry int `json:"expiry,omitempty"`
Extra map[string]string `json:"extra,omitempty"`
}
type createResp struct {
@@ -47,8 +48,8 @@ type statusResp struct {
} `json:"details"`
}
func (c *LNbitsClient) Create(ctx context.Context, amountSats int64, memo string, expirySecs int) (string, string, error) {
body, err := json.Marshal(createReq{Out: false, Amount: amountSats, Memo: memo, Expiry: expirySecs})
func (c *LNbitsClient) Create(ctx context.Context, amountSats int64, memo string, expirySecs int, extra map[string]string) (string, string, error) {
body, err := json.Marshal(createReq{Out: false, Amount: amountSats, Memo: memo, Expiry: expirySecs, Extra: extra})
if err != nil {
return "", "", err
}

View File

@@ -20,6 +20,8 @@ type Pricing struct {
YearlySats int64
LifetimeSats int64
ExpiryMins int
MemoYearly string
MemoLifetime string
}
type Service struct {
@@ -131,17 +133,15 @@ func (s *Service) Create(ctx context.Context, req CreateRequest) (*PendingInvoic
}
amount := s.pricing.YearlySats * int64(req.Years)
memo := s.pricing.MemoYearly
if req.SubscriptionType == user.SubLifetime {
amount = s.pricing.LifetimeSats
}
memo := fmt.Sprintf("%s@%s", username, s.domain)
if isRenewal {
memo = "renewal: " + memo
memo = s.pricing.MemoLifetime
}
expirySecs := s.pricing.ExpiryMins * 60
hash, request, err := s.lnbits.Create(ctx, amount, memo, expirySecs)
extra := map[string]string{"pubkey": req.Pubkey}
hash, request, err := s.lnbits.Create(ctx, amount, memo, expirySecs, extra)
if err != nil {
return nil, err
}