Exemple #1
0
        /// <inheritdoc />
        public async Task<PlaidResult<IList<Account>>> GetAuthAccountDataAsync(AccessToken accessToken)
        {
            Condition.Requires(accessToken).IsNotNull();

            PlaidRequest dataRequest = new PlaidRequest(this.clientId, this.clientSecret, accessToken.Value);
            HttpResponseMessage response = await this.httpClient.PostAsJsonAsync(GetEndpoint(ApiType.Auth, "get"), dataRequest);
            string responseJson = await response.Content.ReadAsStringAsync();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                // Can re-use AddUserResponse since it has accounts, just ignore transactions
                AddUserResponse dataResponse = JsonConvert.DeserializeObject<AddUserResponse>(responseJson);

                return new PlaidResult<IList<Account>>(dataResponse?.Accounts?.Select(a => a.ToAccount()).ToList());
            }

            PlaidResult<IList<Account>> errorResult = new PlaidResult<IList<Account>>();
            errorResult.Exception = await this.ParseException(response, responseJson);
            return errorResult;
        }
Exemple #2
0
        /// <inheritdoc />
        public async Task<PlaidResult<IList<Institution>>> GetInstitutionsAsync()
        {
            HttpResponseMessage response = await this.httpClient.GetAsync("institutions");
            string responseJson = await response.Content.ReadAsStringAsync();
            PlaidResult<IList<Institution>> result = new PlaidResult<IList<Institution>>();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                IList<InstitutionResponse> instResponse = JsonConvert.DeserializeObject<IList<InstitutionResponse>>(responseJson);
                result.Value = instResponse?.Select(x => x.ToInstitution()).ToList();
            }

            result.Exception = await this.ParseException(response, responseJson);
            return result;
        }
Exemple #3
0
        /// <inheritdoc />
        public async Task<PlaidResult<Institution>> GetInstitutionAsync(string id)
        {
            Condition.Requires(id).IsNotNullOrWhiteSpace();

            HttpResponseMessage response = await this.httpClient.GetAsync("institutions/" + id);
            string responseJson = await response.Content.ReadAsStringAsync();
            PlaidResult<Institution> result = new PlaidResult<Institution>();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                InstitutionResponse instResponse = JsonConvert.DeserializeObject<InstitutionResponse>(responseJson);
                result.Value = instResponse?.ToInstitution();
            }

            result.Exception = await this.ParseException(response, responseJson);
            return result;
        }
Exemple #4
0
        /// <inheritdoc />
        public async Task<PlaidResult<bool>> DeleteUserAsync(AccessToken accessToken, ApiType api = ApiType.Connect)
        {
            Condition.Requires(accessToken).IsNotNull();

            PlaidRequest deleteRequest = new PlaidRequest(this.clientId, this.clientSecret, accessToken.Value);

            HttpResponseMessage response = await this.httpClient.DeleteAsJsonAsync(GetEndpoint(api), deleteRequest);

            PlaidResult<bool> result = new PlaidResult<bool>(response.StatusCode == HttpStatusCode.OK);
            result.Exception = await this.ParseException(response);

            return result;
        }
Exemple #5
-1
        /// <inheritdoc />
        public async Task<PlaidResult<IList<Account>>> GetAccountsAsync(AccessToken accessToken)
        {
            Condition.Requires(accessToken).IsNotNull();

            PlaidRequest balanceRequest = new PlaidRequest(this.clientId, this.clientSecret, accessToken.Value);
            HttpResponseMessage response = await this.httpClient.PostAsJsonAsync("balance", balanceRequest);

            // Re-use add user result since it contains the account objects of interest
            AddUserResult userResult = await this.ProcessAddOrAuthResponse(response);
            PlaidResult<IList<Account>> result = new PlaidResult<IList<Account>>();

            if (userResult.Accounts != null) result.Value = new List<Account>(userResult.Accounts);

            result.Exception = userResult.Exception;

            return result;
        }