Exemplo n.º 1
0
        public override PaymentResult TryProcessPayment(PaymentDataBase paymentData)
        {
            if (paymentData.PaymentType == PaymentType.CHECK)
            {
                CheckPaymentData checkPaymentData = paymentData as CheckPaymentData;

                int           referenceNumber = this.paymentsDao.SaveCheckPayment(checkPaymentData);
                PaymentResult paymentResult   = new PaymentResult()
                {
                    CustomerAccountNumber = checkPaymentData.CustomerAccountNumber,
                    PaymentDate           = checkPaymentData.PaymentDate,
                    Success         = true,
                    ReferenceNumber = referenceNumber
                };
                return(paymentResult);
            }
            else if (this.NextPaymentTypeHandler != null)
            {
                return(this.NextPaymentTypeHandler.TryProcessPayment(paymentData));
            }
            else
            {
                throw new ApplicationException("Unknown payment type");
            }
        }
        public PaymentResult ProcessPayment(PaymentDataBase paymentData)
        {
            CheckPaymentData checkPaymentData = paymentData as CheckPaymentData;

            int           referenceNumber = this.paymentsDao.SaveCheckPayment(checkPaymentData);
            PaymentResult paymentResult   = new PaymentResult()
            {
                CustomerAccountNumber = checkPaymentData.CustomerAccountNumber,
                PaymentDate           = checkPaymentData.PaymentDate,
                Success         = true,
                ReferenceNumber = referenceNumber
            };

            return(paymentResult);
        }
        public void TestCheckPayment()
        {
            //Arrange
            PaymentProcessor paymentProcessor = this.CreatePaymentProcessor();

            CheckPaymentData checkPaymentData = new CheckPaymentData()
            {
                CustomerAccountNumber = "00012345",
                PaymentDate           = DateTime.Today,
                Amount            = 100.00m,
                BankRoutingNumber = SampleData.BANK_ROUTING_ONE,
                BankAccountNumber = SampleData.BANK_ACCOUNT_TWO,
                CheckNumber       = "500"
            };

            // Act
            PaymentResult result = paymentProcessor.ProcessPayment(checkPaymentData);

            // Assert
            Assert.True(result.Success);
            Assert.Equal(30, result.ReferenceNumber);
        }
        public int SaveCheckPayment(CheckPaymentData checkData)
        {
            // This would save to a database

            return(30);
        }