Exemplo n.º 1
0
        private async Task <AdvancedPayment> CreateAsync(AdvancedPaymentCreateRequest request)
        {
            AdvancedPayment createdPayment;

            try
            {
                createdPayment = await client.CreateAsync(request);
            }
            catch (MercadoPagoApiException ex)
            {
                if (ex.StatusCode == 422)
                {
                    await Task.Delay(5000);

                    ResultsResourcesPage <AdvancedPayment> results =
                        await SearchByExternalReferenceAsync(request.ExternalReference);

                    createdPayment = results?.Results?.First();
                }
                else
                {
                    throw ex;
                }
            }

            return(createdPayment);
        }
Exemplo n.º 2
0
        private AdvancedPayment Create(AdvancedPaymentCreateRequest request)
        {
            AdvancedPayment createdPayment;

            try
            {
                createdPayment = client.Create(request);
            }
            catch (MercadoPagoApiException ex)
            {
                if (ex.StatusCode == 422)
                {
                    Thread.Sleep(5000);
                    ResultsResourcesPage <AdvancedPayment> results =
                        SearchByExternalReference(request.ExternalReference);
                    createdPayment = results?.Results?.First();
                }
                else
                {
                    throw ex;
                }
            }

            return(createdPayment);
        }
Exemplo n.º 3
0
        public async Task SearchAsync_Success()
        {
            CustomerRequest request         = BuildCreateRequest();
            Customer        createdCustomer = await client.CreateAsync(request);

            await Task.Delay(3000);

            try
            {
                var searchRequest = new SearchRequest
                {
                    Limit   = 1,
                    Offset  = 0,
                    Filters = new Dictionary <string, object>
                    {
                        ["email"] = request.Email,
                    },
                };
                ResultsResourcesPage <Customer> results =
                    await client.SearchAsync(searchRequest);

                Assert.NotNull(results);
                Assert.NotNull(results.Paging);
                Assert.Equal(1, results.Paging.Total);
                Assert.NotNull(results.Results);
                Assert.Equal(createdCustomer.Id, results.Results.First().Id);
            }
            finally
            {
                await client.DeleteAsync(createdCustomer.Id);
            }
        }
Exemplo n.º 4
0
        public void Search_Success()
        {
            CustomerRequest request         = BuildCreateRequest();
            Customer        createdCustomer = client.Create(request);

            Thread.Sleep(3000);

            try
            {
                var searchRequest = new SearchRequest
                {
                    Limit   = 1,
                    Offset  = 0,
                    Filters = new Dictionary <string, object>
                    {
                        ["email"] = request.Email,
                    },
                };
                ResultsResourcesPage <Customer> results = client.Search(searchRequest);

                Assert.NotNull(results);
                Assert.NotNull(results.Paging);
                Assert.Equal(1, results.Paging.Total);
                Assert.NotNull(results.Results);
                Assert.Equal(createdCustomer.Id, results.Results.First().Id);
            }
            finally
            {
                client.Delete(createdCustomer.Id);
            }
        }
Exemplo n.º 5
0
        public void Search_Success()
        {
            PreapprovalCreateRequest request = BuildCreateRequest();
            Preapproval createdPreapproval   = client.Create(request);

            Thread.Sleep(3000);

            var searchRequest = new SearchRequest
            {
                Limit   = 1,
                Offset  = 0,
                Filters = new Dictionary <string, object>
                {
                    ["id"] = createdPreapproval.Id,
                },
            };
            ResultsResourcesPage <Preapproval> results =
                client.Search(searchRequest);

            Assert.NotNull(results);
            Assert.NotNull(results.Paging);
            Assert.Equal(1, results.Paging.Total);
            Assert.NotNull(results.Results);
            Assert.Equal(createdPreapproval.Id, results.Results.First().Id);
        }
