From cf9c8d8fe98f6a19dbefb32f47bd7f73e88bf8b6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 3 Sep 2019 17:00:05 -0400 Subject: [PATCH] support PaymentMethodDetails in stripe webhook --- src/Billing/Controllers/StripeController.cs | 29 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Billing/Controllers/StripeController.cs b/src/Billing/Controllers/StripeController.cs index 263beb135..cb86c05e8 100644 --- a/src/Billing/Controllers/StripeController.cs +++ b/src/Billing/Controllers/StripeController.cs @@ -231,17 +231,17 @@ namespace Bit.Billing.Controllers GatewayId = charge.Id }; - if(charge.Source is Card card) + if(charge.Source != null && charge.Source is Card card) { tx.PaymentMethodType = PaymentMethodType.Card; 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.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) { @@ -260,10 +260,31 @@ namespace Bit.Billing.Controllers $"{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) { - _logger.LogWarning("Charge success from unsupported source. " + charge.Id); + _logger.LogWarning("Charge success from unsupported source/method. " + charge.Id); return new OkResult(); }