mirror of
https://github.com/bitwarden/server.git
synced 2025-04-07 05:58:13 -05:00
refund charges if signup fails
This commit is contained in:
parent
d69ad2e32e
commit
e2937c20f9
@ -514,7 +514,19 @@ namespace Bit.Core.Services
|
||||
});
|
||||
}
|
||||
|
||||
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions);
|
||||
try
|
||||
{
|
||||
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions);
|
||||
}
|
||||
catch(StripeException)
|
||||
{
|
||||
if(customer != null)
|
||||
{
|
||||
await customerService.DeleteAsync(customer.Id);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
var organization = new Organization
|
||||
@ -542,8 +554,8 @@ namespace Bit.Core.Services
|
||||
UserId = signup.Owner.Id,
|
||||
Email = signup.Owner.Email,
|
||||
Key = signup.OwnerKey,
|
||||
Type = Enums.OrganizationUserType.Owner,
|
||||
Status = Enums.OrganizationUserStatusType.Confirmed,
|
||||
Type = OrganizationUserType.Owner,
|
||||
Status = OrganizationUserStatusType.Confirmed,
|
||||
CreationDate = DateTime.UtcNow,
|
||||
RevisionDate = DateTime.UtcNow
|
||||
};
|
||||
@ -556,10 +568,24 @@ namespace Bit.Core.Services
|
||||
{
|
||||
if(subscription != null)
|
||||
{
|
||||
await subscriptionService.CancelAsync(subscription.Id);
|
||||
await subscriptionService.CancelAsync(subscription.Id, false);
|
||||
}
|
||||
|
||||
// TODO: reverse payments
|
||||
if(customer != null)
|
||||
{
|
||||
var chargeService = new StripeChargeService();
|
||||
var charges = await chargeService.ListAsync(new StripeChargeListOptions { CustomerId = customer.Id });
|
||||
if(charges?.Data != null)
|
||||
{
|
||||
var refundService = new StripeRefundService();
|
||||
foreach(var charge in charges.Data.Where(c => !c.Refunded))
|
||||
{
|
||||
await refundService.CreateAsync(charge.Id);
|
||||
}
|
||||
}
|
||||
|
||||
await customerService.DeleteAsync(customer.Id);
|
||||
}
|
||||
|
||||
if(organization.Id != default(Guid))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user