Example #1
0
 /// <summary>
 /// 抽取生日信息
 /// </summary>
 /// <returns></returns>
 public DateTime ExtractBirthDate()
 {
     try
     {
         return(DateTime.ParseExact(CardNumber.Substring(6, 8), BIRTH_DATE_FORMAT, null));
     }
     catch (Exception)
     {
         throw new ApplicationException("身份证的出生日期无效");
     }
 }
        public string GetTransactionData()
        {
            string transactionId = Guid.NewGuid().ToString();

            TransactionData += transactionId;
            TransactionData += $":{CardNumber.Substring(CardNumber.Length - 6)}";
            TransactionData += $":{TransactionValue}";
            TransactionData += $":{ReceivedValue}";

            return(TransactionData);
        }
Example #3
0
        //Return holder name and card number with only the first and last 3 digits
        public override string ToString()
        {
            string finalNumber = CardholderName + " - ";

            finalNumber += CardNumber.Substring(0, 3);
            finalNumber += "********";
            finalNumber += CardNumber.Substring(CardNumber.Length - 3, 3);



            return(finalNumber);
        }
Example #4
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append("Payment Type: Credit Card\n");
            sb.Append($"Payment Name: {Name}\n");
            sb.Append($"Name: {CardHolderName}\n");
            sb.Append($"Number: XXXXX-XXXX-XXXX-{CardNumber.Substring(11)}\n");
            sb.Append($"Expiration: {Expiration}\n");
            sb.Append($"Limit: ${Limit}\n");
            sb.Append($"Balance: ${Balance}\n");
            sb.Append($"Available Credit: ${Limit - Balance}\n");
            return(sb.ToString());
        }
Example #5
0
        /// <summary>
        /// 解析身份证
        /// </summary>
        private void _analysis()
        {
            //取省份,地区,区县
            string provCode = CardNumber.Substring(0, 2).PadRight(6, '0');
            string areaCode = CardNumber.Substring(0, 4).PadRight(6, '0');
            string cityCode = CardNumber.Substring(0, 6).PadRight(6, '0');

            for (int i = 0; i < GetAreas().Count; i++)
            {
                if (provCode == GetAreas()[i][0])
                {
                    this.Province = GetAreas()[i][1];
                }
                if (areaCode == GetAreas()[i][0])
                {
                    this.Area = GetAreas()[i][1];
                }
                if (cityCode == GetAreas()[i][0])
                {
                    this.City = GetAreas()[i][1];
                }
                if (Province != null && Area != null && City != null)
                {
                    break;
                }
            }
            //取年龄
            string ageCode = CardNumber.Substring(6, 8);

            try
            {
                int year  = Convert.ToInt16(ageCode.Substring(0, 4));
                int month = Convert.ToInt16(ageCode.Substring(4, 2));
                int day   = Convert.ToInt16(ageCode.Substring(6, 2));
                Age = new DateTime(year, month, day);
            }
            catch
            {
                throw new Exception("非法的出生日期");
            }
            //取性别
            string orderCode = CardNumber.Substring(14, 3);

            this.Sex = Convert.ToInt16(orderCode) % 2 == 0 ? 0 : 1;
            //生成Json对象
            Json = @"prov:'{0}',area:'{1}',city:'{2}',year:'{3}',month:'{4}',day:'{5}',sex:'{6}',number:'{7}'";
            Json = string.Format(Json, Province, Area, City, Age.Year, Age.Month, Age.Day, (Sex == 1 ? "boy" : "gril"), CardNumber);
            Json = "{" + Json + "}";
        }
        public string MaskCardNumber()
        {
            if (CardNumber == null)
            {
                return(null);
            }

            if (CardNumber.Length <= 4)
            {
                return(Regex.Replace(CardNumber, "\\d", "*"));
            }

            return(Regex.Replace(
                       CardNumber.Substring(0, CardNumber.Length - 4),
                       "\\d",
                       "*") +
                   CardNumber.Substring(CardNumber.Length - 4, 4));
        }
