public async Task MapsPagingProperties()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);

            var firstPageRequest = new GetCreditorBankAccountsRequest
            {
                Limit = 1
            };

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

            var secondPageRequest = new GetCreditorBankAccountsRequest
            {
                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);
        }
        public async Task CallsGetCreditorBankAccountsEndpoint()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);

            // when
            await subject.GetPageAsync();

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditor_bank_accounts")
            .WithVerb(HttpMethod.Get);
        }
        public async Task CallsIndividualCreditorBankAccountsEndpoint()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);
            var id      = "BA12345678";

            // when
            await subject.ForIdAsync(id);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditor_bank_accounts/BA12345678")
            .WithVerb(HttpMethod.Get);
        }
        public void IdIsNullOrWhiteSpaceThrows(string id)
        {
            // given
            var subject = new CreditorBankAccountsClient(_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)));
        }
        public async Task CreatesAndDisablesConflictingCreditorBankAccountUsingBankCode()
        {
            // given
            var createRequest = new CreateCreditorBankAccountRequest
            {
                AccountHolderName = "API BANK ACCOUNT",
                AccountNumber     = "532013001",
                BankCode          = "37040044",
                CountryCode       = "DE",
                Currency          = "EUR",
                Links             = new CreditorBankAccountLinks {
                    Creditor = _creditor.Id
                },
                Metadata = new Dictionary <string, string>
                {
                    ["Key1"] = "Value1",
                    ["Key2"] = "Value2",
                    ["Key3"] = "Value3",
                },
                SetAsDefaultPayoutAccount = true
            };

            var subject = new CreditorBankAccountsClient(_clientConfiguration);

            // when
            await subject.CreateAsync(createRequest);

            var creationResult = await subject.CreateAsync(createRequest);

            var disableRequest = new DisableCreditorBankAccountRequest
            {
                Id = creationResult.Item.Id
            };

            var disabledResult = await subject.DisableAsync(disableRequest);

            // then
            Assert.That(creationResult.Item.Id, Is.Not.Null);
            Assert.That(creationResult.Item.AccountHolderName, Is.EqualTo(createRequest.AccountHolderName));
            Assert.That(creationResult.Item.AccountNumberEnding, Is.Not.Null);
            Assert.That(creationResult.Item.BankName, Is.Not.Null);
            Assert.That(creationResult.Item.CountryCode, Is.EqualTo(createRequest.CountryCode));
            Assert.That(creationResult.Item.Currency, Is.EqualTo(createRequest.Currency));
            Assert.That(creationResult.Item.Metadata, Is.EqualTo(createRequest.Metadata));
            Assert.That(creationResult.Item.Links.Creditor, Is.EqualTo(createRequest.Links.Creditor));
            Assert.That(creationResult.Item.Enabled, Is.True);

            Assert.That(disabledResult.Item.Enabled, Is.False);
        }
        public void DisableCreditorBankAccountRequestIsNullThrows()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);

            DisableCreditorBankAccountRequest request = null;

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

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

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request)));
        }
        public async Task CreatesAndDisablesCreditorBankAccountUsingBranchCode()
        {
            // given
            var createRequest = new CreateCreditorBankAccountRequest
            {
                AccountHolderName = "API BANK ACCOUNT",
                AccountNumber     = "55666666",
                BranchCode        = "200000",
                CountryCode       = "GB",
                Currency          = "GBP",
                Links             = new CreditorBankAccountLinks {
                    Creditor = _creditor.Id
                },
                Metadata = new Dictionary <string, string>
                {
                    ["Key1"] = "Value1",
                    ["Key2"] = "Value2",
                    ["Key3"] = "Value3",
                }
            };

            var subject = new CreditorBankAccountsClient(_clientConfiguration);

            // when
            var creationResult = await subject.CreateAsync(createRequest);

            var disableRequest = new DisableCreditorBankAccountRequest
            {
                Id = creationResult.Item.Id
            };

            var disabledResult = await subject.DisableAsync(disableRequest);

            // then
            Assert.That(creationResult.Item.Id, Is.Not.Null.And.Not.Empty);
            Assert.That(creationResult.Item.AccountHolderName, Is.EqualTo(createRequest.AccountHolderName));
            Assert.That(creationResult.Item.AccountNumberEnding, Is.Not.Null);
            Assert.That(creationResult.Item.BankName, Is.Not.Null.And.Not.Empty);
            Assert.That(creationResult.Item.CountryCode, Is.EqualTo(createRequest.CountryCode));
            Assert.That(creationResult.Item.Currency, Is.EqualTo(createRequest.Currency));
            Assert.That(creationResult.Item.Metadata, Is.EqualTo(createRequest.Metadata));
            Assert.That(creationResult.Item.Links.Creditor, Is.EqualTo(createRequest.Links.Creditor));
            Assert.That(creationResult.Item.Enabled, Is.True);

            Assert.That(disabledResult.Item.Enabled, Is.False);
        }
        public void DisableCreditorBankAccountRequestIdIsNullEmptyOrWhiteSpaceThrows(string id)
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);

            var request = new DisableCreditorBankAccountRequest
            {
                Id = id
            };

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

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

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request.Id)));
        }
        public async Task CallsDisableCreditorBankAccountEndpoint()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);

            var request = new DisableCreditorBankAccountRequest
            {
                Id = "BA12345678"
            };

            // when
            await subject.DisableAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditor_bank_accounts/BA12345678/actions/disable")
            .WithVerb(HttpMethod.Post);
        }
        public async Task ReturnsCreditorBankAccounts()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);

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

            // then
            Assert.That(result.Any(), Is.True);
            Assert.That(result[0].Id, Is.Not.Null);
            Assert.That(result[0].AccountHolderName, Is.Not.Null);
            Assert.That(result[0].AccountNumberEnding, Is.Not.Null);
            Assert.That(result[0].BankName, Is.Not.Null);
            Assert.That(result[0].CountryCode, Is.Not.Null);
            Assert.That(result[0].Currency, Is.Not.Null);
            Assert.That(result[0].Links.Creditor, Is.Not.Null);
        }
        public async Task CallsCreateCreditorBankAccountEndpoint()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);

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

            // when
            await subject.CreateAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditor_bank_accounts")
            .WithHeader("Idempotency-Key")
            .WithVerb(HttpMethod.Post);
        }
        public async Task CallsGetCreditorBankAccountsEndpointUsingRequest()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);

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

            // when
            await subject.GetPageAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditor_bank_accounts?before=before%20test&after=after%20test&limit=5")
            .WithVerb(HttpMethod.Get);
        }
