fsb

package module
v0.0.0-...-45a9198 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 17 Imported by: 0

README

FSB

F***ing Simple Biller. A simple subscription billing library for Go.

Create invoices, manage subscriptions, and track payments.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateNextInvoiceDate

func CalculateNextInvoiceDate(lastInvoiceDate, now time.Time, period BillingPeriod) (*time.Time, bool)

Types

type Bill

type Bill struct {
	PartyId       uuid.UUID       `db:"party_id" json:"party_id"`
	BillingPeriod BillingPeriod   `db:"billing_period" json:"billing_period"`
	Amount        decimal.Decimal `db:"amount" json:"amount"`
}

type Biller

type Biller struct {
	// contains filtered or unexported fields
}

func NewBiller

func NewBiller(db IBillerDb) *Biller

func (*Biller) CreateInvoice

func (b *Biller) CreateInvoice(ctx context.Context, timeNow time.Time, bill *Bill) error

func (*Biller) CreateSchema

func (b *Biller) CreateSchema(ctx context.Context, pool *pgxpool.Pool) error

CreateSchema creates the fsb schema and runs migrations

func (*Biller) GetUnpaidInvoices

func (b *Biller) GetUnpaidInvoices(ctx context.Context) ([]*Invoice, error)

func (*Biller) RecordPayment

func (b *Biller) RecordPayment(ctx context.Context, invoice *Invoice, meta interface{}, timeNow time.Time) error

type BillingPeriod

type BillingPeriod string

BillingPeriod represents the period of time for which a bill is generated It can be monthly, yearly

const (
	PeriodMonthly BillingPeriod = "monthly"
	PeriodYearly  BillingPeriod = "yearly"
)

type Db

type Db struct {
	// contains filtered or unexported fields
}

func NewDb

func NewDb(pool *pgxpool.Pool) *Db

type ErrResponse

type ErrResponse struct {
	Error string `json:"error"`
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(r chi.Router, service *Service) *Handler

func (*Handler) GetInvoicePayments

func (h *Handler) GetInvoicePayments(w http.ResponseWriter, r *http.Request)

func (*Handler) SetupRoutes

func (h *Handler) SetupRoutes(router chi.Router)

type IBillerDb

type IBillerDb interface {
	// contains filtered or unexported methods
}

type IHttpDb

type IHttpDb interface {
	// contains filtered or unexported methods
}

type IPaymentProvider

type IPaymentProvider interface {
	CreatePayment(ctx context.Context) (interface{}, error)
}

type ISubscriptionProvider

type ISubscriptionProvider interface {
	GetBills(ctx context.Context) ([]*Bill, error)
}

type ITimeProvider

type ITimeProvider interface {
	Now() time.Time
}

type Invoice

type Invoice struct {
	Id        uuid.UUID        `db:"id" json:"id"`
	PartyId   uuid.UUID        `db:"party_id" json:"party_id"`
	Amount    decimal.Decimal  `db:"amount" json:"amount"`
	Meta      *json.RawMessage `db:"meta" json:"meta" sql:"type:jsonb"`
	CreatedAt time.Time        `db:"created_at" json:"created_at"`
	DeletedAt *time.Time       `db:"deleted_at" json:"deleted_at"`
}

type Payment

type Payment struct {
	Id        uuid.UUID        `db:"id" json:"id"`
	InvoiceId uuid.UUID        `db:"invoice_id" json:"invoice_id"`
	Meta      *json.RawMessage `db:"meta" json:"meta" sql:"type:jsonb"`
	Success   bool             `db:"success" json:"success"`
	CreatedAt time.Time        `db:"created_at" json:"created_at"`
	DeletedAt *time.Time       `db:"deleted_at" json:"deleted_at"`
}

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(tp ITimeProvider, biller *Biller, payment IPaymentProvider, subs ISubscriptionProvider) *Scheduler

func (*Scheduler) RunInvoiceJob

func (s *Scheduler) RunInvoiceJob(ctx context.Context)

func (*Scheduler) RunPaymentJob

func (s *Scheduler) RunPaymentJob(ctx context.Context)

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(db IHttpDb) *Service

func (*Service) GetInvoicePayments

func (s *Service) GetInvoicePayments(ctx context.Context) ([]*Payment, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL