/// <summary>
        /// Calculates the Recipient List price
        /// </summary>
        public override double calculatePrice()
        {
            ListDataConfig config             = ConfigUtils.LoadConfiguration(ConfigurationXML);
            int            numberOfRecipients = ConfigUtils.GetMaxRecipientsFromSelectionXml(SelectionXML).Value;

            return(Convert.ToDouble(config.Price * numberOfRecipients));
        }
        /// <summary>
        /// Initialize the controls on the page.
        /// </summary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // must be after base.OnLoad to let parent fill ConfigurationXML in the first time
            if (!IsPostBack)
            {
                ListDataConfig config = ConfigUtils.LoadConfiguration(ConfigurationXML);

                // Load previous value from configuration xml
                txtAPIUrl.Text        = config.ApiUrl;
                txtMailPieceJSON.Text = config.JSONData;
                txtPricePerPiece.Text = config.Price.ToString();
            }
        }
        /// <summary>
        /// Page load
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (FirstTime)
            {
                ListDataConfig config = ConfigUtils.LoadConfiguration(LogicPlugin.ConfigurationXML);

                // Load the mail piece json data from the configuration
                txtMailPieceJSON.Text = config.JSONData;

                // Get api url
                txtApiUrl.Value = config.ApiUrl;

                // Update hidden OrderProductId
                int OrderProductId = LogicPlugin.OrderProductDetails.OrderProductID;
                txtItemOrderProductId.Value = OrderProductId.ToString();
            }
        }
        /// <summary>
        /// Gets the list response.
        /// </summary>
        protected IRestResponse <ListDataResponse> GetListResponse(string action)
        {
            // Get OrderProductId
            int OrderProductId = LogicPlugin.OrderProductDetails.OrderProductID;

            // Load the configuration
            ListDataConfig config = ConfigUtils.LoadConfiguration(LogicPlugin.ConfigurationXML);

            // Call the API url to check the list status
            RestClient  client  = new RestClient(config.ApiUrl);
            RestRequest request = new RestRequest("", Method.GET);

            request.AddParameter("action", action);
            request.AddParameter("ExternalTrackingType", "OrderProductId");
            request.AddParameter("ExternalTrackingId", OrderProductId);

            // Execute the request
            return(client.Execute <ListDataResponse>(request));
        }
        /// <summary>
        /// Fetches and updates the Recipient List in an order where the Recipient List was set to RecipientListStatus UnderConstruction
        /// Used for delayed Recipient Lists that fetched after order submission.
        /// </summary>
        public override ValidationResult updateListFromProvider()
        {
            ValidationResult result = new ValidationResult(false);

            try
            {
                ListDataConfig config = ConfigUtils.LoadConfiguration(ConfigurationXML);

                // Call API URL to get list data
                string listId   = ConfigUtils.GetListIdFromSelectionXml(SelectionXML);
                string listGUID = ConfigUtils.GetListGUIDFromSelectionXml(SelectionXML);

                // Call the API url to get the list
                RestClient  client  = new RestClient(config.ApiUrl);
                RestRequest request = new RestRequest("", Method.GET);

                request.AddParameter("action", "DownloadList");
                request.AddParameter("externalTrackingType", "ListId");
                request.AddParameter("externalTrackingId", listId);
                request.AddParameter("listGuid", listGUID);
                request.AddParameter("format", "uStore");
                request.AddParameter("type", "xml");

                // Execute the request
                IRestResponse <ListDataResponse> response = client.Execute <ListDataResponse>(request);

                // Is the list ready?
                if (response.Data.success && response.Data.list_count > 0)
                {
                    // XML Format
                    //
                    // Important: Must contain <RecipitentList></RecipitentList>
                    // for each record. The spelling is wrong but required
                    //
                    // <?xml version=\"1.0\" encoding=\"utf-16\"?>
                    // <NewDataSet><RecipitentList><first>John</first></RecipitentList></NewDataSet>
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(response.Data.xml_data);

                    RecipientListXML    = xml;
                    RecipientListStatus = uStoreStatus.StrStatus.Active;
                    NumberOfRecipients  = response.Data.list_count;

                    // Save the recipient list to the uStore system
                    SaveRecipientList();

                    // The returned ValidationResult should be set to true only if the recipient list is ready.
                    // This is important in order to avoid moving the order out from Pending Recipient List queue.
                    result.IsValid = true;

                    // The following message is being logged by uStore. Not mandatory.
                    result.AddInfoMsg("Recipient List plugin sample - delayed recipient list was successfully fetched.");
                }
            }
            catch (Exception e)
            {
                result.AddErrorMsg(e.Message);
            }

            return(result);
        }