Пример #13
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);
        }
        public async Task ReturnsIndividualCreditorBankAccount()
        {
            // given
            var subject             = new CreditorBankAccountsClient(_clientConfiguration);
            var creditorBankAccount = (await subject.GetPageAsync()).Items.First();

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

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.Not.Null.And.EqualTo(creditorBankAccount.Id));
            Assert.That(actual.AccountHolderName, Is.Not.Null.And.EqualTo(creditorBankAccount.AccountHolderName));
            Assert.That(actual.AccountNumberEnding, Is.Not.Null.And.EqualTo(creditorBankAccount.AccountNumberEnding));
            Assert.That(actual.BankName, Is.Not.Null.And.EqualTo(creditorBankAccount.BankName));
            Assert.That(actual.CountryCode, Is.Not.Null.And.EqualTo(creditorBankAccount.CountryCode));
            Assert.That(actual.Currency, Is.Not.Null.And.EqualTo(creditorBankAccount.Currency));
            Assert.That(actual.Links.Creditor, Is.Not.Null.And.EqualTo(creditorBankAccount.Links.Creditor));
            Assert.That(actual.Enabled, Is.EqualTo(creditorBankAccount.Enabled));
        }
        public async Task PagesThroughCreditorBankAccounts()
        {
            // given
            var subject = new CreditorBankAccountsClient(_clientConfiguration);
            var firstId = (await subject.GetPageAsync()).Items.First().Id;

            var initialRequest = new GetCreditorBankAccountsRequest
            {
                After = firstId,
                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));
        }