public void PaymentCallBack(FormCollection collection)
        {
            int             orderId = _paymentService.GetOrderIdFor(collection);
            GetOrderRequest request = new GetOrderRequest()
            {
                OrderId = orderId
            };

            GetOrderResponse response = _orderService.GetOrder(request);

            OrderPaymentRequest orderPaymentRequest =
                response.Order.ConvertToOrderPaymentRequest();

            TransactionResult transactionResult =
                _paymentService.HandleCallBack(orderPaymentRequest, collection);

            if (transactionResult.PaymentOk)
            {
                SetOrderPaymentRequest paymentRequest = new SetOrderPaymentRequest();
                paymentRequest.Amount          = transactionResult.Amount;
                paymentRequest.PaymentToken    = transactionResult.PaymentToken;
                paymentRequest.PaymentMerchant = transactionResult.PaymentMerchant;
                paymentRequest.OrderId         = orderId;

                _orderService.SetOrderPayment(paymentRequest);
            }
            else
            {
                LoggingFactory.GetLogger().Log(String.Format(
                                                   "Payment not ok for order id {0}, payment token {1}",
                                                   orderId, transactionResult.PaymentToken));
            }
        }
Exemplo n.º 2
0
        public async Task PaymentCallBack(IFormCollection collection)
        {
            int             orderId = _paymentService.GetOrderIdFor(collection);
            GetOrderRequest request = new GetOrderRequest
            {
                OrderId = orderId
            };
            GetOrderResponse    response            = _orderService.GetOrder(request);
            OrderPaymentRequest orderPaymentRequest = _mapper.Map <OrderView, OrderPaymentRequest>(response.Order);
            TransactionResult   transactionResult   = await _paymentService.HandleCallBack(orderPaymentRequest, collection);

            if (transactionResult.PaymentOk)
            {
                SetOrderPaymentRequest paymentRequest = new SetOrderPaymentRequest();
                paymentRequest.Amount          = transactionResult.Amount;
                paymentRequest.PaymentToken    = transactionResult.PaymentToken;
                paymentRequest.PaymentMerchant = transactionResult.PaymentMerchant;
                paymentRequest.OrderId         = orderId;
                paymentRequest.CustomerEmail   = _cookieAuthentication.GetAuthenticationToken();

                _orderService.SetOrderPayment(paymentRequest);
            }
            else
            {
                _logger.LogWarning(string.Format("Payment not ok for order id {0}, payment token {1}", orderId, transactionResult.PaymentToken));
            }
        }
Exemplo n.º 3
0
        public SetOrderPaymentResponse SetOrderPayment(SetOrderPaymentRequest paymentRequest)
        {
            SetOrderPaymentResponse paymentResponse = new SetOrderPaymentResponse();
            Order order = _orderRepository.FindBy(paymentRequest.OrderId);

            try
            {
                order.SetPayment(new Payment(DateTime.Now, paymentRequest.PaymentToken, paymentRequest.PaymentMerchant, paymentRequest.Amount));
                Submit(order, paymentRequest.CustomerEmail);
                _orderRepository.Save(order);
                _uow.Commit();
            }
            catch (OrderAlreadyPaidForException ex)
            {
                // Refund the payment using the payment service.
                _logger.LogError(ex.Message);
            }
            catch (PaymentAmountDoesNotEqualOrderTotalException ex)
            {
                // Refund the payment using the payment service.
                _logger.LogError(ex.Message);
            }

            paymentResponse.Order = _mapper.Map <Order, OrderView>(order);

            return(paymentResponse);
        }
Exemplo n.º 4
0
        public SetOrderPaymentResponse SetOrderPayment(SetOrderPaymentRequest paymentRequest)
        {
            SetOrderPaymentResponse paymentResponse = new SetOrderPaymentResponse();

            Order order = _orderRepository.FindBy(paymentRequest.OrderId);

            try
            {
                order.SetPayment(PaymentFactory.CreatePayment(paymentRequest.PaymentToken,
                                                              paymentRequest.Amount, paymentRequest.PaymentMerchant
                                                              ));

                _orderRepository.Save(order);
                _uow.Commit();
            }
            catch (OrderAlreadyPaidForException ex)
            {
                //  Out of scope of case study: Refund the payment using the payment service...
                LoggingFactory.GetLogger().Log(ex.Message);
            }
            catch (PaymentAmountDoesNotEqualOrderTotalException ex)
            {
                //  Out of scope of case study: Refund the payment using the payment service...
                LoggingFactory.GetLogger().Log(ex.Message);
            }

            paymentResponse.Order = order.ConvertToOrderView();

            return(paymentResponse);
        }