Ejemplo n.º 1
0
        /// <summary>
        /// Process 1 or more shipping/cancellation notifications to bol.com
        /// The maximum number of shipments/cancellations in one request is 400.
        /// NOTE: After informing bol.com of shippings / cancellations through the API you may still see your orders as "open" in the seller dashboard.
        /// This has to do with system caches and queues.
        /// The API briefly caches the input it receives and the seller dashboard also has it's own cache to offload the core systems.
        /// The most important feedback is the feedback one gets from the GetProcessStatus() method.
        /// </summary>
        /// <param name="processOrders">The process orders.</param>
        /// <returns>
        /// A ProcessOrdersResult object. This ProcessOrdersResult object was generated by a tool.
        /// The different elements are described on the following XML Schema Definition https://plazaapi.bol.com/services/xsd/plazaapiservice-v1.xsd
        /// </returns>
        public ProcessOrdersResult ProcessOrders(ProcessOrders processOrders)
        {
            HttpWebResponse     response = null;
            ProcessOrdersResult results  = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url + "/services/rest/orders/v1/process/");

                Utils.HandleRequest(request, C.RequestMethods.POST, _publicKey, _privateKey);

                using (Stream reqStream = request.GetRequestStream())
                {
                    XmlSerializer s = new XmlSerializer(typeof(ProcessOrders));
                    s.Serialize(reqStream, processOrders);
                }

                SigningRequest = Utils.StringToSign.Replace("\n", Environment.NewLine);
                response       = (HttpWebResponse)request.GetResponse();

                if (HttpStatusCode.OK == response.StatusCode)
                {
                    XmlSerializer ser = new XmlSerializer(typeof(ProcessOrdersResult));
                    object        obj = ser.Deserialize(response.GetResponseStream());
                    results = (ProcessOrdersResult)obj;

                    var json = new JavaScriptSerializer().Serialize(obj);
                    ResponseOutput = json;
                }
            }
            catch (WebException ex)
            {
                if (ex.Response != null)
                {
                    throw ExceptionHandler.HandleResponseException((HttpWebResponse)ex.Response);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return(results);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This code demonstrates how to send 1 or more shipping/cancellation notifications to bol.com from a xml file.
        /// This code performs a simple POST on the "/services/rest/orders/v1/process/" PlazaAPI.
        /// See the example code below for typical usage instructions.
        /// </summary>
        /// <param name="plazaAPIClient">The plaza API client.</param>
        private static void ProcessOrdersFromXml(PlazaAPIClient plazaAPIClient)
        {
            // Create an instance of the XmlSerializer specifying type and namespace
            XmlSerializer serializer = new XmlSerializer(typeof(ProcessOrders));

            // A FileStream is needed to read the XML document.
            FileStream fs     = new FileStream(@"C:\WorkingCopy\Projects\bol.com\bol.com-plaza-api-clients-master\c#\bol.com.PlazaAPI\bol.com.PlazaAPI.Test\ProcessOrderTest.xml", FileMode.Open);
            XmlReader  reader = XmlReader.Create(fs);

            // Declare an object variable of the type to be deserialized.
            ProcessOrders processOrders;

            // Use the Deserialize method to restore the object's state.
            processOrders = (ProcessOrders)serializer.Deserialize(reader);
            fs.Close();

            // Done! Let's push this batch to the server.
            ProcessOrdersResult processOrdersResult = plazaAPIClient.ProcessOrders(processOrders);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This code demonstrates how to send 1 or more shipping/cancellation notifications to bol.com
        /// This code performs a simple POST on the "/services/rest/orders/v1/process/" PlazaAPI.
        /// See the example code below for typical usage instructions.
        /// </summary>
        /// <param name="plazaAPIClient">The plaza API client.</param>
        private static void ProcessOrders(PlazaAPIClient plazaAPIClient)
        {
            // Create a new batch.
            // This is required before calling the method "PlazaAPIClient.ProcessOrders()"

            /*
             * ProcessOrders processOrders = new ProcessOrders()
             * {
             *  // Add a shipment
             *  Shipments = new ProcessOrdersShipment[1] { GenerateShipment() },
             *
             *  // Add a cancellation
             *  Cancellations = new ProcessOrdersCancellation[1] { GenerateCancellation() }
             * };
             */

            ProcessOrders processOrders = new ProcessOrders();

            // Create 5 random shipments
            processOrders.Shipments = new ProcessOrdersShipment[5];

            for (int i = 0; i < processOrders.Shipments.Length; i++)
            {
                processOrders.Shipments[i] = GenerateShipment();
            }

            // Create 5 random cancellations
            processOrders.Cancellations = new ProcessOrdersCancellation[5];

            for (int i = 0; i < processOrders.Cancellations.Length; i++)
            {
                processOrders.Cancellations[i] = GenerateCancellation();
            }

            // Done! Let's push this batch to the server.
            ProcessOrdersResult processOrdersResult = plazaAPIClient.ProcessOrders(processOrders);
        }