/// <summary>
        /// Activates transaction round-up and adds remainder to savings goal
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountUid">Required parameter: Account uid</param>
        /// <param name="roundUpGoalPayload">Required parameter: Round-up goal</param>
        /// <returns>Task.</returns>
        /// <return>Returns the void response from the API call</return>
        public async Task ActivateRoundUpGoalAsync(StarlingClient starlingClient, Guid accountUid, Models.RoundUpGoalPayload roundUpGoalPayload)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/feed/account/{accountUid}/round-up");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "accountUid", accountUid }
            });
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Put, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //append body params
            var body = APIHelper.JsonSerialize(roundUpGoalPayload);

            request.Content = new StringContent(body);
            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);
        }
        /// <summary>
        /// Update a profile image if one already exists
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountHolderUid">Required parameter: Unique identifier of an account holder</param>
        /// <param name="contentType">Required parameter: Example:</param>
        /// <param name="inputStream">Required parameter: Attachment input stream</param>
        /// <returns>Task.</returns>
        /// <return>Returns the void response from the API call</return>
        public async Task UpdateProfileImageAsync(StarlingClient starlingClient, Guid accountHolderUid, string contentType, object inputStream)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/account-holder/{accountHolderUid}/profile-image");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "accountHolderUid", accountHolderUid }
            });
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            var headers = new Dictionary <string, string>
            {
                { "user-agent", "Starling Bank C# Client" }, { "Content-Type", contentType }, { "Authorization", $"Bearer {starlingClient.OAuthAccessToken}" }
            };
            var request = new HttpRequestMessage(HttpMethod.Put, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //append body params
            var body = APIHelper.JsonSerialize(inputStream);

            request.Content = new StringContent(body);
            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);
        }
Example #3
0
        /// <summary>
        /// Delete a payee account
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="payeeUid">Required parameter: Unique identifier of the payee</param>
        /// <param name="accountUid">Required parameter: Unique identifier of the payee account</param>
        /// <returns>Task.</returns>
        /// <return>Returns the void response from the API call</return>
        public async Task DeletePayeeAccountAsync(StarlingClient starlingClient, Guid payeeUid, Guid accountUid)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/payees/{payeeUid}/account/{accountUid}");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "payeeUid", payeeUid }, { "accountUid", accountUid }
            });
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient, true);
            var request = new HttpRequestMessage(HttpMethod.Delete, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);
        }
Example #4
0
        /// <summary>
        /// Get an account holder's payees
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <returns>Task&lt;Models.Payees&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Models.Payees response from the API call</return>
        public async Task <Models.Payees> GetPayeesAsync(StarlingClient starlingClient)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/payees");
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Get, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //prepare the API call request to fetch the response
            HttpClient client = _clientFactory.CreateClient("StarlingBank");
            //invoke request and get response
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                var content = await response.Content.ReadAsStringAsync();

                return(APIHelper.JsonDeserialize <Models.Payees>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
        /// <summary>
        /// Update the account holder's current address
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="addressUpdateRequest">Required parameter: Update account holder's current address</param>
        /// <returns>Task.</returns>
        /// <return>Returns the void response from the API call</return>
        public async Task UpdateCurrentAddressAsync(StarlingClient starlingClient, Models.AddressUpdateRequest addressUpdateRequest)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/addresses");
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Post, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            //append body params
            var body = APIHelper.JsonSerialize(addressUpdateRequest);

            request.Content = new StringContent(body);
            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);
        }
Example #6
0
        public CardsTests(DependencySetupFixture fixture)
        {
            ServiceProvider serviceProvider = fixture.ServiceProvider;

            _scope          = serviceProvider.CreateScope();
            _starlingClient = fixture.StarlingClient;
        }
        public AccountsTests(DependencySetupFixture fixture)
        {
            ServiceProvider serviceProvider = fixture.ServiceProvider;

            _scope          = serviceProvider.CreateScope();
            _starlingClient = fixture.StarlingClient;
            _accountUid     = fixture.AccountUid;
        }
