mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 19:14:32 -05:00
[AC-2381][AC-2382] As a billing system, I need to store a transaction when a charge has succeeded for a provider (#4115)
* Add the providerId to the transaction object Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Refactor to check if providerId hasValue before return Signed-off-by: Cy Okeke <cokeke@bitwarden.com> --------- Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
This commit is contained in:
parent
cb9ec27228
commit
ba93c0008b
@ -533,8 +533,8 @@ public class StripeController : Controller
|
|||||||
if (parentTransaction == null)
|
if (parentTransaction == null)
|
||||||
{
|
{
|
||||||
// Attempt to create a transaction for the charge if it doesn't exist
|
// Attempt to create a transaction for the charge if it doesn't exist
|
||||||
var (organizationId, userId) = await GetEntityIdsFromChargeAsync(charge);
|
var (organizationId, userId, providerId) = await GetEntityIdsFromChargeAsync(charge);
|
||||||
var tx = FromChargeToTransaction(charge, organizationId, userId);
|
var tx = FromChargeToTransaction(charge, organizationId, userId, providerId);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parentTransaction = await _transactionRepository.CreateAsync(tx);
|
parentTransaction = await _transactionRepository.CreateAsync(tx);
|
||||||
@ -605,14 +605,14 @@ public class StripeController : Controller
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var (organizationId, userId) = await GetEntityIdsFromChargeAsync(charge);
|
var (organizationId, userId, providerId) = await GetEntityIdsFromChargeAsync(charge);
|
||||||
if (!organizationId.HasValue && !userId.HasValue)
|
if (!organizationId.HasValue && !userId.HasValue)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Charge success has no subscriber ids. {ChargeId}", charge.Id);
|
_logger.LogWarning("Charge success has no subscriber ids. {ChargeId}", charge.Id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var transaction = FromChargeToTransaction(charge, organizationId, userId);
|
var transaction = FromChargeToTransaction(charge, organizationId, userId, providerId);
|
||||||
if (!transaction.PaymentMethodType.HasValue)
|
if (!transaction.PaymentMethodType.HasValue)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Charge success from unsupported source/method. {ChargeId}", charge.Id);
|
_logger.LogWarning("Charge success from unsupported source/method. {ChargeId}", charge.Id);
|
||||||
@ -759,7 +759,7 @@ public class StripeController : Controller
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="charge"></param>
|
/// <param name="charge"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<(Guid?, Guid?)> GetEntityIdsFromChargeAsync(Charge charge)
|
private async Task<(Guid?, Guid?, Guid?)> GetEntityIdsFromChargeAsync(Charge charge)
|
||||||
{
|
{
|
||||||
Guid? organizationId = null;
|
Guid? organizationId = null;
|
||||||
Guid? userId = null;
|
Guid? userId = null;
|
||||||
@ -775,9 +775,9 @@ public class StripeController : Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (organizationId.HasValue || userId.HasValue)
|
if (organizationId.HasValue || userId.HasValue || providerId.HasValue)
|
||||||
{
|
{
|
||||||
return (organizationId, userId);
|
return (organizationId, userId, providerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var subscriptions = await _stripeFacade.ListSubscriptions(new SubscriptionListOptions
|
var subscriptions = await _stripeFacade.ListSubscriptions(new SubscriptionListOptions
|
||||||
@ -794,13 +794,13 @@ public class StripeController : Controller
|
|||||||
|
|
||||||
(organizationId, userId, providerId) = GetIdsFromMetadata(subscription.Metadata);
|
(organizationId, userId, providerId) = GetIdsFromMetadata(subscription.Metadata);
|
||||||
|
|
||||||
if (organizationId.HasValue || userId.HasValue)
|
if (organizationId.HasValue || userId.HasValue || providerId.HasValue)
|
||||||
{
|
{
|
||||||
return (organizationId, userId);
|
return (organizationId, userId, providerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (null, null);
|
return (null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -809,8 +809,9 @@ public class StripeController : Controller
|
|||||||
/// <param name="charge"></param>
|
/// <param name="charge"></param>
|
||||||
/// <param name="organizationId"></param>
|
/// <param name="organizationId"></param>
|
||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
|
/// /// <param name="providerId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static Transaction FromChargeToTransaction(Charge charge, Guid? organizationId, Guid? userId)
|
private static Transaction FromChargeToTransaction(Charge charge, Guid? organizationId, Guid? userId, Guid? providerId)
|
||||||
{
|
{
|
||||||
var transaction = new Transaction
|
var transaction = new Transaction
|
||||||
{
|
{
|
||||||
@ -818,6 +819,7 @@ public class StripeController : Controller
|
|||||||
CreationDate = charge.Created,
|
CreationDate = charge.Created,
|
||||||
OrganizationId = organizationId,
|
OrganizationId = organizationId,
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
|
ProviderId = providerId,
|
||||||
Type = TransactionType.Charge,
|
Type = TransactionType.Charge,
|
||||||
Gateway = GatewayType.Stripe,
|
Gateway = GatewayType.Stripe,
|
||||||
GatewayId = charge.Id
|
GatewayId = charge.Id
|
||||||
|
Loading…
x
Reference in New Issue
Block a user