diff --git a/src/Api/Controllers/OrganizationSponsorshipsController.cs b/src/Api/Controllers/OrganizationSponsorshipsController.cs index 97e7bf763e..9bd945107d 100644 --- a/src/Api/Controllers/OrganizationSponsorshipsController.cs +++ b/src/Api/Controllers/OrganizationSponsorshipsController.cs @@ -158,10 +158,15 @@ namespace Bit.Api.Controllers var existingOrgSponsorship = await _organizationSponsorshipRepository .GetBySponsoringOrganizationUserIdAsync(orgUser.Id); - if (existingOrgSponsorship == null || existingOrgSponsorship.SponsoredOrganizationId == null) + if (existingOrgSponsorship == null) { throw new BadRequestException("You are not currently sponsoring an organization."); } + if (existingOrgSponsorship.SponsoredOrganizationId == null) + { + await _organizationSponsorshipRepository.DeleteAsync(existingOrgSponsorship); + return; + } var sponsoredOrganization = await _organizationRepository .GetByIdAsync(existingOrgSponsorship.SponsoredOrganizationId.Value); diff --git a/src/Core/Models/Api/Response/SubscriptionResponseModel.cs b/src/Core/Models/Api/Response/SubscriptionResponseModel.cs index d18b3c1cbd..dcc592c7a4 100644 --- a/src/Core/Models/Api/Response/SubscriptionResponseModel.cs +++ b/src/Core/Models/Api/Response/SubscriptionResponseModel.cs @@ -82,12 +82,14 @@ namespace Bit.Core.Models.Api Amount = item.Amount; Interval = item.Interval; Quantity = item.Quantity; + SponsoredSubscriptionItem = item.SponsoredSubscriptionItem; } public string Name { get; set; } public decimal Amount { get; set; } public int Quantity { get; set; } public string Interval { get; set; } + public bool SponsoredSubscriptionItem { get; set; } } } diff --git a/src/Core/Models/Business/SubscriptionInfo.cs b/src/Core/Models/Business/SubscriptionInfo.cs index 2d39894502..57b102ed6c 100644 --- a/src/Core/Models/Business/SubscriptionInfo.cs +++ b/src/Core/Models/Business/SubscriptionInfo.cs @@ -52,12 +52,14 @@ namespace Bit.Core.Models.Business } Quantity = (int)item.Quantity; + SponsoredSubscriptionItem = Utilities.StaticStore.SponsoredPlans.Any(p => p.StripePlanId == item.Plan.Id); } public string Name { get; set; } public decimal Amount { get; set; } public int Quantity { get; set; } public string Interval { get; set; } + public bool SponsoredSubscriptionItem { get; set; } } } diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index 31aa08dc55..fcc55c3cac 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -198,8 +198,7 @@ namespace Bit.Core.Services var sponsoredPlan = Utilities.StaticStore.GetSponsoredPlan(sponsorship.PlanSponsorshipType.Value); var subscriptionUpdate = new SponsorOrganizationSubscriptionUpdate(existingPlan, sponsoredPlan, applySponsorship); - var prorationTime = DateTime.UtcNow; - await FinalizeSubscriptionChangeAsync(org, subscriptionUpdate, prorationTime); + await FinalizeSubscriptionChangeAsync(org, subscriptionUpdate, DateTime.UtcNow); var sub = await _stripeAdapter.SubscriptionGetAsync(org.GatewaySubscriptionId); org.ExpirationDate = sub.CurrentPeriodEnd; diff --git a/test/Api.Test/Controllers/OrganizationSponsorshipsControllerTests.cs b/test/Api.Test/Controllers/OrganizationSponsorshipsControllerTests.cs index b427bcaf22..8ddc65ab34 100644 --- a/test/Api.Test/Controllers/OrganizationSponsorshipsControllerTests.cs +++ b/test/Api.Test/Controllers/OrganizationSponsorshipsControllerTests.cs @@ -393,10 +393,10 @@ namespace Bit.Api.Test.Controllers .GetBySponsoringOrganizationUserIdAsync(orgUser.Id) .Returns((OrganizationSponsorship)sponsorship); - var exception = await Assert.ThrowsAsync(() => - sutProvider.Sut.RevokeSponsorship(orgUser.OrganizationId.ToString())); + await sutProvider.Sut.RevokeSponsorship(orgUser.OrganizationId.ToString()); + + await sutProvider.GetDependency().Received(1).DeleteAsync(sponsorship); - Assert.Contains("You are not currently sponsoring an organization.", exception.Message); await sutProvider.GetDependency() .DidNotReceiveWithAnyArgs() .RemoveSponsorshipAsync(default, default);