Пример #1
0
        public async Task <ActionResult <PlaceOrderResponse> > Place([FromBody] PlaceOrderRequest request)
        {
            _logger.LogInformation($"Place order service call for {request.OrderNumber}...");
            var response = new PlaceOrderResponse();

            try
            {
                await _orderProcessingService.PlaceOrderAsync(request.OrderNumber, request.UserId, request.OrderAmount, request.Gateway, request.Description, request.Callback);

                var order = await _orderProcessingService.GetOrderAsync(request.OrderNumber);

                response.Bills.AddRange(order.Bills.Select(x => (BillingInfoDTO)x).ToList());
            }
            catch (ValidationException ex)
            {
                _logger.LogWarning($"Validations failures: {ex.Message}");
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception occured while placing order: {ex.Message} {ex.StackTrace}");
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
            return(Ok(response));
        }
Пример #2
0
        private async Task <PlaceOrderResult> PlaceOrderAsync(Order newOrder, Customer customer)
        {
            var processPaymentRequest = new ProcessPaymentRequest
            {
                StoreId    = newOrder.StoreId,
                CustomerId = customer.Id,
                PaymentMethodSystemName = newOrder.PaymentMethodSystemName
            };


            var placeOrderResult = await _orderProcessingService.PlaceOrderAsync(processPaymentRequest);

            return(placeOrderResult);
        }
Пример #3
0
        public async Task <IActionResult> OrderConfirmation(string scheduleDate)
        {
            var processPaymentRequest = new ProcessPaymentRequest();
            var customer = await _workContext.GetCurrentCustomerAsync();

            _paymentService.GenerateOrderGuid(processPaymentRequest);
            processPaymentRequest.StoreId                 = _storeContext.GetCurrentStore().Id;
            processPaymentRequest.CustomerId              = customer.Id;
            processPaymentRequest.ScheduleDate            = scheduleDate;
            processPaymentRequest.PaymentMethodSystemName = "Payments.CheckMoneyOrder";
            var placeOrderResult = await _orderProcessingService.PlaceOrderAsync(processPaymentRequest);

            if (placeOrderResult.Success)
            {
                placeOrderResult.PlacedOrder.ScheduleDate = await _dateTimeHelper.ConvertToUserTimeAsync(Convert.ToDateTime(scheduleDate));

                await _orderService.UpdateOrderAsync(placeOrderResult.PlacedOrder);

                return(Ok(new { success = true, message = await _localizationService.GetResourceAsync("Order.Placed.Successfully") }));
            }
            return(Ok(new { success = false, message = string.Join(", ", placeOrderResult.Errors).ToString() }));
        }
Пример #4
0
        public override async Task <IActionResult> ConfirmOrder()
        {
            //validation
            if (_orderSettings.CheckoutDisabled)
            {
                return(RedirectToRoute("ShoppingCart"));
            }

            var cart = await _shoppingCartService.GetShoppingCartAsync(
                await _workContext.GetCurrentCustomerAsync(),
                ShoppingCartType.ShoppingCart,
                (await _storeContext.GetCurrentStoreAsync()).Id);

            if (!cart.Any())
            {
                return(RedirectToRoute("ShoppingCart"));
            }

            if (_orderSettings.OnePageCheckoutEnabled)
            {
                return(RedirectToRoute("CheckoutOnePage"));
            }

            if (await _customerService.IsGuestAsync(await _workContext.GetCurrentCustomerAsync()) && !_orderSettings.AnonymousCheckoutAllowed)
            {
                return(Challenge());
            }

            await ValidateGiftCardAmountsAsync();

            //model
            var model = await _checkoutModelFactory.PrepareConfirmOrderModelAsync(cart);

            try
            {
                //prevent 2 orders being placed within an X seconds time frame
                if (!(await IsMinimumOrderPlacementIntervalValidAsync(await _workContext.GetCurrentCustomerAsync())))
                {
                    throw new Exception(await _localizationService.GetResourceAsync("Checkout.MinOrderPlacementInterval"));
                }

                //place order
                var processPaymentRequest = HttpContext.Session.Get <ProcessPaymentRequest>("OrderPaymentInfo");
                if (processPaymentRequest == null)
                {
                    //Check whether payment workflow is required
                    if (await _orderProcessingService.IsPaymentWorkflowRequiredAsync(cart))
                    {
                        return(RedirectToRoute("CheckoutPaymentInfo"));
                    }

                    processPaymentRequest = new ProcessPaymentRequest();
                }

                _paymentService.GenerateOrderGuid(processPaymentRequest);
                processPaymentRequest.StoreId    = (await _storeContext.GetCurrentStoreAsync()).Id;
                processPaymentRequest.CustomerId = (await _workContext.GetCurrentCustomerAsync()).Id;
                processPaymentRequest.PaymentMethodSystemName = await _genericAttributeService.GetAttributeAsync <string>(await _workContext.GetCurrentCustomerAsync(),
                                                                                                                          NopCustomerDefaults.SelectedPaymentMethodAttribute, (await _storeContext.GetCurrentStoreAsync()).Id);

                HttpContext.Session.Set <ProcessPaymentRequest>("OrderPaymentInfo", processPaymentRequest);

                // Set ABC custom values
                var refNo = HttpContext.Session.GetString("Ref_No");
                if (refNo != null)
                {
                    processPaymentRequest.CustomValues.Add("CC_REFNO", refNo);
                    HttpContext.Session.Remove("Ref_No");
                }
                var authNo = HttpContext.Session.GetString("Auth_No");
                if (authNo != null)
                {
                    processPaymentRequest.CustomValues.Add("AuthCode", authNo);
                    HttpContext.Session.Remove("Auth_No");
                }

                var placeOrderResult = await _orderProcessingService.PlaceOrderAsync(processPaymentRequest);

                if (placeOrderResult.Success)
                {
                    HttpContext.Session.Set <ProcessPaymentRequest>("OrderPaymentInfo", null);
                    var postProcessPaymentRequest = new PostProcessPaymentRequest
                    {
                        Order = placeOrderResult.PlacedOrder
                    };
                    await _paymentService.PostProcessPaymentAsync(postProcessPaymentRequest);

                    if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
                    {
                        //redirection or POST has been done in PostProcessPayment
                        return(Content(await _localizationService.GetResourceAsync("Checkout.RedirectMessage")));
                    }

                    return(RedirectToRoute("CheckoutCompleted", new { orderId = placeOrderResult.PlacedOrder.Id }));
                }

                foreach (var error in placeOrderResult.Errors)
                {
                    model.Warnings.Add(error);
                }
            }
            catch (Exception exc)
            {
                await _logger.WarningAsync(exc.Message, exc);

                model.Warnings.Add(exc.Message);
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }