Exemplo n.º 1
0
        public IActionResult ProcessPayment(PaymentRequest model)
        {
            try
            {
                if (model == null)
                {
                    _logger.LogError(Constants.NULL_REQUEST);
                    return(StatusCode((int)HttpStatusCode.BadRequest, Constants.NULL_REQUEST));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError(Constants.INVALID_REQUEST);
                    return(StatusCode((int)HttpStatusCode.BadRequest, Constants.INVALID_REQUEST));
                }

                var request = _mapper.Map <PaymentRequestModel>(model);

                var created = _paymentManager.StorePayment(request);

                var response = _paymentGatewayManager.ProcessPayment(model);

                created.PaymentState = (response == true) ? PaymentStatus.processed : PaymentStatus.failed;

                _paymentManager.UpdatePayment(created);

                return(StatusCode((int)HttpStatusCode.OK, request));
            }
            catch (Exception ex)
            {
                _logger.LogError(Constants.PROCESSING_ERROR + ex.Message);
                return(StatusCode((int)HttpStatusCode.InternalServerError, Constants.INTERNAL_SERVER_ERROR));
            }
        }
Exemplo n.º 2
0
 public void FinalizeOrder(OrderDetails details)
 {
     inventory.Update(details.ProductNo);
     costing.ApplyDiscounts(details.Price, details.DiscountPercent);
     logistic.ShipProduct(details.ProductName, details.AddressLine1);
     orderVerify.VerifyShippingAddress(details.PinCode);
     payment.ProcessPayment(details.CardNo, details.Price);
 }
Exemplo n.º 3
0
        public bool ProcessOrder3()
        {
            //Do some other things here, then process payment

            bool success = _paymentGateway.ProcessPayment();

            return(success);
        }
Exemplo n.º 4
0
 internal void ProcessPayment(User user, PaymentDetails paymentDetails)
 {
     if (!_userValidationService.ValidateUser(user))
     {
         throw new UserInvalidException();
     }
     _paymentGatewayObject.ProcessPayment(paymentDetails);
 }
Exemplo n.º 5
0
 /// <summary>
 /// making the order
 /// </summary>
 /// <param name="orderDetails"></param>
 public void FinalizeOrder(OrderDetails orderDetails)
 {
     inventory.Update(orderDetails.ProductNo);
     orderVerify.VerifyShippingAddress(orderDetails.PinCode);
     orderDetails.Price = costManger.ApplyDiscounts(orderDetails.Price, orderDetails.DiscountPercent);
     paymentGateWay.VerifyCardDetails(orderDetails.CardNo);
     paymentGateWay.ProcessPayment(orderDetails.CardNo, orderDetails.Price);
     logistics.ShipProduct(orderDetails.ProductName, string.Format($"{orderDetails.AddressLine1}, {orderDetails.AddressLine2} - {orderDetails.PinCode}."));
 }
Exemplo n.º 6
0
        public async Task <PaymentStatus> ProcessPayment(Payment payment)
        {
            if (CanProcessPayment(payment))
            {
                return(await HandlePayment(payment));
            }

            return(await NextGateway.ProcessPayment(payment));
        }
Exemplo n.º 7
0
        public PaymentStatusVM ProcessPaymentRequest(PaymentRequestVM paymentRequest)
        {
            GatewayFactory gatewayFactory = new GatewayFactory(unitOfWork);

            IPaymentGateway paymentGateway = gatewayFactory.GetPaymentGateway(paymentRequest.Amount);

            PaymentInfo pi = mapper.Map <PaymentRequestVM, PaymentInfo>(paymentRequest);

            return(paymentGateway.ProcessPayment(pi));
        }
        public bool Update(Order order)
        {
            if (_paymentGateWay.VerifyCardDetails(order))
            {
                _costManger.ApplyDiscounts(order);
                _paymentGateWay.ProcessPayment(order);
                return(InternalUpdate(order));
            }

            return(false);
        }
        private PayStateDto ProcessPaymentStateDto(IPaymentGateway payGateway, PayRequestDto payReqDto, Payment payEntity)
        {
            var paymentSateDto = payGateway.ProcessPayment(payReqDto);
            var payStEntity    = new PaymentState()
            {
                Payment = payEntity, PayId = payEntity.PayId, CreatedDate = paymentSateDto.PaymentStateDate, State = paymentSateDto.PayState.ToString()
            };

            payStEntity = payStateRepo.Create(payStEntity);
            return(paymentSateDto);
        }
