Esempio n. 1
0
    protected void GetCountriesButton_Click(object sender, EventArgs e)
    {
        CustomersClient customersService = new CustomersClient();

        CustomersGridView.DataSource = customersService.GetCountries(StartingLettersTextBox.Text);
        CustomersGridView.DataBind();
    }
Esempio n. 2
0
        public async Task MapsPagingProperties()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            var firstPageRequest = new GetCustomersRequest
            {
                Limit = 1
            };

            // when
            var firstPageResult = await subject.GetPageAsync(firstPageRequest);

            var secondPageRequest = new GetCustomersRequest
            {
                After = firstPageResult.Meta.Cursors.After,
                Limit = 2
            };

            var secondPageResult = await subject.GetPageAsync(secondPageRequest);

            // then
            Assert.That(firstPageResult.Items.Count(), Is.EqualTo(firstPageRequest.Limit));
            Assert.That(firstPageResult.Meta.Limit, Is.EqualTo(firstPageRequest.Limit));
            Assert.That(firstPageResult.Meta.Cursors.Before, Is.Null);
            Assert.That(firstPageResult.Meta.Cursors.After, Is.Not.Null);

            Assert.That(secondPageResult.Items.Count(), Is.EqualTo(secondPageRequest.Limit));
            Assert.That(secondPageResult.Meta.Limit, Is.EqualTo(secondPageRequest.Limit));
            Assert.That(secondPageResult.Meta.Cursors.Before, Is.Not.Null);
            Assert.That(secondPageResult.Meta.Cursors.After, Is.Not.Null);
        }
        private async Task <Customer> CreateCustomer(
            string countryCode,
            string language,
            string danishIdentityNumber  = null,
            string swedishIdentityNumber = null)
        {
            var request = new CreateCustomerRequest
            {
                AddressLine1         = "Address Line 1",
                AddressLine2         = "Address Line 2",
                AddressLine3         = "Address Line 3",
                City                 = "London",
                CompanyName          = "Company Name",
                CountryCode          = countryCode,
                DanishIdentityNumber = danishIdentityNumber,
                Email                = "*****@*****.**",
                FamilyName           = "Family Name",
                GivenName            = "Given Name",
                Language             = language,
                Metadata             = new Dictionary <string, string>
                {
                    ["Key1"] = "Value1",
                    ["Key2"] = "Value2",
                    ["Key3"] = "Value3",
                },
                PhoneNumber           = "+44 1234 567890",
                PostalCode            = "SW1A 1AA",
                Region                = "Essex",
                SwedishIdentityNumber = swedishIdentityNumber
            };

            var customersClient = new CustomersClient(_clientConfiguration);

            return((await customersClient.CreateAsync(request)).Item);
        }
Esempio n. 4
0
        public async Task ReturnsIndividualCustomerForNewZealand()
        {
            // given
            var customer = await _resourceFactory.CreateForeignCustomer();

            var subject = new CustomersClient(_clientConfiguration);

            // when
            var result = await subject.ForIdAsync(customer.Id);

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.Not.Null);
            Assert.That(actual.AddressLine1, Is.Not.Null.And.EqualTo(customer.AddressLine1));
            Assert.That(actual.AddressLine2, Is.Not.Null.And.EqualTo(customer.AddressLine2));
            Assert.That(actual.AddressLine3, Is.Not.Null.And.EqualTo(customer.AddressLine3));
            Assert.That(actual.City, Is.Not.Null.And.EqualTo(customer.City));
            Assert.That(actual.CountryCode, Is.Not.Null.And.EqualTo(customer.CountryCode));
            Assert.That(actual.CreatedAt, Is.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(actual.Email, Is.Not.Null.And.EqualTo(customer.Email));
            Assert.That(actual.FamilyName, Is.Not.Null.And.EqualTo(customer.FamilyName));
            Assert.That(actual.GivenName, Is.Not.Null.And.EqualTo(customer.GivenName));
            Assert.That(actual.Language, Is.Not.Null.And.EqualTo(customer.Language));
            Assert.That(actual.Metadata, Is.Not.Null.And.EqualTo(customer.Metadata));
            Assert.That(actual.PhoneNumber, Is.Not.Null.And.EqualTo(customer.PhoneNumber));
            Assert.That(actual.PostalCode, Is.Not.Null.And.EqualTo(customer.PostalCode));
            Assert.That(actual.Region, Is.Not.Null.And.EqualTo(customer.Region));
        }
