Exemple #1
0
        public IHttpActionResult ProcessOrderPayments([FromBody] BankCardInfo bankCardInfo, string orderId, string paymentId)
        {
            //search first by order number
            var order = _customerOrderService.GetByOrderNumber(orderId, coreModel.CustomerOrderResponseGroup.Full);

            //if not found by order number search by order id
            if (order == null)
            {
                order = _customerOrderService.GetById(orderId, coreModel.CustomerOrderResponseGroup.Full);
            }

            if (order == null)
            {
                throw new NullReferenceException("order");
            }
            var payment = order.InPayments.FirstOrDefault(x => x.Id == paymentId);

            if (payment == null)
            {
                throw new NullReferenceException("payment");
            }
            var store         = _storeService.GetById(order.StoreId);
            var paymentMethod = store.PaymentMethods.FirstOrDefault(x => x.Code == payment.GatewayCode);

            if (payment == null)
            {
                throw new NullReferenceException("appropriate paymentMethod not found");
            }

            var context = new ProcessPaymentEvaluationContext
            {
                Order        = order,
                Payment      = payment,
                Store        = store,
                BankCardInfo = bankCardInfo
            };

            var result = paymentMethod.ProcessPayment(context);

            _customerOrderService.Update(new coreModel.CustomerOrder[] { order });

            var retVal = new webModel.ProcessPaymentResult();

            retVal.InjectFrom(result);
            retVal.PaymentMethodType = paymentMethod.PaymentMethodType;

            return(Ok(retVal));
        }
Exemple #2
0
        public IHttpActionResult PostProcessPayment(webModel.PaymentCallbackParameters callback)
        {
            if (callback != null && callback.Parameters != null && callback.Parameters.Any(param => param.Key == "orderid"))
            {
                var orderId = callback.Parameters.First(param => param.Key == "orderid").Value;
                //some payment method require customer number to be passed and returned. First search customer order by number
                var order = _customerOrderService.GetByOrderNumber(orderId, CustomerOrderResponseGroup.Full);

                //if order not found by order number search by order id
                if (order == null)
                {
                    order = _customerOrderService.GetById(orderId, CustomerOrderResponseGroup.Full);
                }

                var store      = _storeService.GetById(order.StoreId);
                var parameters = new NameValueCollection();
                foreach (var param in callback.Parameters)
                {
                    parameters.Add(param.Key, param.Value);
                }
                var paymentMethod = store.PaymentMethods.Where(x => x.IsActive).FirstOrDefault(x => x.ValidatePostProcessRequest(parameters).IsSuccess);
                if (paymentMethod != null)
                {
                    var paymentOuterId = paymentMethod.ValidatePostProcessRequest(parameters).OuterId;

                    var payment = order.InPayments.FirstOrDefault(x => string.IsNullOrEmpty(x.OuterId) || x.OuterId == paymentOuterId);
                    if (payment == null)
                    {
                        throw new NullReferenceException("appropriate paymentMethod not found");
                    }

                    var context = new PostProcessPaymentEvaluationContext
                    {
                        Order      = order,
                        Payment    = payment,
                        Store      = store,
                        OuterId    = paymentOuterId,
                        Parameters = parameters
                    };

                    var retVal = paymentMethod.PostProcessPayment(context);

                    if (retVal != null)
                    {
                        _customerOrderService.Update(new CustomerOrder[] { order });
                    }

                    return(Ok(retVal));
                }
            }
            return(Ok(new PostProcessPaymentResult {
                ErrorMessage = "cancel payment"
            }));
        }
        public IHttpActionResult UpdateOrders(string action, string order_number, string carrier, string service, string tracking_number, ShipNotice shipnotice)
        {
            var order = _orderService.GetByOrderNumber(shipnotice.OrderNumber, CustomerOrderResponseGroup.Full);

            if (order == null)
            {
                return(BadRequest("Order not found"));
            }

            order.Patch(shipnotice);
            _orderService.Update(new[] { order });
            return(Ok(shipnotice));
        }
