public ActionResult <SuccessResponse> UpdateStatus(UserUpdateStatusRequest model)
        {
            int          sCode    = 200;
            BaseResponse response = null;

            try
            {
                _adminService.UpdateStatus(model);

                if (model.UserStatusId == 2)
                {
                    StripeCustomer customer = _stripeService.GetStripeCustomerByUserId(model.Id);
                    if (customer.SubscriptionTypeId != 1)
                    {
                        _stripeService.CancelSubscription(customer.SubscriptionId);
                        _stripeService.UpdateCustomerSubscriptions(model.Id, "none", "none");
                    }
                }
                response = new SuccessResponse();
            }
            catch (Exception ex)
            {
                sCode = 500;
                base.Logger.LogError(ex.ToString());
                response = new ErrorResponse($"Generic Errors: { ex.Message }");
            }


            return(StatusCode(sCode, response));
        }
Ejemplo n.º 2
0
        public ResponseData <Dashboard> CancelSubscription(string applianceId, string accountId)
        {
            try
            {
                var accountAppliance = _accountApplianceService.GetAccountApplianceByAccountIdAndApplianceId(Convert.ToInt32(accountId), Convert.ToInt32(applianceId));
                var response         = new ResponseData <Dashboard>();
                if (accountAppliance != null)
                {
                    var subscription = _stripeService.CancelSubscription(accountAppliance.SubscriptionId);
                    if (subscription != null)
                    {
                        response.Message = ResponseMessage.CancelSubscriptionSuccess;
                        var appliance = _applianceService.GetApplianceById(Convert.ToInt32(applianceId));
                    }
                }

                response.Status = ResponseStatus.Success.ToString();
                return(response);
            }
            catch (Exception ex)
            {
                var response = new ResponseData <Dashboard>();
                response.Message = ex.Message;
                response.Status  = ResponseStatus.Error.ToString();
                return(response);
            }
        }
Ejemplo n.º 3
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var subscription = await _dbContext.Subscription
                                   .Include(x => x.Customer)
                                   .FirstOrDefaultAsync(x => x.Id == request.SubscriptionId && x.Customer.IdentityKey == _userContext.Id.ToString());

                if (subscription == null)
                {
                    return(Unit.Value);
                }

                if (request.CancelImmediately)
                {
                    await _stripeService.CancelSubscription(subscription.ExternalKey);
                }
                else
                {
                    await _stripeService.UpdateSubscriptionAsync(subscription.ExternalKey, options => options.CancelAtPeriodEnd = true);
                }

                _logger.LogInformation("Subscription {SubscriptionId} cancel at period end set to true.  Stripe subscription identifier is {StripeSubscriptionId}", subscription.Id, subscription.ExternalKey);

                return(Unit.Value);
            }