コード例 #1
0
        public async Task <string> ProcessPayment(PaymentRequest paymentRequest)
        {
            try
            {
                if (paymentRequest.Amount <= 20)
                {
                    string response = await _cheapPayment.ProcessPayment(paymentRequest);

                    return(response);
                }

                if (paymentRequest.Amount >= 20 && paymentRequest.Amount <= 500)
                {
                    if (await _expensiveRepo.CheckIfPaymentGetwayExist(paymentRequest))
                    {
                        string response = await _expensiveRepo.ProcessPayment(paymentRequest);
                    }
                    else
                    {
                        string response = await _cheapPayment.ProcessPayment(paymentRequest);

                        return(response);
                    }
                }

                bool result = false;

                if (paymentRequest.Amount >= 500) //  PremiumPaymentService
                {
                    result = await _premiumRepo.ProcessPayment(paymentRequest);

                    if (!result)
                    {
                        for (int i = 1; i < 3; i++)
                        {
                            result = await _premiumRepo.ProcessPayment(paymentRequest);

                            if (result)
                            {
                                break;
                            }
                        }
                    }
                }
                if (result)
                {
                    return("Success");
                }
                else
                {
                    return("Faild");
                }
            }
            catch (Exception)
            {
                return("Exception");
            }
        }