1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-13 00:58:13 -05:00

support PaymentMethodDetails in stripe webhook

This commit is contained in:
Kyle Spearrin 2019-09-03 17:00:05 -04:00
parent 1be6e2008b
commit cf9c8d8fe9

View File

@ -231,17 +231,17 @@ namespace Bit.Billing.Controllers
GatewayId = charge.Id GatewayId = charge.Id
}; };
if(charge.Source is Card card) if(charge.Source != null && charge.Source is Card card)
{ {
tx.PaymentMethodType = PaymentMethodType.Card; tx.PaymentMethodType = PaymentMethodType.Card;
tx.Details = $"{card.Brand}, *{card.Last4}"; tx.Details = $"{card.Brand}, *{card.Last4}";
} }
else if(charge.Source is BankAccount bankAccount) else if(charge.Source != null && charge.Source is BankAccount bankAccount)
{ {
tx.PaymentMethodType = PaymentMethodType.BankAccount; tx.PaymentMethodType = PaymentMethodType.BankAccount;
tx.Details = $"{bankAccount.BankName}, *{bankAccount.Last4}"; tx.Details = $"{bankAccount.BankName}, *{bankAccount.Last4}";
} }
else if(charge.Source is Source source) else if(charge.Source != null && charge.Source is Source source)
{ {
if(source.Card != null) if(source.Card != null)
{ {
@ -260,10 +260,31 @@ namespace Bit.Billing.Controllers
$"{source.AchCreditTransfer.AccountNumber}"; $"{source.AchCreditTransfer.AccountNumber}";
} }
} }
else if(charge.PaymentMethodDetails != null)
{
if(charge.PaymentMethodDetails.Card != null)
{
tx.PaymentMethodType = PaymentMethodType.Card;
tx.Details = $"{charge.PaymentMethodDetails.Card.Brand}, " +
$"*{charge.PaymentMethodDetails.Card.Last4}";
}
else if(charge.PaymentMethodDetails.AchDebit != null)
{
tx.PaymentMethodType = PaymentMethodType.BankAccount;
tx.Details = $"{charge.PaymentMethodDetails.AchDebit.BankName}, " +
$"*{charge.PaymentMethodDetails.AchDebit.Last4}";
}
else if(charge.PaymentMethodDetails.AchCreditTransfer != null)
{
tx.PaymentMethodType = PaymentMethodType.BankAccount;
tx.Details = $"ACH => {charge.PaymentMethodDetails.AchCreditTransfer.BankName}, " +
$"{charge.PaymentMethodDetails.AchCreditTransfer.AccountNumber}";
}
}
if(!tx.PaymentMethodType.HasValue) if(!tx.PaymentMethodType.HasValue)
{ {
_logger.LogWarning("Charge success from unsupported source. " + charge.Id); _logger.LogWarning("Charge success from unsupported source/method. " + charge.Id);
return new OkResult(); return new OkResult();
} }