コード例 #1
0
        public async Task <ActionResult> CreateOrder([FromBody] orderModel.BankCardInfo bankCardInfo)
        {
            EnsureCartExists();

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

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

                var taskList = new List <Task>
                {
                    //Raise domain event asynchronously
                    _publisher.Publish(new OrderPlacedEvent(WorkContext, order.ToCustomerOrder(WorkContext.AllCurrencies, WorkContext.CurrentLanguage), cartBuilder.Cart)),
                    //Remove the cart asynchronously
                    cartBuilder.RemoveCartAsync()
                };
                //Process order asynchronously
                var incomingPayment = order.InPayments != null?order.InPayments.FirstOrDefault() : null;

                Task <orderModel.ProcessPaymentResult> processPaymentTask = null;
                if (incomingPayment != null)
                {
                    processPaymentTask = _orderApi.ProcessOrderPaymentsAsync(order.Id, incomingPayment.Id, bankCardInfo);
                    taskList.Add(processPaymentTask);
                }
                await Task.WhenAll(taskList.ToArray());

                return(Json(new { order, orderProcessingResult = processPaymentTask != null ? await processPaymentTask : null, paymentMethod = incomingPayment != null ? incomingPayment.PaymentMethod : null }));
            }
        }
コード例 #2
0
        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 }));
            }
        }
コード例 #3
0
        public virtual orderDto.BankCardInfo ToBankCardInfoDto(BankCardInfo model)
        {
            orderDto.BankCardInfo retVal = null;
            if (model != null)
            {
                retVal = new orderDto.BankCardInfo();
                retVal.InjectFrom <NullableAndEnumValueInjecter>(model);
            }

            return(retVal);
        }
コード例 #4
0
        public virtual orderDto.BankCardInfo ToBankCardInfoDto(BankCardInfo model)
        {
            orderDto.BankCardInfo retVal = null;
            if (model != null)
            {
                retVal = new orderDto.BankCardInfo();
                retVal.BankCardCVV2   = model.BankCardCVV2;
                retVal.BankCardMonth  = model.BankCardMonth;
                retVal.BankCardNumber = model.BankCardNumber;
                retVal.BankCardType   = model.BankCardType;
                retVal.BankCardYear   = model.BankCardYear;
                retVal.CardholderName = model.CardholderName;
            }

            return(retVal);
        }
コード例 #5
0
        public static orderDto.BankCardInfo ToBankCardInfoDto(this BankCardInfo model)
        {
            orderDto.BankCardInfo retVal = null;
            if (model != null)
            {
                retVal = new orderDto.BankCardInfo
                {
                    BankCardCVV2   = model.BankCardCVV2,
                    BankCardMonth  = model.BankCardMonth,
                    BankCardNumber = model.BankCardNumber,
                    BankCardType   = model.BankCardType,
                    BankCardYear   = model.BankCardYear,
                    CardholderName = model.CardholderName
                };
            }

            return(retVal);
        }
コード例 #6
0
        public async Task <ActionResult> ProcessOrderPayment(string orderNumber, string paymentNumber, orderModel.BankCardInfo bankCardInfo)
        {
            //Need lock to prevent concurrent access to same order
            using (await AsyncLock.GetLockByKey(GetAsyncLockKey(orderNumber, WorkContext)).LockAsync())
            {
                var orderDto = await GetOrderDtoByNumber(orderNumber);

                var paymentDto = orderDto.InPayments.FirstOrDefault(x => x.Number.EqualsInvariant(paymentNumber));
                if (paymentDto == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "payment " + paymentNumber + " not found"));
                }
                var processingResult = await _orderApi.OrderModule.ProcessOrderPaymentsAsync(orderDto.Id, paymentDto.Id, bankCardInfo);

                return(Json(new { orderProcessingResult = processingResult, paymentMethod = paymentDto.PaymentMethod }));
            }
        }
コード例 #7
0
        public async Task <ActionResult <ProcessOrderPaymentResult> > ProcessOrderPayment(string orderNumber, string paymentNumber, [FromBody][SwaggerOptional] orderModel.BankCardInfo bankCardInfo)
        {
            //Need lock to prevent concurrent access to same order
            using (await AsyncLock.GetLockByKey(GetAsyncLockKey(orderNumber, WorkContext)).LockAsync())
            {
                var orderDto = await GetOrderDtoByNumber(orderNumber);

                var paymentDto = orderDto.InPayments.FirstOrDefault(x => x.Number.EqualsInvariant(paymentNumber));
                if (paymentDto == null)
                {
                    throw new StorefrontException("payment " + paymentNumber + " not found");
                }
                var processingResult = await _orderApi.ProcessOrderPaymentsAsync(orderDto.Id, paymentDto.Id, bankCardInfo);

                return(new ProcessOrderPaymentResult
                {
                    OrderProcessingResult = processingResult,
                    PaymentMethod = paymentDto.PaymentMethod
                });
            }
        }