first commit
This commit is contained in:
52
internal/invoice/model.go
Normal file
52
internal/invoice/model.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package invoice
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/noderunners/nip05api/internal/user"
|
||||
)
|
||||
|
||||
type PendingInvoice struct {
|
||||
PaymentHash string
|
||||
PaymentRequest string
|
||||
Username string
|
||||
Pubkey string
|
||||
SubscriptionType user.SubscriptionType
|
||||
Years int
|
||||
AmountSats int64
|
||||
ExpiresAt time.Time
|
||||
Paid bool
|
||||
IsRenewal bool
|
||||
CreatedAt time.Time
|
||||
// TargetExpiresAt captures the user's new expiry value at first
|
||||
// confirmation. Persisted so retries after a crash apply the same
|
||||
// absolute value and stay idempotent. nil for lifetime.
|
||||
TargetExpiresAt *time.Time
|
||||
// TargetSet is true when target_expires_at has been written (even if
|
||||
// the value is NULL for lifetime). Distinguishes "unset" from "lifetime".
|
||||
TargetSet bool
|
||||
}
|
||||
|
||||
type Status string
|
||||
|
||||
const (
|
||||
StatusPending Status = "pending"
|
||||
StatusPaid Status = "paid"
|
||||
StatusExpired Status = "expired"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvoiceNotFound = errors.New("invoice not found")
|
||||
ErrLNbits = errors.New("lnbits error")
|
||||
)
|
||||
|
||||
func (p *PendingInvoice) Status() Status {
|
||||
if p.Paid {
|
||||
return StatusPaid
|
||||
}
|
||||
if time.Now().UTC().After(p.ExpiresAt) {
|
||||
return StatusExpired
|
||||
}
|
||||
return StatusPending
|
||||
}
|
||||
Reference in New Issue
Block a user