Exemple #1
0
        public virtual string MmsGetDownloadStatus(Guid orderItemId, int part)
        {
            string return_status = "error";
            string callback_url  = null;
            var    orderItem     = _orderService.GetOrderItemByGuid(orderItemId);
            var    mms_prod_id   = MmsGetMmsItemId(orderItem.ProductId);
            var    order         = _orderService.GetOrderById(orderItem.OrderId);
            var    cust          = _customerService.GetCustomerById(order.CustomerId);
            MmsJsonGetDownloadLinkv2 download_link = new MmsJsonGetDownloadLinkv2();


            var mmsadmin_return = MmsJsonGetDownloadLinkv2(cust.EmailToRevalidate, mms_prod_id, part, callback_url, out download_link);

            if (mmsadmin_return == "success")
            {
                return_status = download_link.Status;
            }
            else
            {
                Debug.WriteLine("Error in MmsGetDownloadStatus " + mmsadmin_return);
                return_status = mmsadmin_return;
            }

            return(return_status);
        }
Exemple #2
0
        public IActionResult GetDownloadMms(Guid orderItemId, int part, bool agree = false)
        {
            Debug.WriteLine("**************In Override GetDownload MMS***** " + part.ToString());

            var orderItem = _orderService.GetOrderItemByGuid(orderItemId);
            //if (orderItem == null)
            //    return InvokeHttp404();

            var order = _orderService.GetOrderById(orderItem.OrderId);

            if (!_orderService.IsDownloadAllowed(orderItem))
            {
                return(Content("Downloads are not allowed"));
            }

            if (_customerSettings.DownloadableProductsValidateUser)
            {
                if (_workContext.CurrentCustomer == null)
                {
                    return(Challenge());
                }

                if (order.CustomerId != _workContext.CurrentCustomer.Id)
                {
                    return(Content("This is not your order"));
                }
            }

            var product = _productService.GetProductById(orderItem.ProductId);

            var download = _downloadService.GetDownloadById(product.DownloadId);

            if (download == null)
            {
                return(Content("Download is not available any more."));
            }

            if (product.HasUserAgreement && !agree)
            {
                return(RedirectToRoute("DownloadUserAgreement", new { orderItemId = orderItemId }));
            }


            if (!product.UnlimitedDownloads && orderItem.DownloadCount >= product.MaxNumberOfDownloads)
            {
                return(Content(string.Format(_localizationService.GetResource("DownloadableProducts.ReachedMaximumNumber"), product.MaxNumberOfDownloads)));
            }

            if (download.UseDownloadUrl)
            {
                //WGR
                var cust        = _customerService.GetCustomerById(order.CustomerId);
                var mms_prod_id = _mmsAdminService.MmsGetMmsItemId(product.Id);
                //If MMS download item
                if (mms_prod_id > 0)
                {
                    string callback_url = null;
                    MmsJsonGetDownloadLinkv2 download_link = new MmsJsonGetDownloadLinkv2();


                    var mmsadmin_return = _mmsAdminService.MmsJsonGetDownloadLinkv2(cust.EmailToRevalidate, mms_prod_id, part, callback_url, out download_link);
                    if (mmsadmin_return == "success")
                    {
                        if (download_link.Status == "ready")
                        {
                            var download_url = download_link.DownloadLink;
                            return(new RedirectResult(download_url));
                        }
                        else
                        {
                            Debug.WriteLine("Not ready in GetDownloadMms" + download_link.Status);
                            return(Content(download_link.Status));
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Error in GetDownloadMms" + mmsadmin_return);
                        return(Content("Download data is not available just now."));
                    }
                }
                else // Just normal download
                {
                    orderItem.DownloadCount++;
                    _orderService.UpdateOrderItem(orderItem);

                    //return result
                    //A warning (SCS0027 - Open Redirect) from the "Security Code Scan" analyzer may appear at this point.
                    //In this case, it is not relevant. Url may not be local.
                    return(new RedirectResult(download.DownloadUrl));
                }
            }

            //binary download
            if (download.DownloadBinary == null)
            {
                return(Content("Download data is not available any more."));
            }

            //increase download
            orderItem.DownloadCount++;
            _orderService.UpdateOrderItem(orderItem);

            //return result
            var fileName    = !string.IsNullOrWhiteSpace(download.Filename) ? download.Filename : product.Id.ToString();
            var contentType = !string.IsNullOrWhiteSpace(download.ContentType) ? download.ContentType : MimeTypes.ApplicationOctetStream;

            return(new FileContentResult(download.DownloadBinary, contentType)
            {
                FileDownloadName = fileName + download.Extension
            });
        }
Exemple #3
0
        public virtual string MmsJsonGetDownloadLinkv2(string eMail, int productId, int part, string callbackUrl, out MmsJsonGetDownloadLinkv2 mmsJsonDownloadLinkv2)
        {
            mmsJsonDownloadLinkv2 = null;
            string    return_val  = null;
            WebClient myWebClient = new WebClient();

            NameValueCollection myNameValueCollection = new NameValueCollection();

            // Add necessary parameter/value pairs to the name/value container.
            myNameValueCollection.Add("APIKey", "e252d955a8df2c516fbc74cfbc37bc97");
            myNameValueCollection.Add("Email", eMail);
            myNameValueCollection.Add("ProductID", productId.ToString());
            myNameValueCollection.Add("Part", part.ToString());
            myNameValueCollection.Add("CallbackURL", null);

            var    responseArray = myWebClient.UploadValues("https://downloads.murphysmagic.com/api/GetDownloadLinkv2/", myNameValueCollection);
            string rawJson       = Encoding.ASCII.GetString(responseArray);

            if (rawJson.Substring(2, 5) == "error")
            {
                MmsJsonError authTest = JsonConvert.DeserializeObject <MmsJsonError>(rawJson);
                return_val = authTest.error;
            }
            else
            {
                mmsJsonDownloadLinkv2 = JsonConvert.DeserializeObject <MmsJsonGetDownloadLinkv2>(rawJson);
                return_val            = "success";
            }

            return(return_val);
        }