StartSubscription starts a subscription for an entities.User
(ctx context.Context, params *events.UserSubscriptionCreatedPayload)
| 392 | |
| 393 | // StartSubscription starts a subscription for an entities.User |
| 394 | func (service *UserService) StartSubscription(ctx context.Context, params *events.UserSubscriptionCreatedPayload) error { |
| 395 | ctx, span := service.tracer.Start(ctx) |
| 396 | defer span.End() |
| 397 | |
| 398 | user, err := service.repository.Load(ctx, params.UserID) |
| 399 | if err != nil { |
| 400 | msg := fmt.Sprintf("could not get [%T] with with ID [%s]", user, params.UserID) |
| 401 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 402 | } |
| 403 | |
| 404 | user.SubscriptionID = ¶ms.SubscriptionID |
| 405 | user.SubscriptionName = params.SubscriptionName |
| 406 | user.SubscriptionRenewsAt = ¶ms.SubscriptionRenewsAt |
| 407 | user.SubscriptionStatus = ¶ms.SubscriptionStatus |
| 408 | user.SubscriptionEndsAt = nil |
| 409 | |
| 410 | if err = service.repository.Update(ctx, user); err != nil { |
| 411 | msg := fmt.Sprintf("could not update [%T] with with ID [%s] after update", user, params.UserID) |
| 412 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 413 | } |
| 414 | |
| 415 | return nil |
| 416 | } |
| 417 | |
| 418 | // InitiateSubscriptionCancel initiates the cancelling of a subscription on lemonsqueezy |
| 419 | func (service *UserService) InitiateSubscriptionCancel(ctx context.Context, userID entities.UserID) error { |
no test coverage detected