Exemplo n.º 10
0
        public async Task <PaymentState> ProcessPaymentState(IPaymentGateway paymentGateway, int id)
        {
            var State        = paymentGateway.ProcessPayment();
            var paymentState = new PaymentState
            {
                paymentState = State.paymentState,
                PaymentId    = id
            };
            await _unitOfWork.paymentStates.Add(paymentState);

            return(State);
        }
Exemplo n.º 11
0
        private async Task <PaymentStateDto> ProcessPaymentStateDto(IPaymentGateway paymentGateway, PaymentRequestDto paymentRequestDto, Payment paymentEntity)
        {
            var paymentStateDto             = paymentGateway.ProcessPayment(paymentRequestDto);
            var paymentStateEntityProcessed = new PaymentState()
            {
                Payment = paymentEntity, PaymentId = paymentEntity.PaymentId, CreatedDate = paymentStateDto.PaymentStateDate, State = paymentStateDto.PaymentState.ToString()
            };

            paymentStateEntityProcessed = await _paymentStateRepository.Create(paymentStateEntityProcessed);

            return(paymentStateDto);
        }
Exemplo n.º 12
0
        public async Task <bool> ProcessPayment(ProcessPaymentModel model)
        {
            try
            {
                //Adding Payment
                var payment = new Payment
                {
                    CreditCardNumber = model.CreditCardNumber,
                    CardHolder       = model.CardHolder,
                    ExpirationDate   = model.ExpirationDate,
                    SecurityCode     = model.SecurityCode,
                    Amount           = model.Amount
                };
                _uow.Add(payment);
                await _uow.CommitAsync();

                //Adding Payment Status as Initial - Pending
                var paymentStatus = new PaymentStatus
                {
                    PaymentId = payment.Id,
                    StatusId  = (int)TransactionStatus.Pending
                };
                _uow.Add(paymentStatus);

                paymentStatus = new PaymentStatus()
                {
                    PaymentId = payment.Id
                };

                var             factory        = new PaymentGatewayFactory();
                IPaymentGateway paymentGateway = factory.GetPaymentGateway(model.Amount);

                if (await paymentGateway.ProcessPayment())
                {
                    paymentStatus.StatusId = (int)TransactionStatus.Processed;
                }
                else
                {
                    paymentStatus.StatusId = (int)TransactionStatus.Failed;
                }

                _uow.Add(paymentStatus);
                await _uow.CommitAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw new BadRequestException(ex.Message);
            }
        }