Esempio n. 5
0
 public SearchBilling()
 {
     customersClient  = new CustomersClient(serviceAddress);
     ordersClient     = new OrdersClient(serviceAddress);
     goodsClient      = new GoodsClient(serviceAddress);
     componentsClient = new ComponentsClient(serviceAddress);
 }
Esempio n. 6
0
        public async Task ReturnsCustomers()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            // when
            var result = (await subject.GetPageAsync()).Items.ToList();

            // then
            Assert.That(result.Any(), Is.True);
            Assert.That(result[0], Is.Not.Null);
            Assert.That(result[0].Id, Is.Not.Null);
            Assert.That(result[0].AddressLine1, Is.Not.Null);
            Assert.That(result[0].AddressLine2, Is.Not.Null);
            Assert.That(result[0].AddressLine3, Is.Not.Null);
            Assert.That(result[0].City, Is.Not.Null);
            Assert.That(result[0].CountryCode, Is.Not.Null);
            Assert.That(result[0].CreatedAt, Is.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(result[0].DanishIdentityNumber, Is.Not.Null);
            Assert.That(result[0].Email, Is.Not.Null);
            Assert.That(result[0].FamilyName, Is.Not.Null);
            Assert.That(result[0].GivenName, Is.Not.Null);
            Assert.That(result[0].Language, Is.Not.Null);
            Assert.That(result[0].Metadata, Is.Not.Null);
            Assert.That(result[0].PhoneNumber, Is.Not.Null);
            Assert.That(result[0].PostalCode, Is.Not.Null);
            Assert.That(result[0].Region, Is.Not.Null);
            Assert.That(result[0].SwedishIdentityNumber, Is.Not.Null);
        }
Esempio n. 7
0
        public async Task CreatesConflictingCustomer()
        {
            // given
            var request = new CreateCustomerRequest
            {
                AddressLine1         = "Address Line 1",
                AddressLine2         = "Address Line 2",
                AddressLine3         = "Address Line 3",
                City                 = "London",
                CompanyName          = "Company Name",
                CountryCode          = "NZ",
                DanishIdentityNumber = "2205506218",
                Email                = "*****@*****.**",
                FamilyName           = "Family Name",
                GivenName            = "Given Name",
                Language             = "en",
                Metadata             = new Dictionary <string, string>
                {
                    ["Key1"] = "Value1",
                    ["Key2"] = "Value2",
                    ["Key3"] = "Value3",
                },
                PhoneNumber           = "+44 20 7183 8674",
                PostalCode            = "SW1A 1AA",
                Region                = "Essex",
                SwedishIdentityNumber = "5302256218",
            };

            var subject = new CustomersClient(_clientConfiguration);

            // when
            await subject.CreateAsync(request);

            var result = await subject.CreateAsync(request);

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.Not.Null);
            Assert.That(actual.AddressLine1, Is.EqualTo(request.AddressLine1));
            Assert.That(actual.AddressLine2, Is.EqualTo(request.AddressLine2));
            Assert.That(actual.AddressLine3, Is.EqualTo(request.AddressLine3));
            Assert.That(actual.City, Is.EqualTo(request.City));
            Assert.That(actual.CountryCode, Is.EqualTo(request.CountryCode));
            Assert.That(actual.CreatedAt, Is.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(actual.DanishIdentityNumber, Is.EqualTo(request.DanishIdentityNumber));
            Assert.That(actual.Email, Is.EqualTo(request.Email));
            Assert.That(actual.FamilyName, Is.EqualTo(request.FamilyName));
            Assert.That(actual.GivenName, Is.EqualTo(request.GivenName));
            Assert.That(actual.Language, Is.EqualTo(request.Language));
            Assert.That(actual.Metadata, Is.EqualTo(request.Metadata));
            Assert.That(actual.PhoneNumber, Is.EqualTo(request.PhoneNumber));
            Assert.That(actual.PostalCode, Is.EqualTo(request.PostalCode));
            Assert.That(actual.Region, Is.EqualTo(request.Region));
            Assert.That(actual.SwedishIdentityNumber, Does.Contain(request.SwedishIdentityNumber));
        }
