mirror of
https://github.com/bitwarden/server.git
synced 2025-02-28 03:51:23 +01:00
handle PaymentMethods for PaymentSource billing info
This commit is contained in:
parent
9686b4bf2b
commit
b11fd2fab8
@ -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)
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user