Пример #1
0
        public async Task <IActionResult> ApplyCashBack([FromBody] CreditCardActions creditCardActions)
        {
            logger.LogInformation($"Inside {nameof(ApplyCashBack)} method.");
            string result = await creditCardBiz.AddCashBackAsync(creditCardActions);

            return(PackageData(result, HttpStatusCode.Accepted));
        }
Пример #2
0
        public async Task <IActionResult> ChargeCreditCard([FromBody] CreditCardActions creditCardActions)
        {
            logger.LogInformation($"Inside {nameof(ChargeCreditCard)} Method.");
            string result = await creditCardBiz.ChargeCreditCardAsync(creditCardActions);

            return(PackageData(result, System.Net.HttpStatusCode.Accepted));
        }
Пример #3
0
        public async Task <string> ChargeCreditCardAsync(CreditCardActions creditCardActions)
        {
            logger.LogDebug($"Within {nameof(ChargeCreditCardAsync)} method.");
            logger.LogDebug($"Check the Card Details first.");

            CreditCard creditCard = await creditCardService.GetCreditCardInfoAsync(creditCardActions.CardHolderName);

            if (creditCard == null)
            {
                ErrorMessages.Add($"{creditCardActions.CardHolderName}:No Credit Card Exists for {creditCardActions.CardHolderName}");
                return("No Credit Card Exists with the Given Data");
            }

            decimal currentAvailableLimit = creditCard.TotalCreditLimit;

            if (creditCardActions.Amount < currentAvailableLimit)
            {
                creditCard.Balance          += creditCardActions.Amount;
                creditCard.TotalCreditLimit -= creditCardActions.Amount;
                string response = await creditCardService.ChargeCreditCardAsync(creditCard);

                if (response == "success")
                {
                    logger.LogInformation($"Credit Card Added Successfully");
                    return($"{creditCard.CardHolderName}:${creditCard.Balance}");
                }
                else
                {
                    ErrorMessages.Add($"{creditCard.CardHolderName}: Something went wrong while Charging the CreditCard {creditCard.CardNumber}");
                    return($"Something went wrong while Charging the CreditCard {creditCard.CardNumber}");
                }
            }
            else
            {
                ErrorMessages.Add($"{creditCard.CardHolderName}:InSufficient Funds ${creditCard.Balance} available to process the charge ${creditCardActions.Amount}.");
                return($"{creditCard.CardHolderName}:InSufficient Funds ${creditCard.Balance} available to process the charge ${creditCardActions.Amount}.");
            }
        }
Пример #4
0
        public async Task <string> AddCashBackAsync(CreditCardActions creditCardActions)
        {
            logger.LogDebug($"Within {nameof(AddCashBackAsync)} method.");
            logger.LogDebug($"Check the Card Details first.");

            CreditCard creditCard = await creditCardService.GetCreditCardInfoAsync(creditCardActions.CardHolderName);

            if (creditCard == null)
            {
                ErrorMessages.Add($"{creditCardActions.CardHolderName}:No Credit Card Exists for {creditCardActions.CardHolderName}");
                return($"No Credit Card Exists for {creditCardActions.CardHolderName}");
            }

            decimal currentBalance = creditCard.Balance;

            if (currentBalance != 0)
            {
                creditCard.Balance -= creditCardActions.Amount;
            }
            else
            {
                ErrorMessages.Add($"{creditCardActions.CardHolderName} : Cannot add Credits without Any Charges on this Card {creditCard.CardNumber} with Balance {creditCard.Balance}");
                return($"{creditCardActions.CardHolderName} : Cannot add Credits without Any Charges on this Card {creditCard.CardNumber} with Balance {creditCard.Balance}");
            }

            string response = await creditCardService.ChargeCreditCardAsync(creditCard);

            if (response == "success")
            {
                logger.LogInformation($"Credit Card Added Successfully");
                return($"{creditCard.CardHolderName}:${creditCard.Balance}");
            }
            else
            {
                return($"{creditCard.CardHolderName}:Something went wrong while Charging the CreditCard {creditCard.CardNumber} with Amount {creditCardActions.Amount}");
            }
        }