public async Task <PaymentDto> CreatePaymentAsync(CreatePaymentDto create)
        {
            Logger.LogInformation("About to call External Provider");

            string status = "failed";

            if (create.Amount < 20)
            {
                status = CheapPaymentGateway.MakePayment(create);
            }
            else if (create.Amount > 21 && create.Amount < 500)
            {
                status = ExpensivePaymentGateway.MakePayment(create);
                if (status == "failed")
                {
                    status = CheapPaymentGateway.MakePayment(create);
                }
            }
            else
            {
                for (var i = 0; i < 3; i++)
                {
                    status = PremiumPaymentService.MakePayment(create);
                    if (status != "failed")
                    {
                        break;
                    }
                }
            }

            if (status == "failed")
            {
                return(null);
            }

            Logger.LogInformation("About to Insert new payment entry");
            var paymentInfo = await PaymentRepo.InsertAsync(new Payment()
            {
                CreditCardNumber = create.CreditCardNumber,
                CardHolder       = create.CardHolder,
                ExpirationDate   = create.ExpirationDate,
                SecurityCode     = create.SecurityCode,
                Amount           = create.Amount
            });

            var commitResult = await UnitOfWork.CommitAsync();

            var paymentStatus = await PaymentStatusService.CreatePaymentStatusAsync(new CreatePaymentStatusDto()
            {
                PaymentId = paymentInfo.Entity.Id,
                Status    = status
            });

            return(commitResult == 1 ?  new PaymentDto()
            {
                Id = paymentInfo.Entity.Id,
                Amount = paymentInfo.Entity.Amount,
                Status = paymentStatus != null ? paymentStatus.Status : null
            } : null);
        }
Exemple #2
0
        public async Task <PaymentStatusDto> CreatePaymentStatusAsync(CreatePaymentStatusDto create)
        {
            Logger.LogInformation("About to Insert new payment status entry");

            var paymentStatus = await PaymentStatusRepo.InsertAsync(new PaymentStatus()
            {
                PaymentId = create.PaymentId,
                Status    = create.Status
            });

            var commitResult = await UnitOfWork.CommitAsync();

            return(commitResult == 1 ? new PaymentStatusDto()
            {
                Id = paymentStatus.Entity.Id,
                Status = paymentStatus.Entity.Status
            } : null);
        }