Beispiel #1
0
        public async Task <Token> Create(Customer customer)
        {
            try
            {
                var tokenString   = customer.CardNumber + DateTime.UtcNow.ToString("yyyyMMddHHmm");
                var tokenArrayInt = tokenString.Select(c => int.Parse(c.ToString())).ToArray();
                var rawToken      = ArrayHelpers.GetFromAbsoluteDiff(tokenArrayInt);
                rawToken = ArrayHelpers.RightRotate(rawToken, customer.Cvv);

                tokenString = "";
                foreach (var item in rawToken)
                {
                    tokenString += item;
                }

                Token token = new Token
                {
                    CustomerId = customer.Id,
                    Value      = tokenString
                };

                var newToken = await tokenRepository.Create(token);

                if (newToken != null)
                {
                    return(newToken);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }