<commit_before>﻿using Bit.Core.Enums;
using Bit.Core.Models.Table;
using Stripe;
using System;
using System.Collections.Generic;

namespace Bit.Core.Models.Business
{
    public class BillingInfo
    {
        public decimal Balance { get; set; }
        public BillingSource PaymentSource { get; set; }
        public IEnumerable<BillingInvoice> Invoices { get; set; } = new List<BillingInvoice>();
        public IEnumerable<BillingTransaction> Transactions { get; set; } = new List<BillingTransaction>();

        public class BillingSource
        {
            public BillingSource(IPaymentSource source)
            {
                if(source is BankAccount bankAccount)
                {
                    Type = PaymentMethodType.BankAccount;
                    Description = $"{bankAccount.BankName}, *{bankAccount.Last4} - " +
                        (bankAccount.Status == "verified" ? "verified" :
                        bankAccount.Status == "errored" ? "invalid" :
                        bankAccount.Status == "verification_failed" ? "verification failed" : "unverified");
                    NeedsVerification = bankAccount.Status == "new" || bankAccount.Status == "validated";
                }
                else if(source is Card card)
                {
                    Type = PaymentMethodType.Card;
                    Description = $"{card.Brand}, *{card.Last4}, " +
                        string.Format("{0}/{1}",
                            string.Concat(card.ExpMonth < 10 ?
                                "0" : string.Empty, card.ExpMonth),
                            card.ExpYear);
                    CardBrand = card.Brand;
                }
            }

            public BillingSource(Braintree.PaymentMethod method)
            {
                if(method is Braintree.PayPalAccount paypal)
                {
                    Type = PaymentMethodType.PayPal;
                    Description = paypal.Email;
                }
                else if(method is Braintree.CreditCard card)
                {
                    Type = PaymentMethodType.Card;
                    Description = $"{card.CardType.ToString()}, *{card.LastFour}, " +
                        string.Format("{0}/{1}",
                            string.Concat(card.ExpirationMonth.Length == 1 ?
                                "0" : string.Empty, card.ExpirationMonth),<commit_msg>support for stripe sources in billing info<commit_after>﻿using Bit.Core.Enums;
using Bit.Core.Models.Table;
using Stripe;
using System;
using System.Collections.Generic;

namespace Bit.Core.Models.Business
{
    public class BillingInfo
    {
        public decimal Balance { get; set; }
        public BillingSource PaymentSource { get; set; }
        public IEnumerable<BillingInvoice> Invoices { get; set; } = new List<BillingInvoice>();
        public IEnumerable<BillingTransaction> Transactions { get; set; } = new List<BillingTransaction>();

        public class BillingSource
        {
            public BillingSource(IPaymentSource source)
            {
                if(source is BankAccount bankAccount)
                {
                    Type = PaymentMethodType.BankAccount;
                    Description = $"{bankAccount.BankName}, *{bankAccount.Last4} - " +
                        (bankAccount.Status == "verified" ? "verified" :
                        bankAccount.Status == "errored" ? "invalid" :
                        bankAccount.Status == "verification_failed" ? "verification failed" : "unverified");
                    NeedsVerification = bankAccount.Status == "new" || bankAccount.Status == "validated";
                }
                else if(source is Card card)
                {
                    Type = PaymentMethodType.Card;
                    Description = $"{card.Brand}, *{card.Last4}, " +
                        string.Format("{0}/{1}",
                            string.Concat(card.ExpMonth < 10 ?
                                "0" : string.Empty, card.ExpMonth),
                            card.ExpYear);
                    CardBrand = card.Brand;
                }
                else if(source is Source src && src.Card != null)
                {
                    Type = PaymentMethodType.Card;
                    Description = $"{src.Card.Brand}, *{src.Card.Last4}, " +
                        string.Format("{0}/{1}",
                            string.Concat(src.Card.ExpMonth < 10 ?
                                "0" : string.Empty, src.Card.ExpMonth),
                            src.Card.ExpYear);
                    CardBrand = src.Card.Brand;
                }
            }

            public BillingSource(Braintree.PaymentMethod method)
            {
                if(method is Braintree.PayPalAccount paypal)
                {
                    Type = PaymentMethodType.PayPal;
                    Description = paypal.Email;
                }
                else if(method is Braintree.CreditCard card)
                {
                    Type = PaymentMethodType.Card;
                    Description = $"{card.CardType.ToString()}, *{card.LastFour}, " +
                        string.Format("{0}/{1}",
                            string.Concat(card.ExpirationMonth.Length == 1 ?
                                "0" : string.Empty, card.ExpirationMonth),
{'fraction_non_alphanumeric': 0.10071001494768311, 'fraction_numerical': 0.00523168908819133, 'mean_word_length': 1.387600356824264, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '658873', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1282, 'n_words': 258}