コード例 #1
0
        public void ProcessPayment(PaymentDetail paymentDetail)
        {
            var PremiumAmountString = _configuration["PremiumAmount"];
            int PremiumAmount;

            int.TryParse(PremiumAmountString, out PremiumAmount);
            if (paymentDetail.Amount > PremiumAmount)
            {
                var premiumRetriesString = _configuration["PremiumRetries"];
                int premiumRetries;
                int.TryParse(premiumRetriesString, out premiumRetries);

                var waitTimeString = _configuration["WaitTime"];
                int waitTime;
                int.TryParse(waitTimeString, out waitTime);

                for (int i = 0; i < premiumRetries; i++)
                {
                    PaymentState paymentState = _paymentDbContext.PaymentStates.FirstOrDefault(p => p.PaymentDetailId == paymentDetail.Id);
                    if (paymentState.Status == _configuration["Success"])
                    {
                        break;
                    }
                    ExpensivePaymentGateway expensivePaymentGateway = new ExpensivePaymentGateway(_paymentDbContext, _configuration);
                    expensivePaymentGateway.ProcessPayment(paymentDetail);
                    System.Threading.Thread.Sleep(waitTime * 1000);
                }
            }
        }