Documentation ¶
Index ¶
- Constants
- Variables
- type ChangeRequest
- type CreditService
- 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) CancelUpcomingPhase(ctx context.Context, sub Subscription) error
- func (s *Service) ChangePlan(ctx context.Context, id string, changeRequest ChangeRequest) (Phase, error)
- func (s *Service) Close() error
- func (s *Service) Create(ctx context.Context, sub Subscription) (Subscription, error)
- func (s *Service) DeleteByCustomer(ctx context.Context, customr customer.Customer) 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) HasUserSubscribedBefore(ctx context.Context, customerID string, planID string) (bool, error)
- func (s *Service) Init(ctx context.Context) error
- 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) TriggerSyncByProviderID(ctx context.Context, id string) error
- func (s *Service) UpdateProductQuantity(ctx context.Context, orgID string, currentPlan plan.Plan, ...) error
- type State
- type Subscription
Constants ¶
View Source
const ( SyncDelay = time.Second * 60 InitiatorIDMetadataKey = "initiated_by" )
Variables ¶
View Source
var ( ErrNotFound = fmt.Errorf("subscription not found") ErrInvalidUUID = fmt.Errorf("invalid syntax of uuid") ErrInvalidID = fmt.Errorf("invalid subscription id") ErrInvalidDetail = fmt.Errorf("invalid subscription detail") ErrAlreadyOnSamePlan = fmt.Errorf("already on the same plan") ErrNoPhaseActive = fmt.Errorf("no phase active") ErrPhaseIsUpdating = fmt.Errorf("phase is in the middle of a change, please try again later") ErrSubscriptionOnProviderNotFound = fmt.Errorf("failed to get subscription from billing provider") )
Functions ¶
This section is empty.
Types ¶
type ChangeRequest ¶ added in v0.8.29
type CreditService ¶ added in v0.8.32
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) Delete(ctx context.Context, id string) 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, creditService CreditService) *Service
func (*Service) CancelUpcomingPhase ¶ added in v0.8.29
func (s *Service) CancelUpcomingPhase(ctx context.Context, sub Subscription) error
CancelUpcomingPhase cancels the scheduled phase of the subscription
func (*Service) ChangePlan ¶ added in v0.8.19
func (s *Service) ChangePlan(ctx context.Context, id string, changeRequest ChangeRequest) (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) DeleteByCustomer ¶ added in v0.8.35
func (*Service) GetByProviderID ¶
func (*Service) HasUserSubscribedBefore ¶ added in v0.8.36
func (*Service) SyncWithProvider ¶
SyncWithProvider syncs the subscription state with the billing provider
func (*Service) TriggerSyncByProviderID ¶ added in v0.13.0
func (*Service) UpdateProductQuantity ¶ added in v0.8.19
func (s *Service) UpdateProductQuantity(ctx context.Context, orgID string, currentPlan plan.Plan, stripeSubscription *stripe.Subscription, stripeSchedule *stripe.SubscriptionSchedule) 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 PlanHistory []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 }
func (Subscription) IsActive ¶ added in v0.8.30
func (s Subscription) IsActive() bool
Click to show internal directories.
Click to hide internal directories.