示例#1
0
        public PaymentState PaymentProcess(PaymentDto payment, PaymentState paymentState)
        {
            if (payment.Amount <= 20)
            {
                paymentState.State = _cheapPaymentGateway.PaymentProcessCheap(payment).ToString();
            }
            else if (payment.Amount > 20 && payment.Amount <= 500)
            {
                paymentState.State = _expensivePaymentGateway.PaymentProcessExpensive(payment).ToString();
                if (paymentState.State == PaymentStateEnum.Failed.ToString())
                {
                    paymentState.State = _cheapPaymentGateway.PaymentProcessCheap(payment).ToString();
                }
            }
            else
            {
                int count = 0;
                while (count < 3)
                {
                    count++;
                    paymentState.State = _expensivePaymentGateway.PaymentProcessExpensive(payment).ToString();
                    if (paymentState.State == PaymentStateEnum.Processed.ToString())
                    {
                        break;
                    }
                }
            }

            PaymentStateUpdate(paymentState);
            return(paymentState);
        }