Esempio n. 1
0
        public PaymentInfo MakePayment(Card cardInfo, double amount)
        {
            //Logic
            //Use the cardinfo for payment.
            if (VerifyCard(cardInfo))
            {
                ServiceExceptionInfo info = new ServiceExceptionInfo();

                if (amount <= 0)
                {
                    info.ErrorCode   = 101;
                    info.Description = "Invalid amount";
                    info.When        = DateTime.Now;
                    //throw new FaultException<ServiceExceptionInfo>(info, new FaultReason("Error in MakePayment, invalid amount"));
                    throw new FaultException("Error in MakePayment, invalid amount");
                }

                //Original Code Commented To Induce Bug - Not Checking for Balance
                if (cardBal < amount)
                {
                    info.ErrorCode   = 102;
                    info.Description = "Insufficient balance in the card";
                    info.When        = DateTime.Now;
                    //throw new FaultException<ServiceExceptionInfo>(info, new FaultReason("Error in MakePayment, insufficient balance in the card"));
                    throw new FaultException("Error in MakePayment, insufficient balance in the card");
                }
                cardBal       -= amount;
                s_card.Balance = cardBal;
                s_card         = null;
                return(new PaymentInfo()
                {
                    ReferenceNo = Guid.NewGuid().ToString(), Status = PaymentStatus.Success
                });
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Verifies the card to be used for payment
        /// </summary>
        /// <param name="cardInfo"></param>
        /// <returns>True if card information is valid</returns>
        public bool VerifyCard(Card cardInfo)
        {
            string   cardNo   = null;
            string   cvvNo    = null;
            string   mName    = null;
            CardType cardType = CardType.Visa;

            int cardExpMonth = 0;
            int cardExpYear  = 0;

            for (int i = 0; i < cards.Count; i++)
            {
                if (cards[i].CardNo == cardInfo.CardNo)
                {
                    mName        = cards[i].MemberName;
                    cardNo       = cards[i].CardNo;
                    cvvNo        = cards[i].CVV;
                    cardBal      = cards[i].Balance;
                    cardExpMonth = cards[i].ExpMonth;
                    cardExpYear  = cards[i].ExpYear;
                    cardType     = cards[i].CardType;
                    s_card       = cards[i];
                    break;
                }
            }
            if (cardNo == null)
            {
                throw new FaultException("Invalid Card Number or no such card number exists");
            }
            if (cvvNo == null)
            {
                throw new FaultException("Invalid CVV Number");
            }
            if (cardType != cardInfo.Type)
            {
                throw new FaultException("Invalid Card Type");
            }
            if (cvvNo != cardInfo.Cvv2No)
            {
                throw new FaultException("Invalid CVV Number");
            }
            if (mName != cardInfo.Name)
            {
                throw new FaultException("Invalid Member Name");
            }

            if (cardExpMonth != cardInfo.ExpiryMonth)
            {
                throw new FaultException("Invalid Card Expiry Month");
            }
            if (cardExpYear != cardInfo.ExpiryYear)
            {
                throw new FaultException("Invalid Card Expiry Year");
            }
            if (cardExpYear < DateTime.Now.Year)
            {
                throw new FaultException("Card Expired");
            }
            //if (cardExpYear == DateTime.Now.Year && cardExpMonth <= DateTime.Now.Month)
            //{
            //    throw new FaultException("Card Expired");
            //}

            return(true);
        }