subscription

package
v0.8.22 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncDelay = time.Second * 60
)

Variables

View Source
var (
	ErrNotFound      = errors.New("subscription not found")
	ErrInvalidUUID   = errors.New("invalid syntax of uuid")
	ErrInvalidID     = errors.New("invalid subscription id")
	ErrInvalidDetail = errors.New("invalid subscription detail")
)

Functions

This section is empty.

Types

type CustomerService

type CustomerService interface {
	GetByID(ctx context.Context, id string) (customer.Customer, error)
	List(ctx context.Context, filter customer.Filter) ([]customer.Customer, error)
}

type Filter

type Filter struct {
	CustomerID string
	PlanID     string
	State      string
}

type OrganizationService added in v0.8.13

type OrganizationService interface {
	MemberCount(ctx context.Context, orgID string) (int64, error)
}

type Phase added in v0.8.19

type Phase struct {
	EffectiveAt time.Time
	PlanID      string
}

type PlanService

type PlanService interface {
	List(ctx context.Context, filter plan.Filter) ([]plan.Plan, error)
	GetByID(ctx context.Context, id string) (plan.Plan, error)
}

type ProductService added in v0.8.19

type ProductService interface {
	GetByProviderID(ctx context.Context, id string) (product.Product, error)
}

type Repository

type Repository interface {
	GetByID(ctx context.Context, id string) (Subscription, error)
	Create(ctx context.Context, subs Subscription) (Subscription, error)
	UpdateByID(ctx context.Context, subs Subscription) (Subscription, error)
	List(ctx context.Context, filter Filter) ([]Subscription, error)
	GetByProviderID(ctx context.Context, id string) (Subscription, error)
}

type Service

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

func NewService

func NewService(stripeClient *client.API, repository Repository,
	customerService CustomerService, planService PlanService,
	orgService OrganizationService, productService ProductService) *Service

func (*Service) Cancel

func (s *Service) Cancel(ctx context.Context, id string, immediate bool) (Subscription, error)

func (*Service) ChangePlan added in v0.8.19

func (s *Service) ChangePlan(ctx context.Context, id string, planID string, immediate bool) (Phase, error)

ChangePlan changes the plan of the subscription by creating a subscription schedule it first checks if the schedule is already created, if not it creates a new schedule using the current subscription as the base and the new plan as the target in upcoming phase. Phases can be immediately changed or at the end of the current period.

func (*Service) Close

func (s *Service) Close() error

func (*Service) Create

func (s *Service) Create(ctx context.Context, sub Subscription) (Subscription, error)

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id string) (Subscription, error)

func (*Service) GetByProviderID

func (s *Service) GetByProviderID(ctx context.Context, id string) (Subscription, error)

func (*Service) Init

func (s *Service) Init(ctx context.Context)

func (*Service) List

func (s *Service) List(ctx context.Context, filter Filter) ([]Subscription, error)

func (*Service) SyncWithProvider

func (s *Service) SyncWithProvider(ctx context.Context, customr customer.Customer) error

SyncWithProvider syncs the subscription state with the billing provider

func (*Service) UpdateProductQuantity added in v0.8.19

func (s *Service) UpdateProductQuantity(ctx context.Context, orgID string, plan plan.Plan, stripeSubscription *stripe.Subscription) error

UpdateProductQuantity updates the quantity of the product in the subscription Note: check if we need to handle subscription schedule

type State

type State string
const (
	StateActive  State = "active"
	StatePastDue State = "past_due"
)

func (State) String added in v0.8.18

func (s State) String() string

type Subscription

type Subscription struct {
	ID         string
	ProviderID string // identifier set by the billing engine provider
	CustomerID string
	PlanID     string

	TrialDays int
	State     string

	Metadata metadata.Metadata

	Phase Phase

	CreatedAt  time.Time
	UpdatedAt  time.Time
	CanceledAt time.Time
	DeletedAt  time.Time
	EndedAt    time.Time
}

Jump to

Keyboard shortcuts

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