mirror of
https://github.com/bitwarden/server.git
synced 2025-05-30 07:44:50 -05:00
CancelAndRecoverChargesAsync for braintree
This commit is contained in:
parent
87ee144edd
commit
fca1ee4253
@ -14,6 +14,7 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
private const string PremiumPlanId = "premium-annually";
|
private const string PremiumPlanId = "premium-annually";
|
||||||
private const string StoragePlanId = "storage-gb-annually";
|
private const string StoragePlanId = "storage-gb-annually";
|
||||||
|
|
||||||
private readonly Braintree.BraintreeGateway _btGateway;
|
private readonly Braintree.BraintreeGateway _btGateway;
|
||||||
|
|
||||||
public StripePaymentService(
|
public StripePaymentService(
|
||||||
@ -281,6 +282,32 @@ namespace Bit.Core.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var customerService = new CustomerService();
|
||||||
|
var customer = await customerService.GetAsync(subscriber.GatewayCustomerId);
|
||||||
|
if(customer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(customer.Metadata.ContainsKey("btCustomerId"))
|
||||||
|
{
|
||||||
|
var transactionRequest = new Braintree.TransactionSearchRequest()
|
||||||
|
.CustomerId.Is(customer.Metadata["btCustomerId"]);
|
||||||
|
var transactions = _btGateway.Transaction.Search(transactionRequest);
|
||||||
|
|
||||||
|
if((transactions?.MaximumCount ?? 0) > 0)
|
||||||
|
{
|
||||||
|
var txs = transactions.Cast<Braintree.Transaction>().Where(c => c.RefundedTransactionId == null);
|
||||||
|
foreach(var transaction in txs)
|
||||||
|
{
|
||||||
|
await _btGateway.Transaction.RefundAsync(transaction.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _btGateway.Customer.DeleteAsync(customer.Metadata["btCustomerId"]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
var chargeService = new ChargeService();
|
var chargeService = new ChargeService();
|
||||||
var charges = await chargeService.ListAsync(new ChargeListOptions
|
var charges = await chargeService.ListAsync(new ChargeListOptions
|
||||||
{
|
{
|
||||||
@ -295,8 +322,8 @@ namespace Bit.Core.Services
|
|||||||
await refundService.CreateAsync(new RefundCreateOptions { ChargeId = charge.Id });
|
await refundService.CreateAsync(new RefundCreateOptions { ChargeId = charge.Id });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var customerService = new CustomerService();
|
|
||||||
await customerService.DeleteAsync(subscriber.GatewayCustomerId);
|
await customerService.DeleteAsync(subscriber.GatewayCustomerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user