Ejemplo n.º 1
0
        /// <summary>
        /// Get basic information about the account holder
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <returns>Task&lt;Models.AccountHolder&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Models.AccountHolder response from the API call</return>
        public async Task <Models.AccountHolder> GetAccountHolderAsync(StarlingClient starlingClient)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/account-holder");
            //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);
            }
            //invoke request and get 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.AccountHolder>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update ATM withdrawal control
        /// </summary>
        /// <param name="starlingClient">The starling client.</param>
        /// <param name="cardUid">Required parameter: Card uid of the targeted card</param>
        /// <param name="enabling">Required parameter: Whether ATM withdrawals should be allowed. Set to false to block, true to allow.</param>
        /// <returns>Task.</returns>
        /// <return>Returns the void response from the API call</return>
        public async Task EnableAtmAsync(StarlingClient starlingClient, Guid cardUid, Models.Enabling enabling)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/cards/{cardUid}/controls/atm-enabled");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "cardUid", cardUid }
            });
            //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(enabling);

            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>
        /// 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);
            }
        }
        /// <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);
        }
Ejemplo n.º 5
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="paymentOrderUid">Required parameter: Payment Order uid</param>
        /// <returns>Task&lt;Models.StandingOrder&gt;.</returns>
        /// <exception cref="IBaseServices baseServices)">Failed to parse the response: " + ex.Message</exception>
        /// <return>Returns the Models.StandingOrder response from the API call</return>
        public async Task <Models.StandingOrder> GetStandingOrderAsync(StarlingClient starlingClient, Guid accountUid, Guid categoryUid, Guid paymentOrderUid)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/payments/local/account/{accountUid}/category/{categoryUid}/standing-orders/{paymentOrderUid}");
            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder,
                                                      new Dictionary <string, object>()
            {
                { "accountUid", accountUid }, { "categoryUid", categoryUid }, { "paymentOrderUid", paymentOrderUid }
            });
            //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.StandingOrder>(content));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, request, response);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add money into 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="topUpRequest">Required parameter: Top up 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> AddMoneyAsync(StarlingClient starlingClient,
                                                                               Guid accountUid,
                                                                               Guid savingsGoalUid,
                                                                               Guid transferUid,
                                                                               Models.TopUpRequestV2 topUpRequest)
        {
            //prepare query string for API call
            var queryBuilder = new StringBuilder();

            queryBuilder.Append("api/v2/account/{accountUid}/savings-goals/{savingsGoalUid}/add-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(topUpRequest);

            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);
            }
        }