Esempio n. 8
0
        public async Task UpdatesCustomerReplacingMetadata()
        {
            // given
            var customer = await _resourceFactory.CreateForeignCustomer();

            var subject = new CustomersClient(_clientConfiguration);

            var request = new UpdateCustomerRequest
            {
                Id                   = customer.Id,
                AddressLine1         = "Address Line 1",
                AddressLine2         = "Address Line 2",
                AddressLine3         = "Address Line 3",
                City                 = "London",
                CompanyName          = "Company Name 2",
                CountryCode          = "NZ",
                DanishIdentityNumber = "2205506218",
                Email                = "*****@*****.**",
                FamilyName           = "Family Name 2",
                GivenName            = "Given Name 22",
                Language             = "en",
                Metadata             = new Dictionary <string, string>
                {
                    ["Key4"] = "Value6",
                    ["Key5"] = "Value7",
                    ["Key6"] = "Value8",
                },
                PhoneNumber = "+44 1235 567890",
                PostalCode  = "SW1A 1AA",
                Region      = "Essex",
            };

            // when
            var result = await subject.UpdateAsync(request);

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.Not.Null);
            Assert.That(actual.AddressLine1, Is.EqualTo(request.AddressLine1));
            Assert.That(actual.AddressLine2, Is.EqualTo(request.AddressLine2));
            Assert.That(actual.AddressLine3, Is.EqualTo(request.AddressLine3));
            Assert.That(actual.City, Is.EqualTo(request.City));
            Assert.That(actual.CountryCode, Is.EqualTo(request.CountryCode));
            Assert.That(actual.CreatedAt, Is.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(actual.DanishIdentityNumber, Is.EqualTo(request.DanishIdentityNumber));
            Assert.That(actual.Email, Is.EqualTo(request.Email));
            Assert.That(actual.FamilyName, Is.EqualTo(request.FamilyName));
            Assert.That(actual.GivenName, Is.EqualTo(request.GivenName));
            Assert.That(actual.Language, Is.EqualTo(request.Language));
            Assert.That(actual.Metadata, Is.EqualTo(request.Metadata));
            Assert.That(actual.PhoneNumber, Is.EqualTo(request.PhoneNumber));
            Assert.That(actual.PostalCode, Is.EqualTo(request.PostalCode));
            Assert.That(actual.Region, Is.EqualTo(request.Region));
        }
Esempio n. 9
0
        public async Task <CustomerInfo> GetCustomerInfoAsync(string customerServiceUrl, int customerId)
        {
            var client = new CustomersClient(customerServiceUrl, _httpClientFactory.CreateClient());

            //if customer does not exist -> 404
            var customerInfo = await client.GetAsync(customerId);

            return(new CustomerInfo
            {
                Name = customerInfo.Name,
                Surname = customerInfo.Surname
            });
        }
Esempio n. 10
0
        public async Task CallsGetCustomersEndpoint()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            // when
            await subject.GetPageAsync();

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/customers")
            .WithVerb(HttpMethod.Get);
        }
        static void RunCustomersClient(IMundiAPIClient client)
        {
            //Criar + Atualizar + Obter
            Console.WriteLine("Criar + Atualizar + Obter");
            var customerId = CustomersClient.CreateCustomer(client);

            CustomersClient.UpdateCustomer(client, customerId);
            CustomersClient.GetCustomer(client, customerId);

            //Listar
            Console.WriteLine("Listar");
            CustomersClient.GetCustomers(client);
        }
Esempio n. 12
0
        public void IdIsNullOrWhiteSpaceThrows(string id)
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            // when
            AsyncTestDelegate test = () => subject.ForIdAsync(id);

            // then
            var ex = Assert.ThrowsAsync <ArgumentException>(test);

            Assert.That(ex.Message, Is.Not.Null);
            Assert.That(ex.ParamName, Is.EqualTo(nameof(id)));
        }
Esempio n. 13
0
        public async Task CallsIndividualCustomersEndpoint()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);
            var id      = "CU12345678";

            // when
            await subject.ForIdAsync(id);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/customers/CU12345678")
            .WithVerb(HttpMethod.Get);
        }
