Improve CORS origin handling; extend invoice repo/service and payments dispatch; rate limit and nginx config updates
Made-with: Love
This commit is contained in:
@@ -149,6 +149,31 @@ func (r *Repo) HasUnpaidForPubkey(ctx context.Context, pubkey string) (bool, err
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
// GetActiveUnpaidByPubkey returns the most recent unpaid, unexpired invoice for the pubkey, or nil if none.
|
||||
func (r *Repo) GetActiveUnpaidByPubkey(ctx context.Context, pubkey string) (*PendingInvoice, error) {
|
||||
row := r.db.QueryRowContext(ctx, `SELECT `+invCols+` FROM pending_invoices
|
||||
WHERE pubkey = ? AND paid = 0 AND expires_at > ?
|
||||
ORDER BY created_at DESC LIMIT 1`,
|
||||
pubkey, time.Now().UTC().Format(time.RFC3339))
|
||||
p, err := scanInvoice(row)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// DeleteActiveUnpaidForPubkey removes all unpaid, unexpired invoices for the pubkey so a new
|
||||
// invoice can be issued when the user switches plan (replacing the previous Bolt11).
|
||||
func (r *Repo) DeleteActiveUnpaidForPubkey(ctx context.Context, pubkey string) error {
|
||||
_, err := r.db.ExecContext(ctx,
|
||||
`DELETE FROM pending_invoices WHERE pubkey = ? AND paid = 0 AND expires_at > ?`,
|
||||
pubkey, time.Now().UTC().Format(time.RFC3339))
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *Repo) PurgeOldUnpaid(ctx context.Context) error {
|
||||
cutoff := time.Now().UTC().Add(-1 * time.Hour).Format(time.RFC3339)
|
||||
_, err := r.db.ExecContext(ctx, `DELETE FROM pending_invoices WHERE paid = 0 AND expires_at < ?`, cutoff)
|
||||
|
||||
Reference in New Issue
Block a user