public async Task <ProfileResponseModel> PostPremium(PremiumRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) { throw new UnauthorizedAccessException(); } var valid = model.Validate(_globalSettings); UserLicense license = null; if (valid && _globalSettings.SelfHosted) { license = await ApiHelpers.ReadJsonFileFromBody <UserLicense>(HttpContext, model.License); } if (!valid || (_globalSettings.SelfHosted && license == null)) { throw new BadRequestException("Invalid license."); } await _userService.SignUpPremiumAsync(user, model.PaymentToken, model.AdditionalStorageGb.GetValueOrDefault(0), license); return(new ProfileResponseModel(user, null)); }
public async Task <PaymentResponseModel> PostPremium(PremiumRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) { throw new UnauthorizedAccessException(); } var valid = model.Validate(_globalSettings); UserLicense license = null; if (valid && _globalSettings.SelfHosted) { license = await ApiHelpers.ReadJsonFileFromBody <UserLicense>(HttpContext, model.License); } if (!valid || (_globalSettings.SelfHosted && license == null)) { throw new BadRequestException("Invalid license."); } var result = await _userService.SignUpPremiumAsync(user, model.PaymentToken, model.PaymentMethodType.Value, model.AdditionalStorageGb.GetValueOrDefault(0), license); var profile = new ProfileResponseModel(user, null, await _userService.TwoFactorIsEnabledAsync(user)); return(new PaymentResponseModel { UserProfile = profile, PaymentIntentClientSecret = result.Item2, Success = result.Item1 }); }
public void Validate_Success(bool selfHosted, IFormFile formFile, string country, bool expected) { var gs = new GlobalSettings { SelfHosted = selfHosted }; var sut = new PremiumRequestModel { License = formFile, Country = country, }; Assert.Equal(expected, sut.Validate(gs)); }