Example #8
0
        /// <summary>
        /// Withdraw money from a savings goal
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountUid">Required parameter: Account uid</param>
        /// <param name="savingsGoalUid">Required parameter: Savings goal uid</param>
        /// <param name="transferUid">Required parameter: Transfer uid, generated by the caller</param>
        /// <param name="withdrawalRequest">Required parameter: Withdrawal request</param>
        /// <returns>Task&lt;Models.SavingsGoalTransferResponseV2&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Models.SavingsGoalTransferResponseV2 response from the API call</return>
        public async Task <Models.SavingsGoalTransferResponseV2> WithdrawMoneyAsync(StarlingClient starlingClient,
                                                                                    Guid accountUid,
                                                                                    Guid savingsGoalUid,
                                                                                    Guid transferUid,
                                                                                    Models.WithdrawalRequestV2 withdrawalRequest)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/account/{accountUid}/savings-goals/{savingsGoalUid}/withdraw-money/{transferUid}");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder,
                                                      new Dictionary <string, object>()
            {
                { "accountUid", accountUid }, { "savingsGoalUid", savingsGoalUid }, { "transferUid", transferUid }
            });
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetContentRequestHeaders(starlingClient, true);
            var request = new HttpRequestMessage(HttpMethod.Put, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            //append body params
            var body = APIHelper.JsonSerialize(withdrawalRequest);

            request.Content = new StringContent(body);
            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                var content = await response.Content.ReadAsStringAsync();

                return(APIHelper.JsonDeserialize <Models.SavingsGoalTransferResponseV2>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
Example #9
0
        /// <summary>
        /// Categories are subdivisions within an account.
        /// Within an account, the `defaultCategory` returned by [`/api/v2/accounts`](#operations-tag-Accounts) holds the main balance and transactions. Savings goals and spending spaces are examples of other categories.
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountUid">Required parameter: Account uid</param>
        /// <param name="categoryUid">Required parameter: Category uid</param>
        /// <param name="changesSince">Required parameter: Items which have changed since</param>
        /// <returns>Task&lt;Models.FeedItems&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Models.FeedItems response from the API call</return>
        public async Task <Models.FeedItems> QueryFeedItemsAsync(StarlingClient starlingClient, Guid accountUid, Guid categoryUid, DateTime changesSince)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/feed/account/{accountUid}/category/{categoryUid}");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder,
                                                      new Dictionary <string, object>()
            {
                { "accountUid", accountUid }, { "categoryUid", categoryUid }
            });
            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(queryBuilder,
                                                   new Dictionary <string, object>()
            {
                { "changesSince", changesSince.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK") }
            },
                                                   _arrayDeserializationFormat);
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Get, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            //prepare the API call request to fetch the response
            HttpClient client = _clientFactory.CreateClient("StarlingBank");
            //invoke request and get response
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                var content = await response.Content.ReadAsStringAsync();

                return(APIHelper.JsonDeserialize <Models.FeedItems>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
Example #10
0
        /// <summary>
        ///     Get whether there are available funds for a requested amount
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountUid">Required parameter: Account uid</param>
        /// <param name="targetAmountInMinorUnits">Required parameter: Target amount in minor units</param>
        /// <returns>Task&lt;Models.ConfirmationOfFundsResponse&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Models.ConfirmationOfFundsResponse response from the API call</return>
        public async Task <ConfirmationOfFundsResponse> GetConfirmationOfFundsAsync(StarlingClient starlingClient, Guid accountUid,
                                                                                    long targetAmountInMinorUnits)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/accounts/{accountUid}/confirmation-of-funds");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object> {
                { "accountUid", accountUid }
            });
            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(queryBuilder, new Dictionary <string, object> {
                { "targetAmountInMinorUnits", targetAmountInMinorUnits }
            },
                                                   _arrayDeserializationFormat);
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Get, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //prepare the API call request to fetch the response
            HttpClient client = _clientFactory.CreateClient("StarlingBank");
            //invoke request and get response
            //invoke request and get response
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                var content = await response.Content.ReadAsStringAsync();

                return(APIHelper.JsonDeserialize <ConfirmationOfFundsResponse>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
Example #11
0
        public static Dictionary <string, string> GetRequestHeaders(StarlingClient starlingClient, bool excludeAcceptHeader = false)
        {
            Dictionary <string, string> headers;

            if (excludeAcceptHeader)
            {
                headers = new Dictionary <string, string>();
            }
            else
            {
                headers = new Dictionary <string, string>
                {
                    { "accept", "application/json" }
                };
            }
            headers.Add("Authorization", $"Bearer {starlingClient.OAuthAccessToken}");
            return(headers);
        }
Example #12
0
        /// <summary>
        /// Categories are subdivisions within an account.
        /// Within an account, the `defaultCategory` returned by [`/api/v2/accounts`](#operations-tag-Accounts) holds the main balance and transactions. Savings goals and spending spaces are examples of other categories.
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountUid">Required parameter: Account uid</param>
        /// <param name="categoryUid">Required parameter: Category uid</param>
        /// <param name="feedItemUid">Required parameter: Feed item uid</param>
        /// <param name="feedItemAttachmentUid">Required parameter: Feed item attachment uid</param>
        /// <returns>Task&lt;Stream&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> DownloadFeedItemAttachmentAsync(StarlingClient starlingClient,
                                                                   Guid accountUid,
                                                                   Guid categoryUid,
                                                                   Guid feedItemUid,
                                                                   Guid feedItemAttachmentUid)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/feed/account/{accountUid}/category/{categoryUid}/{feedItemUid}/attachments/{feedItemAttachmentUid}");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder,
                                                      new Dictionary <string, object>()
            {
                { "accountUid", accountUid }, { "categoryUid", categoryUid }, { "feedItemUid", feedItemUid }, { "feedItemAttachmentUid", feedItemAttachmentUid }
            });
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient, true);
            var request = new HttpRequestMessage(HttpMethod.Get, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                return(await response.Content.ReadAsStreamAsync());
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
Example #13
0
        /// <summary>
        ///     To choose a file format, set the Accept header to either 'application/pdf' or 'text/csv'
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountUid">Required parameter: Example: aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaaaa</param>
        /// <param name="start">Required parameter: Example:</param>
        /// <param name="end">Optional parameter: Example:</param>
        /// <returns>Task&lt;Stream&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> DownloadPDFStatementForDateRangeAsync(StarlingClient starlingClient, Guid accountUid, DateTime start, DateTime?end = null)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/accounts/{accountUid}/statement/downloadForDateRange");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object> {
                { "accountUid", accountUid }
            });
            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(queryBuilder,
                                                   new Dictionary <string, object>
            {
                { "start", start.ToString("yyyy'-'MM'-'dd") }, { "end", end.HasValue ? end.Value.ToString("yyyy'-'MM'-'dd") : null }
            }, _arrayDeserializationFormat);
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient, true);
            var request = new HttpRequestMessage(HttpMethod.Get, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                return(await response.Content.ReadAsStreamAsync());
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
        /// <summary>
        /// Get a profile image if one exists
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountHolderUid">Required parameter: Unique identifier of an account holder</param>
        /// <returns>dynamic.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the dynamic response from the API call</return>
        public async Task <dynamic> DownloadProfileImageAsync(StarlingClient starlingClient, Guid accountHolderUid)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/account-holder/{accountHolderUid}/profile-image");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "accountHolderUid", accountHolderUid }
            });
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Get, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //prepare the API call request to fetch the response
            HttpClient client = _clientFactory.CreateClient("StarlingBank");
            //invoke request and get response
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                var content = await response.Content.ReadAsStringAsync();

                return(APIHelper.JsonDeserialize <dynamic>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
Example #15
0
        public static Dictionary <string, string> GetContentRequestHeaders(StarlingClient starlingClient, bool includeAcceptType = false)
        {
            Dictionary <string, string> headers;

            if (includeAcceptType)
            {
                headers = new Dictionary <string, string>
                {
                    { "accept", "application/json" },
                    { "content-type", "application/json; charset=utf-8" }
                };
            }
            else
            {
                headers = new Dictionary <string, string>
                {
                    { "content-type", "application/json; charset=utf-8" }
                };
            }
            headers.Add("Authorization", $"Bearer {starlingClient.OAuthAccessToken}");
            return(headers);
        }
        /// <summary>
        /// Deliver webhook payload for a Starling account event
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="defaultWebhookPayloadModel">Optional parameter: The webhook payload for the account event</param>
        /// <returns>Task.</returns>
        /// <exception cref="IBaseServices baseServices)">This, and all other HTTP codes, will be treated as a failure of hook receipt and Starling will resend with exponential back-off</exception>
        /// <return>Returns the void response from the API call</return>
        public async Task DispatchWebhookAsync(StarlingClient starlingClient, Models.DefaultWebhookPayloadModel defaultWebhookPayloadModel = null)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("/yourdomain.com/your/registered/web-hook/address");
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Post, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            //append body params
            var body = APIHelper.JsonSerialize(defaultWebhookPayloadModel);

            request.Content = new StringContent(body);
            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            //Error handling using HTTP status codes
            if (response.StatusCode == HttpStatusCode.InternalServerError)
            {
                throw new APIException(
                          "This, and all other HTTP codes, will be treated as a failure of hook receipt and Starling will resend with exponential back-off", request,
                          response);
            }
            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);
        }
