示例#1
0
        public void ValidExpiryReturnsTrue()
        {
            string expiry = $"12/{_thisYear}";

            Assert.True(
                ExpiryValidator.Validate(expiry));
        }
示例#2
0
        public void InvalidExpiryLengthReturnsFalse()
        {
            string expiry = $"122/{_thisYear}";

            Assert.False(
                ExpiryValidator.Validate(expiry));
        }
示例#3
0
        public void InvalidExpiryYearUpperRangReturnsFalse()
        {
            string expiry = $"22/{_thisYear + 11}";

            Assert.False(
                ExpiryValidator.Validate(expiry));
        }
示例#4
0
        public void InvalidExpiryMarkerReturnsFalse()
        {
            string expiry = $"12-{_thisYear}";

            Assert.False(
                ExpiryValidator.Validate(expiry));
        }
示例#5
0
        /// <summary>
        /// Simulates a payment authorization, invalid expiry or card number or a payment does not match the payment policy returns false as status
        /// </summary>
        /// <param name="paymentAuthorizationRequest"></param>
        /// <returns>Indicating the current payment authorization response in <see cref="PaymentAuthorizationResponse"/>.</returns>
        public PaymentAuthorizationResponse AuthorizePayment(
            PaymentAuthorizationRequest paymentAuthorizationRequest)
        {
            // Check payment based on the payment policy
            if (_paymentPolicy.MaxAllowedAmount < paymentAuthorizationRequest.Amount ||
                _paymentPolicy.MinAllowedAmount > paymentAuthorizationRequest.Amount ||
                _paymentPolicy.AllowedCurrencies.Count(c => c.Code == paymentAuthorizationRequest.Currency) == 0 ||
                !ExpiryValidator.Validate(paymentAuthorizationRequest.Expiry) ||
                !CardNumberValidator.Validate(paymentAuthorizationRequest.CardNumber))
            {
                return(new PaymentAuthorizationResponse(Guid.NewGuid(), false));
            }

            return(new PaymentAuthorizationResponse(Guid.NewGuid(), true));
        }