Exemple #4
0
        public IHttpActionResult PostProcessPayment(string orderId)
        {
            var order = _customerOrderService.GetById(orderId, CustomerOrderResponseGroup.Full);

            if (order == null)
            {
                throw new NullReferenceException("order");
            }

            var store         = _storeService.GetById(order.StoreId);
            var parameters    = HttpContext.Current.Request.QueryString;
            var paymentMethod = store.PaymentMethods.Where(x => x.IsActive).FirstOrDefault(x => x.ValidatePostProcessRequest(parameters).IsSuccess);

            if (paymentMethod != null)
            {
                var paymentOuterId = paymentMethod.ValidatePostProcessRequest(HttpContext.Current.Request.QueryString).OuterId;

                var payment = order.InPayments.FirstOrDefault(x => x.OuterId == paymentOuterId);
                if (payment == null)
                {
                    throw new NullReferenceException("payment");
                }

                if (payment == null)
                {
                    throw new NullReferenceException("appropriate paymentMethod not found");
                }

                var context = new PostProcessPaymentEvaluationContext
                {
                    Order      = order,
                    Payment    = payment,
                    Store      = store,
                    OuterId    = paymentOuterId,
                    Parameters = parameters
                };

                var retVal = paymentMethod.PostProcessPayment(context);

                if (retVal != null)
                {
                    _customerOrderService.Update(new CustomerOrder[] { order });
                }

                return(Ok(retVal));
            }

            return(Ok(new PostProcessPaymentResult {
                ErrorMessage = "cancel payment"
            }));
        }
Exemple #5
0
        private void UpdateOrders(ICollection <CustomerOrder> original, ICollection <CustomerOrder> backup)
        {
            var toUpdate = new List <CustomerOrder>();

            backup.CompareTo(original, EqualityComparer <Operation> .Default, (state, x, y) =>
            {
                switch (state)
                {
                case EntryState.Modified:
                    toUpdate.Add(x);
                    break;

                case EntryState.Added:
                    _customerOrderService.Create(x);
                    break;
                }
            });
            _customerOrderService.Update(toUpdate.ToArray());
        }
Exemple #6
0
        public IHttpActionResult RegisterPayment()
        {
            var orderId = HttpContext.Current.Request.Form["orderid"];
            var order   = _customerOrderService.GetByOrderNumber(orderId, CustomerOrderResponseGroup.Full);

            if (order == null)
            {
                order = _customerOrderService.GetById(orderId, CustomerOrderResponseGroup.Full);
            }
            if (order == null)
            {
                throw new NullReferenceException("Order not found");
            }

            var store = _storeService.GetById(order.StoreId);

            var parameters = new NameValueCollection();

            foreach (var key in HttpContext.Current.Request.QueryString.AllKeys)
            {
                parameters.Add(key, HttpContext.Current.Request.Form[key]);
            }

            foreach (var key in HttpContext.Current.Request.Form.AllKeys)
            {
                parameters.Add(key, HttpContext.Current.Request.Form[key]);
            }

            var paymentMethod = store.PaymentMethods.FirstOrDefault(x => x.Code == dibsCode);

            if (paymentMethod != null)
            {
                var validateResult = paymentMethod.ValidatePostProcessRequest(parameters);
                var paymentOuterId = validateResult.OuterId;

                var payment = order.InPayments.FirstOrDefault(x => x.GatewayCode == dibsCode && (int)(x.Sum * 100) == Convert.ToInt32(parameters["amount"], CultureInfo.InvariantCulture));

                if (payment == null)
                {
                    throw new NullReferenceException("appropriate paymentMethod not found");
                }

                var context = new PostProcessPaymentEvaluationContext
                {
                    Order      = order,
                    Payment    = payment,
                    Store      = store,
                    OuterId    = paymentOuterId,
                    Parameters = parameters
                };

                var retVal = paymentMethod.PostProcessPayment(context);

                if (retVal != null && retVal.IsSuccess)
                {
                    _customerOrderService.Update(new CustomerOrder[] { order });
                    return(Ok());
                }
            }

            return(StatusCode(System.Net.HttpStatusCode.NotFound));
        }
        public IHttpActionResult RegisterPayment(string orderId)
        {
            var order = _customerOrderService.GetById(orderId, CustomerOrderResponseGroup.Full);

            if (order == null)
            {
                throw new NullReferenceException("order");
            }

            var store      = _storeService.GetById(order.StoreId);
            var parameters = new NameValueCollection();

            foreach (var key in HttpContext.Current.Request.QueryString.AllKeys)
            {
                parameters.Add(key, HttpContext.Current.Request.Form[key]);
            }

            foreach (var key in HttpContext.Current.Request.Form.AllKeys)
            {
                parameters.Add(key, HttpContext.Current.Request.Form[key]);
            }

            var paymentMethod = store.PaymentMethods.FirstOrDefault(x => x.Code == "AuthorizeNet");

            if (paymentMethod != null)
            {
                var validateResult = paymentMethod.ValidatePostProcessRequest(parameters);
                var paymentOuterId = validateResult.OuterId;

                var payment = order.InPayments.FirstOrDefault(x => x.GatewayCode == "AuthorizeNet" && x.Sum == Convert.ToDecimal(parameters["x_amount"], CultureInfo.InvariantCulture));
                if (payment == null)
                {
                    throw new NullReferenceException("payment");
                }

                if (payment == null)
                {
                    throw new NullReferenceException("appropriate paymentMethod not found");
                }

                var context = new PostProcessPaymentEvaluationContext
                {
                    Order      = order,
                    Payment    = payment,
                    Store      = store,
                    OuterId    = paymentOuterId,
                    Parameters = parameters
                };

                var retVal = paymentMethod.PostProcessPayment(context);

                if (retVal != null && retVal.IsSuccess)
                {
                    _customerOrderService.Update(new CustomerOrder[] { order });

                    var returnHtml = string.Format("<html><head><script type='text/javascript' charset='utf-8'>window.location='{0}';</script><noscript><meta http-equiv='refresh' content='1;url={0}'></noscript></head><body></body></html>", retVal.ReturnUrl);

                    return(Ok(returnHtml));
                }
            }

            return(StatusCode(System.Net.HttpStatusCode.NoContent));
        }
