mirror of
https://github.com/bitwarden/server.git
synced 2025-04-08 06:28:14 -05:00
refund charges if signup fails
This commit is contained in:
parent
d69ad2e32e
commit
e2937c20f9
@ -514,8 +514,20 @@ namespace Bit.Core.Services
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions);
|
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions);
|
||||||
}
|
}
|
||||||
|
catch(StripeException)
|
||||||
|
{
|
||||||
|
if(customer != null)
|
||||||
|
{
|
||||||
|
await customerService.DeleteAsync(customer.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var organization = new Organization
|
var organization = new Organization
|
||||||
{
|
{
|
||||||
@ -542,8 +554,8 @@ namespace Bit.Core.Services
|
|||||||
UserId = signup.Owner.Id,
|
UserId = signup.Owner.Id,
|
||||||
Email = signup.Owner.Email,
|
Email = signup.Owner.Email,
|
||||||
Key = signup.OwnerKey,
|
Key = signup.OwnerKey,
|
||||||
Type = Enums.OrganizationUserType.Owner,
|
Type = OrganizationUserType.Owner,
|
||||||
Status = Enums.OrganizationUserStatusType.Confirmed,
|
Status = OrganizationUserStatusType.Confirmed,
|
||||||
CreationDate = DateTime.UtcNow,
|
CreationDate = DateTime.UtcNow,
|
||||||
RevisionDate = DateTime.UtcNow
|
RevisionDate = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
@ -556,10 +568,24 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
if(subscription != null)
|
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))
|
if(organization.Id != default(Guid))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user