コード例 #1
0
        private void LoadSearchGrid(int offset, int pageSize)
        {
            // Set PaymentHelper
            PaymentsHelper ph = GetPaymentsHelper();

            // Get Collections
            List <KeyValuePair <string, string> > args = new List <KeyValuePair <string, string> >();

            args.Add(new KeyValuePair <string, string>("sort", "date_created"));
            args.Add(new KeyValuePair <string, string>("criteria", "desc"));
            args.Add(new KeyValuePair <string, string>("offset", (offset - 1).ToString()));
            args.Add(new KeyValuePair <string, string>("limit", pageSize.ToString()));
            SearchPage <Collection> searchPage  = ph.SearchCollections(args);
            List <Collection>       collections = searchPage.Results;

            // Bind this info to the grid view
            CollectionsGridView.DataSource = collections;
            CollectionsGridView.DataBind();

            // Set pager info
            PagerFrom.Text     = offset.ToString();
            PagerTo.Text       = (offset + collections.Count - 1).ToString();
            PagerTotal.Text    = searchPage.Total.ToString();
            PagerPanel.Visible = true;
        }
コード例 #2
0
        /// <summary>
        /// Recursively tries to get a collections page from the MP API.
        /// </summary>
        public static SearchPage <Collection> GetCollectionsPage(Int32 offset, Int32 limit, OAuthResponse authorization, DateTime dateFrom, DateTime dateTo, int retryNumber = 0)
        {
            PaymentsHelper ph = new PaymentsHelper();

            // Set access token
            ph.AccessToken = GetAccessToken(authorization);

            // Prepare API call arguments
            List <KeyValuePair <string, string> > args = new List <KeyValuePair <string, string> >();

            if (authorization.IsAdmin)
            {
                args.Add(new KeyValuePair <string, string>("collector_id", authorization.UserId.ToString()));
            }
            // Try optimize the query by site id, taking advantage of the search sharding
            if (authorization.SiteId != null)
            {
                args.Add(new KeyValuePair <string, string>("site_id", authorization.SiteId));
            }
            args.Add(new KeyValuePair <string, string>("sort", "date_created"));
            args.Add(new KeyValuePair <string, string>("criteria", "desc"));
            args.Add(new KeyValuePair <string, string>("offset", offset.ToString()));
            args.Add(new KeyValuePair <string, string>("limit", limit.ToString()));
            args.Add(new KeyValuePair <string, string>("range", "date_created"));
            args.Add(new KeyValuePair <string, string>("begin_date", HttpUtility.UrlEncode(dateFrom.GetDateTimeFormats('s')[0].ToString() + ".000Z")));
            args.Add(new KeyValuePair <string, string>("end_date", HttpUtility.UrlEncode(dateTo.GetDateTimeFormats('s')[0].ToString() + ".000Z")));

            SearchPage <Collection> searchPage = null;

            try
            {
                // Search the API
                searchPage = ph.SearchCollections(args);
            }
            catch (RESTAPIException raex)
            {
                // Retries the same call until max is reached
                if (retryNumber <= MAX_RETRIES)
                {
                    LogHelper.WriteLine("SearchCollections breaks. Retry num: " + retryNumber.ToString());
                    BackendHelper.GetCollectionsPage(offset, limit, authorization, dateFrom, dateTo, retryNumber + 1);
                }
                else
                {
                    // then breaks
                    throw raex;
                }
            }

            return(searchPage);
        }
コード例 #3
0
        public List <Int32> GetPendingCollections(Int32?lastProcessedCollectionId)
        {
            // Set payments helper
            PaymentsHelper ph = new PaymentsHelper();

            ph.AccessToken = this.AccessToken;

            // Prepare API call arguments
            List <KeyValuePair <string, string> > args = new List <KeyValuePair <string, string> >();

            args.Add(new KeyValuePair <string, string>("sort", "id"));
            args.Add(new KeyValuePair <string, string>("criteria", "desc"));
            args.Add(new KeyValuePair <string, string>("offset", "0"));
            args.Add(new KeyValuePair <string, string>("limit", "5"));

            // Set environment
            MercadoPagoSDK.Environment.Scope = _environmentScope;

            // Call API
            SearchPage <Collection> searchPage  = ph.SearchCollections(args);
            List <Collection>       collections = searchPage.Results;

            // Populate pending ids
            List <Int32> pendingIds = new List <int>();

            foreach (Collection collection in collections)
            {
                if (lastProcessedCollectionId != null)
                {
                    if (lastProcessedCollectionId == collection.Id)
                    {
                        break;
                    }
                }
                pendingIds.Add(collection.Id.Value);
            }
            return(pendingIds);
        }