Exemplo n.º 13
0
        private PaymentStateViewModel ProcessPayment(IPaymentGateway gateway, Payment entity)
        {
            var request      = gateway.ProcessPayment();
            var paymentState = new PaymentState()
            {
                PaymentId   = entity.Id,
                CreatedDate = request.CreatedDate,
                State       = request.State,
                Id          = new Guid()
            };

            db.PaymentStates.Add(paymentState);
            return(request);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Processes the payment.
        /// </summary>
        private void ProcessPayment()
        {
            // If total is 0, we do not need to proceed
            if (OrderGroup.Total == 0)
            {
                return;
            }

            // Start Charging!
            PaymentMethodDto methods = PaymentManager.GetPaymentMethods(Thread.CurrentThread.CurrentCulture.Name);

            foreach (OrderForm orderForm in OrderGroup.OrderForms)
            {
                foreach (Payment payment in orderForm.Payments)
                {
                    PaymentMethodDto.PaymentMethodRow[] rows = (PaymentMethodDto.PaymentMethodRow[])methods.PaymentMethod.Select(String.Format("PaymentMethodId = '{0}'", payment.PaymentMethodId));

                    // If we couldn't find payment method specified, generate an error
                    if (rows == null || rows.Length == 0)
                    {
                        throw new MissingMethodException(String.Format("Specified payment method \"{0}\" has not been defined.", payment.PaymentMethodId));
                    }

                    Logger.Debug(String.Format("Getting the type \"{0}\".", rows[0].ClassName));
                    Type type = Type.GetType(rows[0].ClassName);
                    if (type == null)
                    {
                        throw new TypeLoadException(String.Format("Specified payment method class \"{0}\" can not be created.", rows[0].ClassName));
                    }

                    Logger.Debug(String.Format("Creating instance of \"{0}\".", type.Name));
                    IPaymentGateway provider = (IPaymentGateway)Activator.CreateInstance(type);

                    provider.Settings = CreateSettings(rows[0]);

                    string message = "";
                    Logger.Debug(String.Format("Processing the payment."));
                    if (!provider.ProcessPayment(payment, ref message))
                    {
                        throw new PaymentException(PaymentException.ErrorType.ProviderError, "", String.Format(message));
                    }
                    Logger.Debug(String.Format("Payment processed."));
                    PostProcessPayment(payment);

                    // TODO: add message to transaction log
                }
            }
        }
Exemplo n.º 15
0
        public ActionResult Post([FromBody] PaymentRequest request)
        {
            try
            {
                var response = _paymentGateway.ProcessPayment(request);
                if (response == null)
                {
                    return(StatusCode((int)HttpStatusCode.NotFound));
                }

                return(StatusCode((int)HttpStatusCode.OK, response));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error Processing Payment", ex);
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }
        }
 public override void MakePayment(IPaymentGateway paymentGateway)
 {
     paymentGateway.ProcessPayment("G Pay Payment processed");
 }
Exemplo n.º 17
0
 public void SubmitPayment(decimal amount)
 {
     _mPaymentGateway.ProcessPayment(amount, this);
 }
        /// <summary>
        /// Processes the payment.
        /// </summary>
        private void ProcessPayment()
        {
            // If total is 0, we do not need to proceed
            if (OrderGroup.Total == 0 || OrderGroup is PaymentPlan)
            {
                return;
            }

            // Start Charging!
            PaymentMethodDto methods = PaymentManager.GetPaymentMethods(/*Thread.CurrentThread.CurrentCulture.Name*/ String.Empty);

            foreach (OrderForm orderForm in OrderGroup.OrderForms)
            {
                foreach (Payment payment in orderForm.Payments)
                {
                    if (this.Payment != null && !this.Payment.Equals(payment))
                    {
                        continue;
                    }

                    //Do not process payments with status Processing and Fail
                    var paymentStatus = PaymentStatusManager.GetPaymentStatus(payment);
                    if (paymentStatus != PaymentStatus.Pending)
                    {
                        continue;
                    }

                    PaymentMethodDto.PaymentMethodRow paymentMethod = methods.PaymentMethod.FindByPaymentMethodId(payment.PaymentMethodId);

                    // If we couldn't find payment method specified, generate an error
                    if (paymentMethod == null)
                    {
                        throw new MissingMethodException(String.Format("Specified payment method \"{0}\" has not been defined.", payment.PaymentMethodId));
                    }

                    Logger.Debug(String.Format("Getting the type \"{0}\".", paymentMethod.ClassName));
                    Type type = Type.GetType(paymentMethod.ClassName);
                    if (type == null)
                    {
                        throw new TypeLoadException(String.Format("Specified payment method class \"{0}\" can not be created.", paymentMethod.ClassName));
                    }

                    Logger.Debug(String.Format("Creating instance of \"{0}\".", type.Name));
                    IPaymentGateway provider = (IPaymentGateway)Activator.CreateInstance(type);

                    provider.Settings = CreateSettings(paymentMethod);

                    string message = "";
                    Logger.Debug(String.Format("Processing the payment."));
                    if (provider.ProcessPayment(payment, ref message))
                    {
                        Mediachase.Commerce.Orders.Managers.PaymentStatusManager.ProcessPayment(payment);
                    }
                    else
                    {
                        throw new PaymentException(PaymentException.ErrorType.ProviderError, "", String.Format(message));
                    }
                    Logger.Debug(String.Format("Payment processed."));
                    PostProcessPayment(payment);

                    // TODO: add message to transaction log
                }
            }
        }
Exemplo n.º 19
0
        public bool ProcessOrder()
        {
            bool success = _paymentGateway.ProcessPayment();

            return(success);
        }
Exemplo n.º 20
0
 public override void MakePayment(IPaymentGateway paymentGateway)
 {
     paymentGateway.ProcessPayment("Debit card payment");
 }