Esempio n. 14
0
        public void CreateCustomerRequestIsNullThrows()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            CreateCustomerRequest request = null;

            // when
            AsyncTestDelegate test = () => subject.CreateAsync(request);

            // then
            var ex = Assert.ThrowsAsync <ArgumentNullException>(test);

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request)));
        }
Esempio n. 15
0
    protected void GetCountriesButton_Click(object sender, EventArgs e)
    {
        // Does cached item exist?
        if (countryDataTable == null)
        {
            CustomersClient customersService = new CustomersClient();
            // Retrieve DataTable from WCF Service
            countryDataTable = customersService.GetCountries(StartingLettersTextBox.Text);
            // Save DataTable to cache
            Cache["Countries"] = countryDataTable;
        }

        // Set GridView DataSource
        CustomersGridView.DataSource = countryDataTable;
        CustomersGridView.DataBind();
    }
Esempio n. 16
0
    protected void GetCountriesButton_Click(object sender, EventArgs e)
    {
        // Does cached item exist?
        if (countryDataTable == null)
        {
            CustomersClient customersService = new CustomersClient();
            // Retrieve DataTable from WCF Service
            countryDataTable = customersService.GetCountries(StartingLettersTextBox.Text);
            // Save DataTable to cache
            Cache["Countries"] = countryDataTable;

        }

        // Set GridView DataSource
        CustomersGridView.DataSource = countryDataTable;
        CustomersGridView.DataBind();
    }
        static void RunAddressesClient(IMundiAPIClient client)
        {
            //Criação + Atualização + Consulta
            Console.WriteLine("Criação + Atualização + Consulta");
            var customerId = CustomersClient.CreateCustomer(client);
            var addressId  = AddressesClient.CreateAddress(client, customerId);

            AddressesClient.UpdateAddress(client, customerId, addressId);
            AddressesClient.GetAddress(client, customerId, addressId);

            //Listagem:
            Console.WriteLine("Listagem");
            AddressesClient.GetAddresses(client, customerId);

            //Exclusão
            Console.WriteLine("Exclusão");
            AddressesClient.DeleteAddress(client, customerId, addressId);
        }
Esempio n. 18
0
        public void UpdateCustomerRequestIdIsNullOrWhiteSpaceThrows(string id)
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            var request = new UpdateCustomerRequest
            {
                Id = id
            };

            // when
            AsyncTestDelegate test = () => subject.UpdateAsync(request);

            // then
            var ex = Assert.ThrowsAsync <ArgumentException>(test);

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request.Id)));
        }
Esempio n. 19
0
        public async Task CallsUpdateCustomerEndpoint()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            var request = new UpdateCustomerRequest
            {
                Id = "CU12345678"
            };

            // when
            await subject.UpdateAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/customers")
            .WithVerb(HttpMethod.Put);
        }
        static void RunCardsClient(IMundiAPIClient client)
        {
            //Criação + Consulta + Atualização
            Console.WriteLine("Criação + Consulta + Atualização");
            var customerId = CustomersClient.CreateCustomer(client);
            var cardId     = CardsClient.CreateCreditCard(client, customerId);

            CardsClient.GetCreditCard(client, customerId, cardId);
            CardsClient.UpdateCreditCard(client, customerId, cardId);

            //Listagem
            Console.WriteLine("Listagem");
            CardsClient.GetCreditCards(client, customerId);

            //Exclusão
            Console.WriteLine("Exclusão");
            CardsClient.DeleteCreditCard(client, customerId, cardId);
        }
