1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-20 19:14:32 -05:00

check to make sure not already refunded

This commit is contained in:
Kyle Spearrin 2019-02-01 23:29:12 -05:00
parent 4ade9a229b
commit fb3cdba99e
2 changed files with 52 additions and 42 deletions

View File

@ -94,28 +94,32 @@ namespace Bit.Billing.Controllers
return new BadRequestResult(); return new BadRequestResult();
} }
saleTransaction.RefundedAmount = refund.TotalRefundedAmount.ValueAmount; if(!saleTransaction.Refunded.GetValueOrDefault() &&
if(saleTransaction.RefundedAmount == saleTransaction.Amount) saleTransaction.RefundedAmount.GetValueOrDefault() < refund.TotalRefundedAmount.ValueAmount)
{ {
saleTransaction.Refunded = true; saleTransaction.RefundedAmount = refund.TotalRefundedAmount.ValueAmount;
} if(saleTransaction.RefundedAmount == saleTransaction.Amount)
await _transactionRepository.ReplaceAsync(saleTransaction);
var ids = refund.GetIdsFromCustom();
if(ids.Item1.HasValue || ids.Item2.HasValue)
{
await _transactionRepository.CreateAsync(new Core.Models.Table.Transaction
{ {
Amount = refund.Amount.TotalAmount, saleTransaction.Refunded = true;
CreationDate = refund.CreateTime, }
OrganizationId = ids.Item1, await _transactionRepository.ReplaceAsync(saleTransaction);
UserId = ids.Item2,
Type = TransactionType.Refund, var ids = refund.GetIdsFromCustom();
Gateway = GatewayType.PayPal, if(ids.Item1.HasValue || ids.Item2.HasValue)
GatewayId = refund.Id, {
PaymentMethodType = PaymentMethodType.PayPal, await _transactionRepository.CreateAsync(new Core.Models.Table.Transaction
Details = refund.Id {
}); Amount = refund.Amount.TotalAmount,
CreationDate = refund.CreateTime,
OrganizationId = ids.Item1,
UserId = ids.Item2,
Type = TransactionType.Refund,
Gateway = GatewayType.PayPal,
GatewayId = refund.Id,
PaymentMethodType = PaymentMethodType.PayPal,
Details = refund.Id
});
}
} }
} }
} }

View File

@ -237,34 +237,40 @@ namespace Bit.Billing.Controllers
throw new Exception("Cannot find refunded charge."); throw new Exception("Cannot find refunded charge.");
} }
chargeTransaction.RefundedAmount = charge.AmountRefunded / 100M; var amountRefunded = charge.AmountRefunded / 100M;
if(charge.Refunded)
{
chargeTransaction.Refunded = true;
}
await _transactionRepository.ReplaceAsync(chargeTransaction);
foreach(var refund in charge.Refunds) if(!chargeTransaction.Refunded.GetValueOrDefault() &&
chargeTransaction.RefundedAmount.GetValueOrDefault() < amountRefunded)
{ {
var refundTransaction = await _transactionRepository.GetByGatewayIdAsync( chargeTransaction.RefundedAmount = amountRefunded;
GatewayType.Stripe, refund.Id); if(charge.Refunded)
if(refundTransaction != null)
{ {
continue; chargeTransaction.Refunded = true;
} }
await _transactionRepository.ReplaceAsync(chargeTransaction);
await _transactionRepository.CreateAsync(new Transaction foreach(var refund in charge.Refunds)
{ {
Amount = refund.Amount / 100M, var refundTransaction = await _transactionRepository.GetByGatewayIdAsync(
CreationDate = refund.Created, GatewayType.Stripe, refund.Id);
OrganizationId = chargeTransaction.OrganizationId, if(refundTransaction != null)
UserId = chargeTransaction.UserId, {
Type = TransactionType.Refund, continue;
Gateway = GatewayType.Stripe, }
GatewayId = refund.Id,
PaymentMethodType = chargeTransaction.PaymentMethodType, await _transactionRepository.CreateAsync(new Transaction
Details = chargeTransaction.Details {
}); Amount = refund.Amount / 100M,
CreationDate = refund.Created,
OrganizationId = chargeTransaction.OrganizationId,
UserId = chargeTransaction.UserId,
Type = TransactionType.Refund,
Gateway = GatewayType.Stripe,
GatewayId = refund.Id,
PaymentMethodType = chargeTransaction.PaymentMethodType,
Details = chargeTransaction.Details
});
}
} }
} }