public async Task CallsGetCreditorsEndpoint()
        {
            // given
            var subject = new CreditorsClient(_clientConfiguration);

            // when
            await subject.GetPageAsync();

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditors")
            .WithVerb(HttpMethod.Get);
        }
        public async Task ReturnsIndividualCreditor()
        {
            // given
            var creditor = await _resourceFactory.Creditor();

            var subject = new CreditorsClient(_clientConfiguration);

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

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.Not.Null.And.EqualTo(creditor.Id));
            Assert.That(actual.AddressLine1, Is.Not.Null.And.EqualTo(creditor.AddressLine1));
            Assert.That(actual.AddressLine2, Is.Not.Null.And.EqualTo(creditor.AddressLine2));
            Assert.That(actual.AddressLine3, Is.Not.Null.And.EqualTo(creditor.AddressLine3));
            Assert.That(actual.CanCreateRefunds, Is.Not.Null.And.EqualTo(creditor.CanCreateRefunds));
            Assert.That(actual.City, Is.Not.Null.And.EqualTo(creditor.City));
            Assert.That(actual.CountryCode, Is.Not.Null.And.EqualTo(creditor.CountryCode));
            Assert.That(actual.CreatedAt, Is.Not.Null.And.EqualTo(creditor.CreatedAt));
            Assert.That(actual.Links, Is.Not.Null);
            Assert.That(actual.Links.DefaultDkkPayoutAccount, Is.Not.Null);
            Assert.That(actual.Links.DefaultGbpPayoutAccount, Is.Not.Null);
            Assert.That(actual.Links.DefaultSekPayoutAccount, Is.Not.Null);
            Assert.That(actual.Name, Is.Not.Null.And.EqualTo(creditor.Name));
            Assert.That(actual.PostalCode, Is.Not.Null.And.EqualTo(creditor.PostalCode));
            Assert.That(actual.Region, Is.Not.Null.And.EqualTo(creditor.Region));
            Assert.That(actual.VerificationStatus, Is.Not.Null.And.EqualTo(creditor.VerificationStatus));

            Assert.That(actual.SchemeIdentifiers, Is.Not.Null);
            Assert.That(actual.SchemeIdentifiers.Any(), Is.True);

            var schemeIdentifier = actual.SchemeIdentifiers.SingleOrDefault(x => x.Currency == "GBP");

            Assert.That(schemeIdentifier, Is.Not.Null);
            Assert.That(schemeIdentifier.AddressLine1, Is.Not.Null);
            Assert.That(schemeIdentifier.CanSpecifyMandateReference, Is.True);
            Assert.That(schemeIdentifier.City, Is.Not.Null);
            Assert.That(schemeIdentifier.CountryCode, Is.Not.Null);
            Assert.That(schemeIdentifier.Currency, Is.Not.Null);
            Assert.That(schemeIdentifier.Email, Is.Not.Null);
            Assert.That(schemeIdentifier.MinimumAdvanceNotice, Is.Not.EqualTo(default(int)));
            Assert.That(schemeIdentifier.Name, Is.Not.Null);
            Assert.That(schemeIdentifier.PhoneNumber, Is.Not.Null);
            Assert.That(schemeIdentifier.PostalCode, Is.Not.Null);
            Assert.That(schemeIdentifier.Region, Is.Not.Null);
            Assert.That(schemeIdentifier.Reference, Is.Not.Null);
            Assert.That(schemeIdentifier.Scheme, Is.Not.Null);
        }
        public async Task CallsIndividualCreditorsEndpoint()
        {
            // given
            var subject = new CreditorsClient(_clientConfiguration);
            var id      = "CR12345678";

            // when
            await subject.ForIdAsync(id);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditors/CR12345678")
            .WithVerb(HttpMethod.Get);
        }
        public void IdIsNullOrWhiteSpaceThrows(string id)
        {
            // given
            var subject = new CreditorsClient(_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 void GetCreditorsRequestIsNullThrows()
        {
            // given
            var subject = new CreditorsClient(_clientConfiguration);

            GetCreditorsRequest request = null;

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

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

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

            var request = new UpdateCreditorRequest
            {
                Id = "CR12345678"
            };

            // when
            await subject.UpdateAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditors")
            .WithVerb(HttpMethod.Put);
        }
        public void UpdateCreditorRequestIdIsNullEmptyOrWhiteSpaceThrows(string id)
        {
            // given
            var subject = new CreditorsClient(_clientConfiguration);

            var request = new UpdateCreditorRequest
            {
                Id = id
            };

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

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

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

            var request = new GetCreditorsRequest
            {
                Limit = 1
            };

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

            // then
            Assert.That(result.Items.Count(), Is.EqualTo(request.Limit));
            Assert.That(result.Meta.Limit, Is.EqualTo(request.Limit));
            Assert.That(result.Meta.Cursors.Before, Is.Null);
            Assert.That(result.Meta.Cursors.After, Is.Null);
        }
        public async Task CallsGetCreditorsEndpointUsingRequest()
        {
            // given
            var subject = new CreditorsClient(_clientConfiguration);

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

            // when
            await subject.GetPageAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/creditors?before=before%20test&after=after%20test&limit=5")
            .WithVerb(HttpMethod.Get);
        }
Example #10
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);
        }
        internal async Task <Creditor> Creditor()
        {
            var creditorsClient = new CreditorsClient(_clientConfiguration);

            return((await creditorsClient.GetPageAsync()).Items.First());
        }
        public async Task UpdatesCreditor()
        {
            // given
            var creditor = await _resourceFactory.Creditor();

            var request = new UpdateCreditorRequest
            {
                Id           = creditor.Id,
                AddressLine1 = "Address Line 1",
                AddressLine2 = "Address Line 2",
                AddressLine3 = "Address Line 3",
                City         = "London",
                CountryCode  = "GB",
                Links        = new CreditorLinks
                {
                    DefaultDkkPayoutAccount = creditor.Links.DefaultDkkPayoutAccount,
                    DefaultGbpPayoutAccount = creditor.Links.DefaultGbpPayoutAccount,
                    DefaultSekPayoutAccount = creditor.Links.DefaultSekPayoutAccount,
                },
                Name       = "API Client Development",
                PostalCode = "SW1A 1AA",
                Region     = "Essex",
            };

            var subject = new CreditorsClient(_clientConfiguration);

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

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.EqualTo(request.Id));
            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.CanCreateRefunds, Is.Not.Null);
            Assert.That(actual.City, Is.EqualTo(request.City));
            Assert.That(actual.CountryCode, Is.EqualTo(request.CountryCode));
            Assert.That(actual.CreatedAt, Is.Not.Null.And.EqualTo(creditor.CreatedAt));
            Assert.That(actual.Links, Is.Not.Null);
            Assert.That(actual.Links.DefaultDkkPayoutAccount, Is.Not.Null.And.EqualTo(creditor.Links.DefaultDkkPayoutAccount));
            Assert.That(actual.Links.DefaultGbpPayoutAccount, Is.Not.Null.And.EqualTo(creditor.Links.DefaultGbpPayoutAccount));
            Assert.That(actual.Links.DefaultSekPayoutAccount, Is.Not.Null.And.EqualTo(creditor.Links.DefaultSekPayoutAccount));
            Assert.That(actual.Name, Is.EqualTo(request.Name));
            Assert.That(actual.PostalCode, Is.EqualTo(request.PostalCode));
            Assert.That(actual.Region, Is.EqualTo(request.Region));
            Assert.That(actual.VerificationStatus, Is.Not.Null);

            Assert.That(actual.SchemeIdentifiers, Is.Not.Null);
            Assert.That(actual.SchemeIdentifiers.Any(), Is.True);

            var schemeIdentifier = actual.SchemeIdentifiers.SingleOrDefault(x => x.Currency == "GBP");

            Assert.That(schemeIdentifier, Is.Not.Null);
            Assert.That(schemeIdentifier.AddressLine1, Is.Not.Null);
            Assert.That(schemeIdentifier.CanSpecifyMandateReference, Is.True);
            Assert.That(schemeIdentifier.City, Is.Not.Null);
            Assert.That(schemeIdentifier.CountryCode, Is.Not.Null);
            Assert.That(schemeIdentifier.Currency, Is.Not.Null);
            Assert.That(schemeIdentifier.Email, Is.Not.Null);
            Assert.That(schemeIdentifier.MinimumAdvanceNotice, Is.Not.EqualTo(default(int)));
            Assert.That(schemeIdentifier.Name, Is.Not.Null);
            Assert.That(schemeIdentifier.PhoneNumber, Is.Not.Null);
            Assert.That(schemeIdentifier.PostalCode, Is.Not.Null);
            Assert.That(schemeIdentifier.Region, Is.Not.Null);
            Assert.That(schemeIdentifier.Reference, Is.Not.Null);
            Assert.That(schemeIdentifier.Scheme, Is.Not.Null);
        }