Documentation
¶
Overview ¶
Package selfsub implements the user self-service subscription management of the subscription module: viewing, token reset, notes, and the two-phase cancellation whose refund stage the billing module settles. Only the module facade may reach it.
Index ¶
- type CacheInvalidator
- type Deps
- type LogReader
- type MarkerReader
- type OrderReader
- type RefundSettler
- type Service
- func (s *Service) GetSubscribeLog(ctx context.Context, req *dto.GetSubscribeLogRequest) (*dto.GetSubscribeLogResponse, error)
- func (s *Service) PreUnsubscribe(ctx context.Context, req *dto.PreUnsubscribeRequest) (*dto.PreUnsubscribeResponse, error)
- func (s *Service) QueryUserSubscribe(ctx context.Context) (*dto.QueryUserSubscribeListResponse, error)
- func (s *Service) ResetUserSubscribeToken(ctx context.Context, req *dto.ResetUserSubscribeTokenRequest) error
- func (s *Service) Unsubscribe(ctx context.Context, req *dto.UnsubscribeRequest) error
- func (s *Service) UpdateUserSubscribeNote(ctx context.Context, req *dto.UpdateUserSubscribeNoteRequest) error
- type Store
- type UserSubscriptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheInvalidator ¶ added in v1.21.0
type CacheInvalidator interface {
ClearSubscribeCache(ctx context.Context, data ...*usersub.Subscribe) error
}
CacheInvalidator drops cached subscription rows.
type Deps ¶
type Deps struct {
UserSubs UserSubscriptions
Plans repository.SubscribeRepo
// Orders, Refunds, Logs and Inbox are ports onto the billing and
// platform domains: the order a refund pays back, the refund stage of a
// cancellation, the system log and the cancellation markers.
Orders OrderReader
Refunds RefundSettler
Cache CacheInvalidator
Logs LogReader
Inbox MarkerReader
Store Store
// SingleModel forbids holding more than one blocking subscription;
// runtime-mutable, read per request.
SingleModel func() bool
}
Deps declares the subdomain's dependencies; the module facade forwards them from the composition root.
type LogReader ¶ added in v1.21.0
type LogReader interface {
FilterSystemLog(ctx context.Context, filter *log.FilterParams) ([]*log.SystemLog, int64, error)
}
LogReader pages the platform's system log.
type MarkerReader ¶ added in v1.21.0
type MarkerReader interface {
Find(ctx context.Context, consumer, eventKey string) (*inbox.Record, error)
}
MarkerReader reads the inbox markers of the cancellation stage.
type OrderReader ¶ added in v1.21.0
type OrderReader interface {
FindOneDetails(ctx context.Context, id int64) (*order.Details, error)
}
OrderReader reads an order with its renewals: what a refund pays back.
type RefundSettler ¶ added in v1.21.0
type RefundSettler interface {
// UnsubscribeRefundSettled reports whether the subscription's refund was
// settled.
UnsubscribeRefundSettled(ctx context.Context, subscriptionID int64) (bool, error)
// SettleUnsubscribeRefund settles it in a billing-domain transaction:
// amount back to the user's wallet and the referral commission taken
// back when the subscription has an order, and the refund marker; a
// second settlement fails.
SettleUnsubscribeRefund(ctx context.Context, userID, subscriptionID, orderID, amount int64) error
}
RefundSettler is the billing port of the cancellation's refund stage; the billing facade provides it.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the self-service entry point used by the subscription facade.
func NewService ¶
func (*Service) GetSubscribeLog ¶
func (s *Service) GetSubscribeLog(ctx context.Context, req *dto.GetSubscribeLogRequest) (*dto.GetSubscribeLogResponse, error)
GetSubscribeLog pages the owner's subscription fetch log.
func (*Service) PreUnsubscribe ¶
func (s *Service) PreUnsubscribe(ctx context.Context, req *dto.PreUnsubscribeRequest) (*dto.PreUnsubscribeResponse, error)
PreUnsubscribe quotes the refund the owner would get for cancelling the subscription now.
func (*Service) QueryUserSubscribe ¶
func (s *Service) QueryUserSubscribe(ctx context.Context) (*dto.QueryUserSubscribeListResponse, error)
QueryUserSubscribe lists the owner's subscriptions with their next calendar traffic reset.
func (*Service) ResetUserSubscribeToken ¶
func (s *Service) ResetUserSubscribeToken(ctx context.Context, req *dto.ResetUserSubscribeTokenRequest) error
ResetUserSubscribeToken rotates the owner's subscription token and node credential. The row is read under lock, so the previous credentials whose cache entries the commit invalidates are the stored ones.
func (*Service) Unsubscribe ¶
Unsubscribe cancels the subscription in a subscription-domain transaction, then has the billing module settle the refund in a billing-domain transaction (gift amount first for balance-paid orders, then regular balance). A crash between the two is repaired when the user retries: a Deducted subscription whose refund was not settled resumes at the refund stage.
func (*Service) UpdateUserSubscribeNote ¶
func (s *Service) UpdateUserSubscribeNote(ctx context.Context, req *dto.UpdateUserSubscribeNoteRequest) error
UpdateUserSubscribeNote stores the owner's note on their subscription. Only the note column is written, so a note edit racing the traffic accounting or the lifecycle sweep keeps what they wrote.
type Store ¶ added in v1.20.3
type Store interface {
repository.SubscriptionTransactor
}
Store is the persistence capability required by this package: the cancellation's subscription-domain transaction.
type UserSubscriptions ¶ added in v1.21.0
type UserSubscriptions interface {
FindOneSubscribe(ctx context.Context, id int64) (*usersub.Subscribe, error)
// FindOneUserSubscribe returns the subscription with its plan.
FindOneUserSubscribe(ctx context.Context, id int64) (*usersub.SubscribeDetails, error)
// QueryUserSubscribe lists the user's subscriptions with their plans;
// given statuses, only those in one of them.
QueryUserSubscribe(ctx context.Context, userID int64, statuses ...int64) ([]*usersub.SubscribeDetails, error)
// UpdateSubscribeColumns writes only the named columns of data.Id.
UpdateSubscribeColumns(ctx context.Context, data *usersub.Subscribe, columns ...string) error
}
UserSubscriptions is the part of the subscription repository the self-service reads and the note edit use outside a transaction; the module's repository provides it.