Esempio n. 21
0
        public async Task CallsCreateCustomerEndpoint()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            var request = new CreateCustomerRequest
            {
                IdempotencyKey = Guid.NewGuid().ToString()
            };

            // when
            await subject.CreateAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/customers")
            .WithHeader("Idempotency-Key")
            .WithVerb(HttpMethod.Post);
        }
        public void ValidationFailsForRequestThrows()
        {
            // given
            var request = new CreateCustomerRequest
            {
                AddressLine1         = "Address Line 1",
                AddressLine2         = "Address Line 2",
                AddressLine3         = "Address Line 3",
                City                 = "London",
                CompanyName          = "Company Name",
                CountryCode          = "DK",
                DanishIdentityNumber = "2205506218",
                Email                = "*****@*****.**",
                FamilyName           = "Family Name",
                GivenName            = "Given Name",
                Language             = "incorrect language", // This triggers the error.
                Metadata             = new Dictionary <string, string>
                {
                    ["Key1"] = "Value1",
                    ["Key2"] = "Value2",
                    ["Key3"] = "Value3",
                },
                PostalCode            = "SW1A 1AA",
                Region                = "Essex",
                SwedishIdentityNumber = "5302256218",
            };

            var subject = new CustomersClient(_clientConfiguration);

            // when
            AsyncTestDelegate test = () => subject.CreateAsync(request);

            // then
            var ex = Assert.ThrowsAsync <ValidationFailedException>(test);

            Assert.That(ex.Code, Is.EqualTo((int)HttpStatusCode.UnprocessableEntity));
            Assert.That(ex.DocumentationUrl, Is.Not.Null);
            Assert.That(ex.Errors?.Any(), Is.True);
            Assert.That(ex.Message, Is.Not.Null.And.Not.Empty);
            Assert.That(ex.RawResponse, Is.Not.Null.And.Not.Empty);
            Assert.That(ex.RequestId, Is.Not.Null.And.Not.Empty);
        }
Esempio n. 23
0
        public async Task CallsGetCustomersEndpointUsingRequest()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);

            var request = new GetCustomersRequest
            {
                Before = "before test",
                After  = "after test",
                Limit  = 5
            };

            // when
            await subject.GetPageAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/customers?before=before%20test&after=after%20test&limit=5")
            .WithVerb(HttpMethod.Get);
        }
Esempio n. 24
0
        public GoCardlessClient(ClientConfiguration configuration)
        {
            _configuration = configuration;

            BankDetailsLookups    = new BankDetailsLookupsClient(configuration);
            CreditorBankAccounts  = new CreditorBankAccountsClient(configuration);
            Creditors             = new CreditorsClient(configuration);
            CustomerBankAccounts  = new CustomerBankAccountsClient(configuration);
            CustomerNotifications = new CustomerNotificationsClient(configuration);
            Customers             = new CustomersClient(configuration);
            Events = new EventsClient(configuration);
            MandateImportEntries = new MandateImportEntriesClient(configuration);
            MandateImports       = new MandateImportsClient(configuration);
            MandatePdfs          = new MandatePdfsClient(configuration);
            Mandates             = new MandatesClient(configuration);
            Payments             = new PaymentsClient(configuration);
            PayoutItems          = new PayoutItemsClient(configuration);
            Payouts       = new PayoutsClient(configuration);
            RedirectFlows = new RedirectFlowsClient(configuration);
            Refunds       = new RefundsClient(configuration);
            Subscriptions = new SubscriptionsClient(configuration);
        }
Esempio n. 25
0
        public async Task PagesThroughCustomers()
        {
            // given
            var subject = new CustomersClient(_clientConfiguration);
            var firstId = (await subject.GetPageAsync()).Items.First().Id;

            var initialRequest = new GetCustomersRequest
            {
                After = firstId,
                CreatedGreaterThan = new DateTimeOffset(DateTime.Now.AddDays(-1)),
                Limit = 1,
            };

            // when
            var result = await subject
                         .BuildPager()
                         .StartFrom(initialRequest)
                         .AndGetAllAfterAsync();

            // then
            Assert.That(result.Count, Is.GreaterThan(1));
            Assert.That(result[0].Id, Is.Not.Null.And.Not.EqualTo(result[1].Id));
            Assert.That(result[1].Id, Is.Not.Null.And.Not.EqualTo(result[0].Id));
        }
Esempio n. 26
0
 public void Setup()
 {
     _client = new CustomersClient();
 }
Esempio n. 27
0
 protected void GetCountriesButton_Click(object sender, EventArgs e)
 {
     CustomersClient customersService = new CustomersClient();
     CustomersGridView.DataSource = customersService.GetCountries(StartingLettersTextBox.Text);
     CustomersGridView.DataBind();
 }
Esempio n. 28
0
 private void frmCustomerAdmin_Load(object sender, EventArgs e)
 {
     InitializeGridView(gridView, colId);
     Client = SdkClient.Create <CustomersClient>();
 }