mirror of
https://github.com/bitwarden/server.git
synced 2024-11-26 12:55:17 +01:00
remove charge and add balance to billing models
This commit is contained in:
parent
2397c6d862
commit
250784d197
@ -11,13 +11,13 @@ namespace Bit.Core.Models.Api
|
||||
public BillingResponseModel(BillingInfo billing)
|
||||
: base("billing")
|
||||
{
|
||||
CreditAmount = billing.CreditAmount;
|
||||
Balance = billing.Balance;
|
||||
PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
|
||||
Transactions = billing.Transactions?.Select(t => new BillingTransaction(t));
|
||||
Invoices = billing.Invoices?.Select(i => new BillingInvoice(i));
|
||||
}
|
||||
|
||||
public decimal CreditAmount { get; set; }
|
||||
public decimal Balance { get; set; }
|
||||
public BillingSource PaymentSource { get; set; }
|
||||
public IEnumerable<BillingInvoice> Invoices { get; set; }
|
||||
public IEnumerable<BillingTransaction> Transactions { get; set; }
|
||||
|
@ -8,9 +8,8 @@ namespace Bit.Core.Models.Business
|
||||
{
|
||||
public class BillingInfo
|
||||
{
|
||||
public decimal CreditAmount { get; set; }
|
||||
public decimal Balance { get; set; }
|
||||
public BillingSource PaymentSource { get; set; }
|
||||
public IEnumerable<BillingCharge> Charges { get; set; } = new List<BillingCharge>();
|
||||
public IEnumerable<BillingInvoice> Invoices { get; set; } = new List<BillingInvoice>();
|
||||
public IEnumerable<BillingTransaction> Transactions { get; set; } = new List<BillingTransaction>();
|
||||
|
||||
@ -85,57 +84,6 @@ namespace Bit.Core.Models.Business
|
||||
public bool NeedsVerification { get; set; }
|
||||
}
|
||||
|
||||
public class BillingCharge
|
||||
{
|
||||
public BillingCharge(Charge charge)
|
||||
{
|
||||
Amount = charge.Amount / 100M;
|
||||
RefundedAmount = charge.AmountRefunded / 100M;
|
||||
PaymentSource = charge.Source != null ? new BillingSource(charge.Source) : null;
|
||||
CreatedDate = charge.Created;
|
||||
FailureMessage = charge.FailureMessage;
|
||||
Refunded = charge.Refunded;
|
||||
Status = charge.Status;
|
||||
InvoiceId = charge.InvoiceId;
|
||||
}
|
||||
|
||||
public BillingCharge(Braintree.Transaction transaction)
|
||||
{
|
||||
Amount = transaction.Amount.GetValueOrDefault();
|
||||
RefundedAmount = 0; // TODO?
|
||||
|
||||
if(transaction.PayPalDetails != null)
|
||||
{
|
||||
PaymentSource = new BillingSource(transaction.PayPalDetails);
|
||||
}
|
||||
else if(transaction.CreditCard != null &&
|
||||
transaction.CreditCard.CardType != Braintree.CreditCardCardType.UNRECOGNIZED)
|
||||
{
|
||||
PaymentSource = new BillingSource(transaction.CreditCard);
|
||||
}
|
||||
else if(transaction.UsBankAccountDetails != null)
|
||||
{
|
||||
PaymentSource = new BillingSource(transaction.UsBankAccountDetails);
|
||||
}
|
||||
|
||||
CreatedDate = transaction.CreatedAt.GetValueOrDefault();
|
||||
FailureMessage = null;
|
||||
Refunded = transaction.RefundedTransactionId != null;
|
||||
Status = transaction.Status.ToString();
|
||||
InvoiceId = null;
|
||||
}
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
public decimal Amount { get; set; }
|
||||
public BillingSource PaymentSource { get; set; }
|
||||
public string Status { get; set; }
|
||||
public string FailureMessage { get; set; }
|
||||
public bool Refunded { get; set; }
|
||||
public bool PartiallyRefunded => !Refunded && RefundedAmount > 0;
|
||||
public decimal RefundedAmount { get; set; }
|
||||
public string InvoiceId { get; set; }
|
||||
}
|
||||
|
||||
public class BillingTransaction
|
||||
{
|
||||
public BillingTransaction(Transaction transaction)
|
||||
|
@ -939,7 +939,7 @@ namespace Bit.Core.Services
|
||||
var customer = await customerService.GetAsync(subscriber.GatewayCustomerId);
|
||||
if(customer != null)
|
||||
{
|
||||
billingInfo.CreditAmount = customer.AccountBalance / 100M;
|
||||
billingInfo.Balance = customer.AccountBalance / 100M;
|
||||
|
||||
if(customer.Metadata?.ContainsKey("btCustomerId") ?? false)
|
||||
{
|
||||
@ -968,14 +968,6 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
var charges = await chargeService.ListAsync(new ChargeListOptions
|
||||
{
|
||||
CustomerId = customer.Id,
|
||||
Limit = 20
|
||||
});
|
||||
billingInfo.Charges = charges?.Data?.OrderByDescending(c => c.Created)
|
||||
.Select(c => new BillingInfo.BillingCharge(c));
|
||||
|
||||
var invoices = await invoiceService.ListAsync(new InvoiceListOptions
|
||||
{
|
||||
CustomerId = customer.Id,
|
||||
|
Loading…
Reference in New Issue
Block a user