public async Task <ActionResult> CreateOrder(orderModel.BankCardInfo bankCardInfo)
        {
            EnsureCartExists();

            //Need lock to prevent concurrent access to same cart
            using (await AsyncLock.GetLockByKey(GetAsyncLockCartKey(WorkContext.CurrentCart)).LockAsync())
            {
                var cartBuilder = await LoadOrCreateCartAsync();

                var order = await _orderApi.OrderModule.CreateOrderFromCartAsync(cartBuilder.Cart.Id);

                //Raise domain event
                await _orderPlacedEventPublisher.PublishAsync(new OrderPlacedEvent(order.ToCustomerOrder(WorkContext.AllCurrencies, WorkContext.CurrentLanguage), cartBuilder.Cart));


                orderModel.ProcessPaymentResult processingResult = null;
                var incomingPayment = order.InPayments != null?order.InPayments.FirstOrDefault() : null;

                if (incomingPayment != null)
                {
                    processingResult = await _orderApi.OrderModule.ProcessOrderPaymentsAsync(order.Id, incomingPayment.Id, bankCardInfo);
                }

                await cartBuilder.RemoveCartAsync();

                return(Json(new { order, orderProcessingResult = processingResult, paymentMethod = incomingPayment != null ? incomingPayment.PaymentMethod : null }));
            }
        }
 public static ProcessPaymentResult ToProcessPaymentResult(this orderDto.ProcessPaymentResult processPaymentResultDto, CustomerOrder order)
 {
     return(new ProcessPaymentResult()
     {
         Error = processPaymentResultDto.Error,
         HtmlForm = processPaymentResultDto.HtmlForm,
         IsSuccess = processPaymentResultDto.IsSuccess ?? false,
         NewPaymentStatus = processPaymentResultDto.NewPaymentStatus,
         OuterId = processPaymentResultDto.OuterId,
         PaymentMethod = processPaymentResultDto.PaymentMethod?.ToPaymentMethod(order),
         RedirectUrl = processPaymentResultDto.RedirectUrl
     });
 }