Exemple #1
0
        public static bool IsValid(string cardNumber, EnumBrand brand)
        {
            // Visa
            if (Regex.IsMatch(cardNumber, "^(4)") &&
                ((brand & EnumBrand.Visa) != 0))
            {
                return(cardNumber.Length == 13 || cardNumber.Length == 16);
            }

            // MasterCard
            if (Regex.IsMatch(cardNumber, "^(51|52|53|54|55)") &&
                ((brand & EnumBrand.Master) != 0))
            {
                return(cardNumber.Length == 16);
            }

            // Amex
            if (Regex.IsMatch(cardNumber, "^(34|37)") &&
                ((brand & EnumBrand.Amex) != 0))
            {
                return(cardNumber.Length == 15);
            }

            // Diners
            if (Regex.IsMatch(cardNumber, "^(300|301|302|303|304|305|36|38)") &&
                ((brand & EnumBrand.Diners) != 0))
            {
                return(cardNumber.Length == 14);
            }

            return(false);
        }
Exemple #2
0
 public CreditCard(string cardNumber,
                   string holder,
                   int yearExpiration,
                   int monthExpiration,
                   string securityCode,
                   EnumBrand Brand)
 {
     AlterarBrand(Brand);
     AlterarCardNumber(cardNumber, Brand);
     AlterarSecurityCode(securityCode);
     AlterarHolder(holder);
     AlterarDateExpiration(yearExpiration, monthExpiration);
 }
Exemple #3
0
        private void AlterarCardNumber(string cardNumber, EnumBrand brand)
        {
            if (string.IsNullOrEmpty(cardNumber))
            {
                throw new ArgumentException("CardNumber name is required");
            }

            if (!CredcardValidator.IsValid(cardNumber, brand))
            {
                throw new ArgumentException("Número de cartão é invalido");
            }

            this.CardNumber = cardNumber;
        }
Exemple #4
0
 public Payment(string holder,
                string cardNumber,
                int yearExpiration,
                int monthExpiration,
                string securityCode,
                EnumBrand brand,
                decimal amount,
                int installments,
                string softDescriptor)
 {
     AlterarAmount(amount);
     AlterarInstallments(installments);
     AlterarSoftDescriptor(softDescriptor);
     AlterarCreditCard(cardNumber, holder, yearExpiration, monthExpiration, securityCode, brand);
 }
Exemple #5
0
 public CieloSale(string merchantOrderId,
                  string customerName,
                  string cardNumber,
                  string holder,
                  int yearExpiration,
                  int monthExpiration,
                  string securityCode,
                  EnumBrand brand,
                  decimal amount,
                  int installments,
                  string softDescriptor)
 {
     AlterarMerchantOderId(merchantOrderId);
     AlterarCustomer(customerName);
     AlterarPayment(holder, cardNumber, yearExpiration, monthExpiration, securityCode, brand, amount, installments, softDescriptor);
 }
Exemple #6
0
 private void AlterarPayment(string holder,
                             string cardNumber,
                             int yearExpiration,
                             int monthExpiration,
                             string securityCode,
                             EnumBrand brand,
                             decimal amount,
                             int installments,
                             string softDescriptor)
 {
     this.Payment = new Payment(holder,
                                cardNumber,
                                yearExpiration,
                                monthExpiration,
                                securityCode,
                                brand,
                                amount,
                                installments,
                                softDescriptor);
 }
Exemple #7
0
 private void AlterarBrand(EnumBrand brand)
 {
     this.Brand = brand.ToString();
 }
Exemple #8
0
 private void AlterarCreditCard(string cardNumber, string holder, int yearExpiration, int monthExpiration, string securityCode, EnumBrand brand)
 {
     this.CreditCard = new CreditCard(cardNumber, holder, yearExpiration, monthExpiration, securityCode, brand);
 }