IsEntitledWithCount checks if a user can send or receive and SMS message
(ctx context.Context, userID entities.UserID, count uint)
| 50 | |
| 51 | // IsEntitledWithCount checks if a user can send or receive and SMS message |
| 52 | func (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 |
| 78 | func (service *BillingService) IsEntitled(ctx context.Context, userID entities.UserID) *string { |
no test coverage detected