Ejemplo n.º 1
0
        public async Task <PaddleLinkReply> GetPaddlePayLink([FromQuery] Guid subscriptionPlanId)
        {
            // Get the subscription plan.
            var gotPlan = SubscriptionPlan.PlansById.TryGetValue(subscriptionPlanId, out var plan);

            if (!gotPlan)
            {
                throw new NotFoundException($"Cannot find plan '{subscriptionPlanId}'");
            }

            // Get the user details.
            var account = await GetLoggedInAccountAsync();

            if (account.PaddleSubscriptionId != null)
            {
                throw new BadRequestException("You already have a subscription.");
            }

            var email = GetLoggedInUserEmail();

            // Figure out the remaining trial days.
            var remainingTrialDays = 1;

            if (account.TrialExpiryUtc != null)
            {
                var trialExpiryUtc = account.TrialExpiryUtc.Value;
                var utcNow         = _timeService.UtcNow.Date;
                remainingTrialDays = (int)Math.Floor((trialExpiryUtc - utcNow).TotalDays + 1);
                remainingTrialDays = Math.Max(remainingTrialDays, 1);
            }

            // Prep passthrough data.
            var productId   = plan.PaddleProductId;
            var passthrough = _passthroughSerializer.Serialize(account.Id);

            // Send the request to Paddle.
            var url = await _paddleClient.GeneratePayLink(productId, remainingTrialDays, email, passthrough);

            var result = new PaddleLinkReply {
                Link = url
            };

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <PaddleLinkReply> GetPaddleUpdateUrl()
        {
            var account = await GetLoggedInAccountAsync();

            var subscriptionId = account.PaddleSubscriptionId;

            if (subscriptionId == null)
            {
                throw new BadRequestException("You do not have a subscription.");
            }

            var subscriptionUser = await _paddleClient.GetSubscriptionUser(subscriptionId.Value);

            var result = new PaddleLinkReply {
                Link = subscriptionUser.UpdateUrl
            };

            return(result);
        }