Documentation ¶
Index ¶
- Constants
- Variables
- type CustomerService
- type Filter
- type OrganizationService
- type Phase
- type PlanService
- type ProductService
- type Repository
- type Service
- func (s *Service) Cancel(ctx context.Context, id string, immediate bool) (Subscription, error)
- func (s *Service) ChangePlan(ctx context.Context, id string, planID string, immediate bool) (Phase, error)
- func (s *Service) Close() error
- func (s *Service) Create(ctx context.Context, sub Subscription) (Subscription, error)
- func (s *Service) GetByID(ctx context.Context, id string) (Subscription, error)
- func (s *Service) GetByProviderID(ctx context.Context, id string) (Subscription, error)
- func (s *Service) Init(ctx context.Context)
- func (s *Service) List(ctx context.Context, filter Filter) ([]Subscription, error)
- func (s *Service) SyncWithProvider(ctx context.Context, customr customer.Customer) error
- func (s *Service) UpdateProductQuantity(ctx context.Context, orgID string, plan plan.Plan, ...) error
- type State
- type Subscription
Constants ¶
View Source
const (
SyncDelay = time.Second * 60
)
Variables ¶
Functions ¶
This section is empty.
Types ¶
type CustomerService ¶
type OrganizationService ¶ added in v0.8.13
type PlanService ¶
type ProductService ¶ added in v0.8.19
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, config billing.Config, repository Repository, customerService CustomerService, planService PlanService, orgService OrganizationService, productService ProductService) *Service
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) Create ¶
func (s *Service) Create(ctx context.Context, sub Subscription) (Subscription, error)
func (*Service) GetByProviderID ¶
func (*Service) SyncWithProvider ¶
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 Subscription ¶
type Subscription struct { ID string ProviderID string // identifier set by the billing engine provider CustomerID string PlanID string State string Metadata metadata.Metadata Phase Phase CreatedAt time.Time UpdatedAt time.Time CanceledAt time.Time DeletedAt time.Time EndedAt time.Time TrialEndsAt time.Time CurrentPeriodStartAt time.Time CurrentPeriodEndAt time.Time BillingCycleAnchorAt time.Time }
Click to show internal directories.
Click to hide internal directories.