Exemplo n.º 6
0
        public async Task SearchAsync_Success()
        {
            PreapprovalCreateRequest request = BuildCreateRequest();
            Preapproval createdPreapproval   = await client.CreateAsync(request);

            await Task.Delay(3000);

            var searchRequest = new SearchRequest
            {
                Limit   = 1,
                Offset  = 0,
                Filters = new Dictionary <string, object>
                {
                    ["id"] = createdPreapproval.Id,
                },
            };
            ResultsResourcesPage <Preapproval> results =
                await client.SearchAsync(searchRequest);

            Assert.NotNull(results);
            Assert.NotNull(results.Paging);
            Assert.Equal(1, results.Paging.Total);
            Assert.NotNull(results.Results);
            Assert.Equal(createdPreapproval.Id, results.Results.First().Id);
        }
        public void Search_ByExternalReference_Success()
        {
            PaymentCreateRequest request = BuildCreateRequest(true, "approved");
            Payment createdPayment       = client.Create(request);

            Thread.Sleep(3000);

            var searchRequest = new AdvancedSearchRequest
            {
                Limit     = 1,
                Offset    = 0,
                Sort      = "date_created",
                Criteria  = "desc",
                Range     = "date_created",
                BeginDate = DateTime.Now.Date,
                EndDate   = DateTime.Now.AddDays(1).AddMilliseconds(-1),
                Filters   = new Dictionary <string, object>
                {
                    ["external_reference"] = createdPayment.ExternalReference,
                },
            };
            ResultsResourcesPage <Payment> results = client.Search(searchRequest);

            Assert.NotNull(results);
            Assert.NotNull(results.Paging);
            Assert.Equal(1, results.Paging.Total);
            Assert.NotNull(results.Results);
            Assert.Equal(createdPayment.Id, results.Results.First().Id);
        }
        public async Task SearchAsync_NullParameters_Success()
        {
            var           httpClientMock = new HttpClientMock();
            var           httpClient     = new DefaultHttpClient(httpClientMock.HttpClient);
            var           client         = new DummyClient(httpClient, null);
            var           path           = "/x";
            SearchRequest request        = null;
            string        json           = File.ReadAllText("Client/Mock/DummySearchResponse.json");
            var           url            = $"{MercadoPagoConfig.BaseUrl}{path}";
            var           httpResponse   = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(json),
            };

            // Mock
            httpClientMock.MockRequest(url, System.Net.Http.HttpMethod.Get, httpResponse);

            ResultsResourcesPage <DummyResource> resultsSearchPage
                = await client.SearchAsync(path, request);

            Assert.NotNull(resultsSearchPage);
            Assert.NotNull(resultsSearchPage.Paging);
            Assert.Equal(1000, resultsSearchPage.Paging.Total);
            Assert.Equal(10, resultsSearchPage.Paging.Limit);
            Assert.Equal(0, resultsSearchPage.Paging.Offset);
            Assert.NotNull(resultsSearchPage.Results);
            Assert.True(resultsSearchPage.Results.Count > 0);
        }
Exemplo n.º 9
0
        public void Search_ByExternalReference_Success()
        {
            AdvancedPaymentCreateRequest request = BuildCreateRequest(true, "approved");
            AdvancedPayment createdPayment       = Create(request);

            Thread.Sleep(5000);

            ResultsResourcesPage <AdvancedPayment> results =
                SearchByExternalReference(createdPayment.ExternalReference);

            Assert.NotNull(results);
            Assert.NotNull(results.Paging);
            Assert.Equal(1, results.Paging.Total);
            Assert.NotNull(results.Results);
            Assert.Equal(createdPayment.Id, results.Results.First().Id);
        }
Exemplo n.º 10
0
        public async Task SearchAsync_ByExternalReference_Success()
        {
            AdvancedPaymentCreateRequest request = await BuildCreateRequestAsync(true, "approved");

            AdvancedPayment createdPayment = await CreateAsync(request);

            await Task.Delay(5000);

            ResultsResourcesPage <AdvancedPayment> results =
                await SearchByExternalReferenceAsync(createdPayment.ExternalReference);

            Assert.NotNull(results);
            Assert.NotNull(results.Paging);
            Assert.Equal(1, results.Paging.Total);
            Assert.NotNull(results.Results);
            Assert.Equal(createdPayment.Id, results.Results.First().Id);
        }
Exemplo n.º 11
0
        public void Search_Parameters_Success()
        {
            var httpClientMock = new HttpClientMock();
            var httpClient     = new DefaultHttpClient(httpClientMock.HttpClient);
            var client         = new DummyClient(httpClient, null);
            var path           = "/x";
            var request        = new SearchRequest
            {
                Limit   = 10,
                Offset  = 100,
                Filters = new Dictionary <string, object>
                {
                    ["key"] = "value",
                },
            };
            var    url          = $"{MercadoPagoConfig.BaseUrl}{path}?key=value&limit=10&offset=100";
            string json         = File.ReadAllText("Client/Mock/DummySearchResponse.json");
            var    httpResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(json),
            };

            // Mock
            httpClientMock.MockRequest(url, System.Net.Http.HttpMethod.Get, httpResponse);

            ResultsResourcesPage <DummyResource> resultsSearchPage
                = client.Search(path, request);

            Assert.NotNull(resultsSearchPage);
            Assert.NotNull(resultsSearchPage.Paging);
            Assert.Equal(1000, resultsSearchPage.Paging.Total);
            Assert.Equal(10, resultsSearchPage.Paging.Limit);
            Assert.Equal(0, resultsSearchPage.Paging.Offset);
            Assert.NotNull(resultsSearchPage.Results);
            Assert.True(resultsSearchPage.Results.Count > 0);
        }