Example #17
0
        /// <summary>
        /// Validates and processes the given query Url to clean empty slashes
        /// </summary>
        /// <param name="queryBuilder">The given query Url to process</param>
        /// <returns>Clean Url as string</returns>
        public static string GetUrl(StarlingClient starlingClient, StringBuilder queryBuilder)
        {
            //convert to immutable string
            var baseUrl = starlingClient.Environment == ServerEnvironment.PRODUCTION ? "https://api.starlingbank.com/" : "https://api-sandbox.starlingbank.com/";
            var url     = baseUrl + queryBuilder.ToString();
            //ensure that the urls are absolute
            Match match = Regex.Match(url, "^https?://[^/]+");

            if (!match.Success)
            {
                throw new ArgumentException("Invalid Url format.");
            }
            //remove redundant forward slashes
            var index    = url.IndexOf('?');
            var protocol = match.Value;
            var query    = url.Substring(protocol.Length, (index == -1 ? url.Length : index) - protocol.Length);

            query = Regex.Replace(query, "//+", "/");
            var parameters = index == -1 ? "" : url.Substring(index);

            //return process url
            return(string.Concat(protocol, query, parameters));;
        }
        /// <summary>
        /// This endpoint logs an individual out by disabling all of their active access tokens.
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <returns>Task.</returns>
        /// <return>Returns the void response from the API call</return>
        public async Task LogoutIndividualAsync(StarlingClient starlingClient)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/identity/logout");
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient, true);
            var request = new HttpRequestMessage(HttpMethod.Put, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //prepare the API call request to fetch the response
            HttpClient          client   = _clientFactory.CreateClient("StarlingBank");
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);
        }
        /// <summary>
        /// Get the spending insights grouped by counter party
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountUid">Required parameter: Account uid</param>
        /// <param name="year">Required parameter: Year</param>
        /// <param name="month">Required parameter: Month</param>
        /// <returns>Task&lt;Models.SpendingCounterPartySummary&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Models.SpendingCounterPartySummary response from the API call</return>
        public async Task <Models.SpendingCounterPartySummary> QuerySpendingInsightsByCounterpartyAsync(StarlingClient starlingClient, Guid accountUid,
                                                                                                        string year, Models.Month month)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/accounts/{accountUid}/spending-insights/counter-party");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "accountUid", accountUid }
            });
            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(queryBuilder,
                                                   new Dictionary <string, object>()
            {
                { "year", year }, { "month", Models.MonthHelper.ToValue(month) }
            }, _arrayDeserializationFormat);
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Get, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            //prepare the API call request to fetch the response
            HttpClient client = _clientFactory.CreateClient("StarlingBank");
            //invoke request and get response
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                var content = await response.Content.ReadAsStringAsync();

                return(APIHelper.JsonDeserialize <Models.SpendingCounterPartySummary>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
Example #20
0
 /// <summary>
 /// Starlings the client.
 /// </summary>
 /// <param name="starlingClient">The starling client.</param>
 /// <returns>StatementParametersBuilder.</returns>
 public StatementParametersBuilder StarlingClient(StarlingClient starlingClient)
 {
     _starlingClient = starlingClient;
     return(this);
 }
Example #21
0
        /// <summary>
        /// N.B. if you're looking for only the next payment date, this is also returned when getting a standing order in the `StandingOrder` response from the field `nextDate`.
        /// Categories are subdivisions within an account.
        /// Within an account, the `defaultCategory` returned by [`/api/v2/accounts`](#operations-tag-Accounts) holds the main balance and transactions. Savings goals and spending spaces are examples of other categories.
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="accountUid">Required parameter: Account uid</param>
        /// <param name="categoryUid">Required parameter: Category uid</param>
        /// <param name="paymentOrderUid">Required parameter: Payment Order uid</param>
        /// <param name="count">Optional parameter: Number of next payment dates to retrieve, between 1 and 100. If count is greater than the number of future payments all future payments will be returned. Defaults to 10.</param>
        /// <returns>Task&lt;Models.NextPaymentDatesResponse&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Models.NextPaymentDatesResponse response from the API call</return>
        public async Task <Models.NextPaymentDatesResponse> ListNextPaymentDatesAsync(StarlingClient starlingClient,
                                                                                      Guid accountUid,
                                                                                      Guid categoryUid,
                                                                                      Guid paymentOrderUid,
                                                                                      int?count = null)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/payments/local/account/{accountUid}/category/{categoryUid}/standing-orders/{paymentOrderUid}/upcoming-payments");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder,
                                                      new Dictionary <string, object>()
            {
                { "accountUid", accountUid }, { "categoryUid", categoryUid }, { "paymentOrderUid", paymentOrderUid }
            });
            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "count", count }
            }, _arrayDeserializationFormat);
            //validate and preprocess url
            var queryUrl = APIHelper.GetUrl(starlingClient, queryBuilder);
            //append request with appropriate headers and parameters
            Dictionary <string, string> headers = APIHelper.GetRequestHeaders(starlingClient);
            var request = new HttpRequestMessage(HttpMethod.Get, queryUrl);

            foreach (KeyValuePair <string, string> header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
            //prepare the API call request to fetch the response
            HttpClient client = _clientFactory.CreateClient("StarlingBank");
            //invoke request and get response
            HttpResponseMessage response = await client.SendAsync(request);

            //handle errors defined at the API level
            await _baseServices.ValidateResponse(request, response);

            try
            {
                var content = await response.Content.ReadAsStringAsync();

                return(APIHelper.JsonDeserialize <Models.NextPaymentDatesResponse>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }