mirror of
https://github.com/bitwarden/server.git
synced 2025-05-29 23:34:53 -05:00
prevent duplicate paypal charges
This commit is contained in:
parent
d9181045c9
commit
c5ae1b8283
@ -584,10 +584,25 @@ namespace Bit.Billing.Controllers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var btObjIdField = ids.Item1.HasValue ? "organization_id" : "user_id";
|
var orgTransaction = ids.Item1.HasValue;
|
||||||
|
var btObjIdField = orgTransaction ? "organization_id" : "user_id";
|
||||||
var btObjId = ids.Item1 ?? ids.Item2.Value;
|
var btObjId = ids.Item1 ?? ids.Item2.Value;
|
||||||
var btInvoiceAmount = (invoice.AmountDue / 100M);
|
var btInvoiceAmount = (invoice.AmountDue / 100M);
|
||||||
|
|
||||||
|
var existingTransactions = orgTransaction ?
|
||||||
|
await _transactionRepository.GetManyByOrganizationIdAsync(ids.Item1.Value) :
|
||||||
|
await _transactionRepository.GetManyByUserIdAsync(ids.Item2.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}). " +
|
||||||
|
"Do not charge again to prevent possible duplicate.", duplicateTransaction.GatewayId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var transactionResult = await _btGateway.Transaction.SaleAsync(
|
var transactionResult = await _btGateway.Transaction.SaleAsync(
|
||||||
new Braintree.TransactionRequest
|
new Braintree.TransactionRequest
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user