Exemple #8
0
        public async Task <IHttpActionResult> UpdateCustomerOder([FromBody] CustomerOrderProductViewModelUpdate customer_order_update)
        {
            ResponseDataDTO <bool> response = new ResponseDataDTO <bool>();

            try
            {
                //Id user now
                new BaseController();
                var current_id = BaseController.current_id;
                if (customer_order_update.customer.cu_id == 0)
                {
                    #region [Create Customer]
                    //Cach truong bat buoc
                    if (customer_order_update.customer.cu_fullname == null)
                    {
                        response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                        response.Message = "Họ và tên không được để trống";
                        response.Data    = false;
                        return(Ok(response));
                    }
                    if (customer_order_update.customer.cu_mobile == null)
                    {
                        response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                        response.Message = "Số điện thoại không được để trống";
                        response.Data    = false;
                        return(Ok(response));
                    }
                    if (customer_order_update.customer.cu_email == null)
                    {
                        response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                        response.Message = "Email không được để trống";
                        response.Data    = false;
                        return(Ok(response));
                    }
                    if (customer_order_update.customer.cu_type == 0)
                    {
                        response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                        response.Message = "Loại khách hàng không được để trống";
                        response.Data    = false;
                        return(Ok(response));
                    }
                    if (customer_order_update.customer.customer_group_id == 0)
                    {
                        response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                        response.Message = "Nhóm khách hàng không được để trống";
                        response.Data    = false;
                        return(Ok(response));
                    }
                    if (customer_order_update.customer.source_id == 0)
                    {
                        response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                        response.Message = "Nguồn không được để trống";
                        response.Data    = false;
                        return(Ok(response));
                    }
                    // get data from formdata
                    CustomerCreateViewModel customerCreateViewModel = new CustomerCreateViewModel
                    {
                        cu_mobile   = Convert.ToString(customer_order_update.customer.cu_mobile),
                        cu_email    = Convert.ToString(customer_order_update.customer.cu_email),
                        cu_fullname = Convert.ToString(customer_order_update.customer.cu_fullname),

                        customer_group_id = Convert.ToInt32(customer_order_update.customer.customer_group_id),
                        source_id         = Convert.ToInt32(customer_order_update.customer.source_id),

                        cu_type = Convert.ToByte(customer_order_update.customer.cu_type),
                    };
                    //Bat cac dieu kien rang buoc
                    if (CheckEmail.IsValidEmail(customerCreateViewModel.cu_email) == false && customerCreateViewModel.cu_email == "")
                    {
                        response.Message = "Định dạng email không hợp lệ !";
                        response.Data    = false;
                        return(Ok(response));
                    }

                    if (CheckNumber.IsPhoneNumber(customerCreateViewModel.cu_mobile) == false && customerCreateViewModel.cu_mobile == "")
                    {
                        response.Message = "Số điện thoại không hợp lệ";
                        response.Data    = false;
                        return(Ok(response));
                    }


                    //bat cac truog con lai
                    if (customer_order_update.customer.cu_birthday == null)
                    {
                        customerCreateViewModel.cu_birthday = null;
                    }
                    else
                    {
                        customerCreateViewModel.cu_birthday = Convert.ToDateTime(customer_order_update.customer.cu_birthday);
                    }
                    if (customer_order_update.customer.cu_address == null)
                    {
                        customerCreateViewModel.cu_address = null;
                    }
                    else
                    {
                        customerCreateViewModel.cu_address = Convert.ToString(customer_order_update.customer.cu_address);
                    }
                    if (customer_order_update.customer.cu_note == null)
                    {
                        customerCreateViewModel.cu_note = null;
                    }
                    else
                    {
                        customerCreateViewModel.cu_note = Convert.ToString(customer_order_update.customer.cu_note);
                    }
                    if (customer_order_update.customer.cu_geocoding == null)
                    {
                        customerCreateViewModel.cu_geocoding = null;
                    }
                    else
                    {
                        customerCreateViewModel.cu_geocoding = Convert.ToString(customer_order_update.customer.cu_geocoding);
                    }
                    if (customer_order_update.customer.cu_curator_id == 0)
                    {
                        customerCreateViewModel.cu_curator_id = null;
                    }
                    else
                    {
                        customerCreateViewModel.cu_curator_id = Convert.ToInt32(customer_order_update.customer.cu_curator_id);
                    }
                    if (customer_order_update.customer.cu_age == 0)
                    {
                        customerCreateViewModel.cu_age = null;
                    }
                    else
                    {
                        customerCreateViewModel.cu_age = Convert.ToInt32(customer_order_update.customer.cu_age);
                    }
                    if (customer_order_update.customer.cu_status == 0)
                    {
                        customerCreateViewModel.cu_status = null;
                    }
                    else
                    {
                        customerCreateViewModel.cu_status = Convert.ToByte(customer_order_update.customer.cu_status);
                    }

                    customerCreateViewModel.staff_id       = Convert.ToInt32(current_id);
                    customerCreateViewModel.cu_create_date = DateTime.Now;
                    var cu = _customerservice.GetLast();
                    customerCreateViewModel.cu_code = Utilis.CreateCode("CU", cu.cu_id, 7);
                    // mapping view model to entity
                    var createdcustomer = _mapper.Map <customer>(customerCreateViewModel);

                    // save new customer
                    _customerservice.Create(createdcustomer);
                    var cu_last = _customerservice.GetLast();
                    customer_order_update.customer.cu_id = cu_last.cu_id;
                    #endregion
                }


                var existscustomerorder = _customer_orderservice.Find(customer_order_update.cuo_id);

                existscustomerorder.customer_id        = customer_order_update.customer.cu_id;
                existscustomerorder.staff_id           = Convert.ToInt32(current_id);
                existscustomerorder.cuo_payment_status = customer_order_update.cuo_payment_status;
                existscustomerorder.cuo_payment_type   = customer_order_update.cuo_payment_type;
                existscustomerorder.cuo_ship_tax       = customer_order_update.cuo_ship_tax;
                existscustomerorder.cuo_total_price    = customer_order_update.cuo_total_price;
                existscustomerorder.cuo_discount       = customer_order_update.cuo_discount;
                existscustomerorder.cuo_status         = customer_order_update.cuo_status;



                // update customer order
                _customer_orderservice.Update(existscustomerorder, existscustomerorder.cuo_id);

                //update order product

                OrderProductCreateViewModel orderCreateViewModel = new OrderProductCreateViewModel {
                };

                foreach (productorderviewmodel i in customer_order_update.list_product)
                {
                    var order_product_delete = _order_productservice.Find(i.op_id);
                    if (order_product_delete != null)
                    {
                        _order_productservice.Delete(order_product_delete);
                    }

                    orderCreateViewModel.customer_order_id = customer_order_update.cuo_id;
                    orderCreateViewModel.op_discount       = i.op_discount;
                    orderCreateViewModel.op_note           = i.op_note;
                    orderCreateViewModel.op_quantity       = i.op_quantity;
                    orderCreateViewModel.product_id        = i.product_id;

                    var createdorderproduct = _mapper.Map <order_product>(orderCreateViewModel);

                    _order_productservice.Create(createdorderproduct);
                }


                // return response
                response.Code    = HttpCode.OK;
                response.Message = MessageResponse.SUCCESS;
                response.Data    = false;
                return(Ok(response));
            }
            catch (Exception ex)
            {
                response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                response.Message = ex.Message;
                response.Data    = true;
                Console.WriteLine(ex.ToString());

                return(Ok(response));
            }
        }