Example #7
0
        public override string ToString()
        {
            CreditCardType cardType;
            string         cardLastFiveDigits = null;

            if (CardNumber.Contains('|'))
            {
                CreditCardUtils.GetCardInfoFromToken(CardNumber, out cardType, out cardLastFiveDigits);
            }
            else
            {
                var type = CreditCardUtils.GetCardTypeFromNumber(CardNumber);
                cardType = type ?? CreditCardType.Other;

                if (CardNumber != null && CardNumber.Length > 4)
                {
                    cardLastFiveDigits = CardNumber.Substring(CardNumber.Length - 4, 4);
                }
            }

            return(string.Format("{0} ending in xx{1} - expires {2:MM/yyyy}",
                                 Formats.GetFriendlyName(cardType.ToString()), cardLastFiveDigits, CardExpirationDate));
        }
Example #8
0
            public Cipher(Models.Cipher cipher, IAppSettingsService appSettings)
            {
                CipherModel    = cipher;
                Id             = cipher.Id;
                Shared         = !string.IsNullOrWhiteSpace(cipher.OrganizationId);
                HasAttachments = cipher.Attachments?.Any() ?? false;
                FolderId       = cipher.FolderId;
                Name           = cipher.Name?.Decrypt(cipher.OrganizationId);
                Type           = cipher.Type;

                if (string.IsNullOrWhiteSpace(Name) || Name.Length == 0)
                {
                    NameGroup = "-";
                }
                else if (Char.IsLetter(Name[0]))
                {
                    NameGroup = Name[0].ToString();
                }
                else if (Char.IsDigit(Name[0]))
                {
                    NameGroup = "#";
                }
                else
                {
                    NameGroup = "-";
                }

                switch (cipher.Type)
                {
                case CipherType.Login:
                    LoginUsername = cipher.Login?.Username?.Decrypt(cipher.OrganizationId) ?? " ";
                    LoginUri      = cipher.Login.Uris?.FirstOrDefault()?.Uri?.Decrypt(cipher.OrganizationId) ?? " ";
                    LoginPassword = new Lazy <string>(() => cipher.Login?.Password?.Decrypt(cipher.OrganizationId));
                    LoginTotp     = new Lazy <string>(() => cipher.Login?.Totp?.Decrypt(cipher.OrganizationId));

                    Icon = "login.png";
                    var hostnameUri  = LoginUri;
                    var isWebsite    = false;
                    var imageEnabled = !appSettings.DisableWebsiteIcons;
                    if (hostnameUri.StartsWith("androidapp://"))
                    {
                        Icon = "android.png";
                    }
                    else if (hostnameUri.StartsWith("iosapp://"))
                    {
                        Icon = "apple.png";
                    }
                    else if (imageEnabled && !hostnameUri.Contains("://") && hostnameUri.Contains("."))
                    {
                        hostnameUri = $"http://{hostnameUri}";
                        isWebsite   = true;
                    }
                    else if (imageEnabled)
                    {
                        isWebsite = hostnameUri.StartsWith("http") && hostnameUri.Contains(".");
                    }

                    if (imageEnabled && isWebsite && Uri.TryCreate(hostnameUri, UriKind.Absolute, out Uri u))
                    {
                        var iconsUrl = appSettings.IconsUrl;
                        if (string.IsNullOrWhiteSpace(iconsUrl))
                        {
                            if (!string.IsNullOrWhiteSpace(appSettings.BaseUrl))
                            {
                                iconsUrl = $"{appSettings.BaseUrl}/icons";
                            }
                            else
                            {
                                iconsUrl = "https://icons.bitwarden.net";
                            }
                        }

                        Icon = $"{iconsUrl}/{u.Host}/icon.png";
                    }

                    Subtitle = LoginUsername;
                    break;

                case CipherType.SecureNote:
                    Icon     = "note.png";
                    Subtitle = " ";
                    break;

                case CipherType.Card:
                    CardNumber = cipher.Card?.Number?.Decrypt(cipher.OrganizationId) ?? " ";
                    var cardBrand = cipher.Card?.Brand?.Decrypt(cipher.OrganizationId) ?? " ";
                    CardCode = new Lazy <string>(() => cipher.Card?.Code?.Decrypt(cipher.OrganizationId));

                    Icon     = "card.png";
                    Subtitle = cardBrand;
                    if (!string.IsNullOrWhiteSpace(CardNumber) && CardNumber.Length >= 4)
                    {
                        if (!string.IsNullOrWhiteSpace(CardNumber))
                        {
                            Subtitle += ", ";
                        }
                        Subtitle += ("*" + CardNumber.Substring(CardNumber.Length - 4));
                    }
                    break;

                case CipherType.Identity:
                    var firstName = cipher.Identity?.FirstName?.Decrypt(cipher.OrganizationId) ?? " ";
                    var lastName  = cipher.Identity?.LastName?.Decrypt(cipher.OrganizationId) ?? " ";

                    Icon     = "id.png";
                    Subtitle = " ";
                    if (!string.IsNullOrWhiteSpace(firstName))
                    {
                        Subtitle = firstName;
                    }
                    if (!string.IsNullOrWhiteSpace(lastName))
                    {
                        if (!string.IsNullOrWhiteSpace(Subtitle))
                        {
                            Subtitle += " ";
                        }
                        Subtitle += lastName;
                    }
                    break;

                default:
                    break;
                }
            }
