public IHttpActionResult GetById(string id)
        {
            var retVal = _customerOrderService.GetById(id, coreModel.CustomerOrderResponseGroup.Full);

            if (retVal == null)
            {
                return(NotFound());
            }
            return(Ok(retVal.ToWebModel()));
        }
Ejemplo n.º 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"
            }));
        }
Ejemplo n.º 3
0
 public IHttpActionResult GetOrderData(string id)
 {
     if (!string.IsNullOrEmpty(id))
     {
         var orderData = _orderSearchService.GetById(id, CustomerOrderResponseGroup.Full);
         if (orderData != null)
         {
             return(Ok(orderData));
         }
     }
     return(NotFound());
 }
Ejemplo n.º 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"
            }));
        }
        public IHttpActionResult GetById(string id)
        {
            var retVal = _customerOrderService.GetById(id, coreModel.CustomerOrderResponseGroup.Full);

            if (retVal == null)
            {
                return(NotFound());
            }
            //Scope bound security check
            var scopes = _permissionScopeService.GetObjectPermissionScopeStrings(retVal).ToArray();

            if (!_securityService.UserHasAnyPermission(User.Identity.Name, scopes, OrderPredefinedPermissions.Read))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            var result = retVal.ToWebModel();

            //Set scopes for UI scope bounded ACL checking
            result.Scopes = scopes;

            return(Ok(result));
        }
Ejemplo n.º 6
0
        private BackupObject GetBackupObject()
        {
            var responce = _customerOrderSearchService.Search(new SearchCriteria {
                Count = int.MaxValue
            });
            var orderIds = responce.CustomerOrders.Select(x => x.Id);
            const CustomerOrderResponseGroup filter = CustomerOrderResponseGroup.WithAddresses | CustomerOrderResponseGroup.WithItems
                                                      | CustomerOrderResponseGroup.WithShipments | CustomerOrderResponseGroup.WithInPayments;

            return(new BackupObject
            {
                CustomerOrders = orderIds.Select(id => _customerOrderService.GetById(id, filter)).ToArray(),
            });
        }
Ejemplo n.º 7
0
        private BackupObject GetBackupObject(Action <ExportImportProgressInfo> progressCallback)
        {
            var retVal       = new BackupObject();
            var progressInfo = new ExportImportProgressInfo();
            const CustomerOrderResponseGroup responseGroup = CustomerOrderResponseGroup.WithAddresses | CustomerOrderResponseGroup.WithItems
                                                             | CustomerOrderResponseGroup.WithShipments | CustomerOrderResponseGroup.WithInPayments;

            var searchResponse = _customerOrderSearchService.Search(new SearchCriteria {
                Count = int.MaxValue
            });

            progressInfo.Description = String.Format("{0} orders loading", searchResponse.CustomerOrders.Count());
            progressCallback(progressInfo);

            retVal.CustomerOrders = searchResponse.CustomerOrders.Select((x) => _customerOrderService.GetById(x.Id, responseGroup)).ToList();

            return(retVal);
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        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));
        }