1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-23 14:05:10 -05:00

Restore original collection method (#804)

This commit is contained in:
Chad Scharf 2020-06-30 11:52:50 -04:00 committed by GitHub
parent d7b00f6c27
commit a37706eba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -336,6 +336,8 @@ namespace Bit.Core.Services
var prorationDate = DateTime.UtcNow; var prorationDate = DateTime.UtcNow;
var seatItem = sub.Items?.Data?.FirstOrDefault(i => i.Plan.Id == plan.StripeSeatPlanId); var seatItem = sub.Items?.Data?.FirstOrDefault(i => i.Plan.Id == plan.StripeSeatPlanId);
// Retain original collection method
var collectionMethod = sub.CollectionMethod;
var subResponse = await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions var subResponse = await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions
{ {
@ -381,17 +383,20 @@ namespace Bit.Core.Services
// This proration behavior prevents a false "credit" from // This proration behavior prevents a false "credit" from
// being applied forward to the next month's invoice // being applied forward to the next month's invoice
ProrationBehavior = "none", ProrationBehavior = "none",
CollectionMethod = "charge_automatically", CollectionMethod = collectionMethod,
}); });
throw; throw;
} }
} }
// Change back the subscription collection method // Change back the subscription collection method
await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions if (collectionMethod != "send_invoice")
{ {
CollectionMethod = "charge_automatically", await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions
}); {
CollectionMethod = collectionMethod,
});
}
organization.Seats = (short?)newSeatTotal; organization.Seats = (short?)newSeatTotal;
await ReplaceAndUpdateCache(organization); await ReplaceAndUpdateCache(organization);

View File

@ -732,6 +732,8 @@ namespace Bit.Core.Services
var prorationDate = DateTime.UtcNow; var prorationDate = DateTime.UtcNow;
var storageItem = sub.Items?.FirstOrDefault(i => i.Plan.Id == storagePlanId); var storageItem = sub.Items?.FirstOrDefault(i => i.Plan.Id == storagePlanId);
// Retain original collection method
var collectionMethod = sub.CollectionMethod;
var subResponse = await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions var subResponse = await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions
{ {
@ -778,17 +780,20 @@ namespace Bit.Core.Services
// This proration behavior prevents a false "credit" from // This proration behavior prevents a false "credit" from
// being applied forward to the next month's invoice // being applied forward to the next month's invoice
ProrationBehavior = "none", ProrationBehavior = "none",
CollectionMethod = "charge_automatically", CollectionMethod = collectionMethod,
}); });
throw; throw;
} }
} }
// Change back the subscription collection method // Change back the subscription collection method
await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions if (collectionMethod != "send_invoice")
{ {
CollectionMethod = "charge_automatically", await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions
}); {
CollectionMethod = collectionMethod,
});
}
return paymentIntentClientSecret; return paymentIntentClientSecret;
} }