diff --git a/src/Core/Models/Business/BillingInfo.cs b/src/Core/Models/Business/BillingInfo.cs index 233defe446..8629698a86 100644 --- a/src/Core/Models/Business/BillingInfo.cs +++ b/src/Core/Models/Business/BillingInfo.cs @@ -15,6 +15,20 @@ namespace Bit.Core.Models.Business public class BillingSource { + public BillingSource(PaymentMethod method) + { + if(method.Card != null) + { + Type = PaymentMethodType.Card; + Description = $"{method.Card.Brand?.ToUpperInvariant()}, *{method.Card.Last4}, " + + string.Format("{0}/{1}", + string.Concat(method.Card.ExpMonth < 10 ? + "0" : string.Empty, method.Card.ExpMonth), + method.Card.ExpYear); + CardBrand = method.Card.Brand; + } + } + public BillingSource(IPaymentSource source) { if(source is BankAccount bankAccount) diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index 1e3d66caab..fb652631f3 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -1216,6 +1216,18 @@ namespace Bit.Core.Services } } } + if(billingInfo.PaymentSource == null) + { + var paymentMethodService = new PaymentMethodService(); + var paymentMethods = paymentMethodService.ListAutoPaging( + new PaymentMethodListOptions { CustomerId = customer.Id, Type = "card" }); + var paymentMethod = paymentMethods.Where(m => m.Card != null) + .OrderByDescending(m => m.Created).FirstOrDefault(); + if(paymentMethod != null) + { + billingInfo.PaymentSource = new BillingInfo.BillingSource(paymentMethod); + } + } var invoices = await invoiceService.ListAsync(new InvoiceListOptions {