private async Task <bool> capturePaymentAsync(ProcessPaymentCommand param) { if (param.Amount <= 20) { return(await _cheapPaymentGateway.CaptureAsync(param.Amount, param.CardNumber, param.SecurityCode)); } else if (param.Amount <= 500) { var maxRetryCount = 2; var retryLeft = maxRetryCount; var isCapturedSuccess = false; while (retryLeft > 0) { try { if (retryLeft == maxRetryCount) { isCapturedSuccess = await _expensivePaymentGateway.CaptureAsync(param.Amount, param.CardNumber, param.SecurityCode); } else { isCapturedSuccess = await _cheapPaymentGateway.CaptureAsync(param.Amount, param.CardNumber, param.SecurityCode); } retryLeft = 0; } catch (Exception) { retryLeft--; if (retryLeft == 0) { throw; } } } return(isCapturedSuccess); } else { var maxRetryCount = 3; var retryLeft = maxRetryCount; var isCapturedSuccess = false; while (retryLeft > 0) { try { isCapturedSuccess = await _premiumPaymentGateway.CaptureAsync(param.Amount, param.CardNumber, param.SecurityCode); retryLeft = 0; } catch (Exception) { retryLeft--; if (retryLeft == 0) { throw; } } } return(isCapturedSuccess); } }