mirror of
https://github.com/bitwarden/server.git
synced 2025-12-10 00:42:07 -06:00
Fix the duplicate issue
This commit is contained in:
parent
2e0a4161be
commit
c837c22caa
@ -289,20 +289,13 @@ public class StripeEventUtilityService : IStripeEventUtilityService
|
|||||||
}
|
}
|
||||||
var btInvoiceAmount = Math.Round(invoice.AmountDue / 100M, 2);
|
var btInvoiceAmount = Math.Round(invoice.AmountDue / 100M, 2);
|
||||||
|
|
||||||
var existingTransactions = organizationId.HasValue
|
// Check if this invoice already has a Braintree transaction ID to prevent duplicate charges
|
||||||
? await _transactionRepository.GetManyByOrganizationIdAsync(organizationId.Value)
|
if (invoice.Metadata?.ContainsKey("btTransactionId") ?? false)
|
||||||
: userId.HasValue
|
|
||||||
? await _transactionRepository.GetManyByUserIdAsync(userId.Value)
|
|
||||||
: await _transactionRepository.GetManyByProviderIdAsync(providerId.Value);
|
|
||||||
|
|
||||||
var duplicateTimeSpan = TimeSpan.FromHours(24);
|
|
||||||
var now = DateTime.UtcNow;
|
|
||||||
var duplicateTransaction = existingTransactions?
|
|
||||||
.FirstOrDefault(t => (now - t.CreationDate) < duplicateTimeSpan);
|
|
||||||
if (duplicateTransaction != null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("There is already a recent PayPal transaction ({0}). " +
|
_logger.LogWarning("Invoice {InvoiceId} already has a Braintree transaction ({TransactionId}). " +
|
||||||
"Do not charge again to prevent possible duplicate.", duplicateTransaction.GatewayId);
|
"Do not charge again to prevent duplicate.",
|
||||||
|
invoice.Id,
|
||||||
|
invoice.Metadata["btTransactionId"]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user