MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / IsEntitledWithCount

Method IsEntitledWithCount

api/pkg/services/billing_service.go:52–75  ·  view source on GitHub ↗

IsEntitledWithCount checks if a user can send or receive and SMS message

(ctx context.Context, userID entities.UserID, count uint)

Source from the content-addressed store, hash-verified

50
51// IsEntitledWithCount checks if a user can send or receive and SMS message
52func (service *BillingService) IsEntitledWithCount(ctx context.Context, userID entities.UserID, count uint) *string {
53 ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)
54 defer span.End()
55
56 user, err := service.userRepository.Load(ctx, userID)
57 if err != nil {
58 msg := fmt.Sprintf("cannot load user with ID [%s], entitlement successfull", userID)
59 ctxLogger.Error(service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)))
60 return nil
61 }
62
63 usage, err := service.billingUsageRepository.GetCurrent(ctx, userID)
64 if err != nil {
65 msg := fmt.Sprintf("cannot load billing usage for user with ID [%s], entitlement successfull", userID)
66 ctxLogger.Error(service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)))
67 return nil
68 }
69
70 if !usage.IsEntitled(count, user.SubscriptionName.Limit()) {
71 return service.handleLimitExceeded(ctx, user)
72 }
73
74 return nil
75}
76
77// IsEntitled checks if a user can send or receive and SMS message
78func (service *BillingService) IsEntitled(ctx context.Context, userID entities.UserID) *string {

Callers 3

IsEntitledMethod · 0.95
StoreMethod · 0.80
BulkSendMethod · 0.80

Calls 8

handleLimitExceededMethod · 0.95
LimitMethod · 0.80
StartWithLoggerMethod · 0.65
LoadMethod · 0.65
ErrorMethod · 0.65
WrapErrorSpanMethod · 0.65
GetCurrentMethod · 0.65
IsEntitledMethod · 0.45

Tested by

no test coverage detected