Example #9
0
        private bool Validate()
        {
            try
            {
                if (CardNumber.Length < 12 || CardNumber.Length > 19)
                {
                    return(false);
                }
                var IIN = CardNumber.Substring(0, 6);
                CardType = eCardType.Unknown;
                if (IIN.StartsWith("34") || IIN.StartsWith("37"))
                {
                    CardType = eCardType.AmericanExpress;
                }
                else if (IIN.StartsWith("4"))
                {
                    if (IIN.StartsWith("4026") || IIN.StartsWith("417500") || IIN.StartsWith("4405") || IIN.StartsWith("4508") ||
                        IIN.StartsWith("4844") || IIN.StartsWith("4913") || IIN.StartsWith("4917"))
                    {
                        CardType = eCardType.VisaElectron;
                    }
                    else
                    {
                        CardType = eCardType.Visa;
                    }
                }
                else if (IIN.StartsWith("51") || IIN.StartsWith("52") || IIN.StartsWith("53") || IIN.StartsWith("54") ||
                         IIN.StartsWith("55"))
                {
                    CardType = eCardType.MasterCard;
                }
                else if (IIN.StartsWith("6011") || IIN.StartsWith("644") || IIN.StartsWith("65"))
                {
                    CardType = eCardType.Discover;
                }
                else if (IIN.StartsWith("36") || IIN.StartsWith("38") || IIN.StartsWith("39"))
                {
                    CardType = eCardType.DinersClubInternational;
                }
                else if (IIN.StartsWith("3"))
                {
                    var jcbCheck = Convert.ToInt32(IIN.Substring(0, 4));
                    if (jcbCheck >= 3528 && jcbCheck <= 3589)
                    {
                        CardType = eCardType.JCB;
                    }
                    else
                    {
                        var dinersCheck = Convert.ToInt32(IIN.Substring(0, 3));
                        if (dinersCheck < 306)
                        {
                            CardType = eCardType.DinersClubCarteBlanche;
                        }
                        else if (dinersCheck == 309)
                        {
                            CardType = eCardType.DinersClubInternational;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }

                //// 1.	Starting with the check digit double the value of every other digit
                //// 2.	If doubling of a number results in a two digits number, add up
                ///   the digits to get a single digit number. This will results in eight single digit numbers
                //// 3. Get the sum of the digits
                int sumOfDigits = CardNumber.Where((e) => e >= '0' && e <= '9')
                                  .Reverse()
                                  .Select((e, i) => ((int)e - 48) * (i % 2 == 0 ? 1 : 2))
                                  .Sum((e) => e / 10 + e % 10);


                //// If the final sum is divisible by 10, then the credit card number
                //   is valid. If it is not divisible by 10, the number is invalid.
                return(sumOfDigits % 10 == 0);
            }
            catch
            {
                return(false);
            }
        }
Example #10
0
 /// <summary>
 /// 抽取信息
 /// </summary>
 private void Extract()
 {
     AddressCode = CardNumber.Substring(0, 6);
     Gender      = ((int)CardNumber[CARD_NUMBER_LENGTH - 2]) % 2 == 0 ? Sex.Female : Sex.Male;
     BirthDate   = ExtractBirthDate();
 }
Example #11
0
 public string HiddenCardNumber()
 {
     return($"{CardNumber?.Substring(0, 4)} **** **** ****");
 }
Example #12
0
        private void FrmProcessing_Shown(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            Error  = null;

            var thread = new Thread(new ThreadStart(delegate
            {
                var api          = Properties.Settings.Default.StripeKey;
                var tokenService = new StripeTokenService(api);
                try
                {
                    var description = Description + " for ";
                    var tokenData   = new StripeTokenCreateOptions
                    {
                        CardNumber          = CardNumber,
                        CardExpirationMonth = CardMonth,
                        CardExpirationYear  = CardYear,
                        CardCvc             = CardCVC
                    };

                    if (Person != null)
                    {
                        tokenData.CardAddressLine1   = Person.Address1;
                        tokenData.CardAddressLine2   = Person.Address2;
                        tokenData.CardAddressCity    = Person.City;
                        tokenData.CardAddressState   = Person.State;
                        tokenData.CardAddressZip     = Person.ZipCode;
                        tokenData.CardAddressCountry = Person.Country;
                        tokenData.CardName           = Person.Name;
                        description += Person.Name + " (#" + Person.PeopleID + ")";
                    }
                    else
                    {
                        tokenData.CardName = PayeeName;
                        description       += PayeeName;
                    }

                    var token = tokenService.Create(tokenData);

                    var chargeData = new StripeChargeCreateOptions
                    {
                        TokenId       = token.Id,
                        Description   = description,
                        AmountInCents = Convert.ToInt32(Amount * 100),
                        Currency      = "usd"
                    };
                    var chargeService = new StripeChargeService(api);

                    if (!FirstTry)
                    {
                        // Double-check to see if we already have a charge recently that matches the details of this. Helps with dealing
                        // with timeout scenarios to prevent double-charges.
                        var lastCharges = chargeService.List(20, 0, null);
                        foreach (var charge in lastCharges)
                        {
                            if (charge.StripeCard.Last4 == CardNumber.Substring(CardNumber.Length - 4) &&
                                charge.StripeCard.ExpirationMonth.PadLeft(2, '0') == CardMonth &&
                                charge.StripeCard.ExpirationYear.Substring(2) == CardYear &&
                                charge.AmountInCents == Convert.ToInt32(Amount * 100) &&
                                charge.Description == "Purchases for " + Person.Name + " (#" + Person.PeopleID + ")")
                            {
                                Charge = charge;
                                break;
                            }
                        }
                    }

                    if (Charge == null)
                    {
                        Charge = chargeService.Create(chargeData);
                    }
                }
                catch (StripeException ex)
                {
                    Error = ex;
                }
                _processingDone = true;
            }));

            thread.Start();

            while (!_processingDone)
            {
                Application.DoEvents();
            }

            Cursor       = Cursors.Default;
            DialogResult = DialogResult.OK;
        }
Example #13
0
 public override string ToString()
 {
     return($"You paid ${Amount:0.00} with a credit card ending in {CardNumber.Substring(CardNumber.Length - 4)}");
 }
Example #14
0
 public string Mask()
 {
     return("xxxxxxxxx" + CardNumber.Substring(CardNumber.Length - 3, 3));
 }
 public void FixCardNumber()
 {
     CardNumber = CardNumber.Substring(CardNumber.Length - 4);
 }
Example #16
0
 void extract()
 {
     AddressCode = CardNumber.Substring(0, 6);
     Gender      = ((int)CardNumber[CARD_NUMBER_LENGTH - 2]) % 2 == 0 ? Gender.Female : Gender.Male;
     BirthDate   = extract_birth_date();
 }