Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for /processor/token/create API #23

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions src/Plaid/Entity/Processor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace Going.Plaid.Entity
{
/// <summary>
/// Enum Processor
/// </summary>
/// <seealso href="https://plaid.com/docs/api/processors/#processor-token-create-request-processor"/>
public enum Processor
{
/// <summary>
/// ACH Processing Solutions
/// </summary>
/// <seealso href="https://achq.com/"/>
[EnumMember(Value = "achq")]
Achq,

/// <summary>
/// Checkbook Payments Solutions
/// </summary>
/// <seealso href="https://checkbook.io/"/>
[EnumMember(Value = "checkbook")]
Checkbook,

/// <summary>
/// Circle Payments System
/// </summary>
/// <seealso href="https://www.circle.com/"/>
[EnumMember(Value = "circle")]
circle,

/// <summary>
/// DriveWealth Investment System
/// </summary>
/// <seealso href="https://drivewealth.com/"/>
[EnumMember(Value = "drivewealth")]
DriveWealth,

/// <summary>
/// Dwolla Payments Infrastructure
/// </summary>
/// <seealso href="https://www.dwolla.com/"/>
[EnumMember(Value = "dwolla")]
Dwolla,

/// <summary>
/// Galileo Card Management System
/// </summary>
/// <seealso href="https://www.galileo-ft.com/"/>
[EnumMember(Value = "galileo")]
Galileo,

/// <summary>
/// Interactive Brokers Investment System
/// </summary>
/// <seealso href="https://www.interactivebrokers.com/"/>
[EnumMember(Value = "interactive_brokers")]
InteractiveBrokers,

/// <summary>
/// Modern Treasury Payments System
/// </summary>
/// <seealso href="https://www.moderntreasury.com/"/>
[EnumMember(Value = "modern_treasury")]
ModernTreasury,

/// <summary>
/// Ocrulus Document Management System
/// </summary>
/// <seealso href="https://www.ocrolus.com/"/>
[EnumMember(Value = "ocrolus")]
Ocrolus,

/// <summary>
/// Prime Trust Financial System
/// </summary>
/// <seealso href="https://www.primetrust.com/"/>
[EnumMember(Value = "prime_trust")]
PrimeTrust,

/// <summary>
/// Velox Clearing Firm
/// </summary>
/// <seealso href="https://www.velox-global.com/Home"/>
[EnumMember(Value = "velox")]
Velox,

/// <summary>
/// Vesta Fraud Prevention System
/// </summary>
/// <seealso href="https://trustvesta.com/"/>
[EnumMember(Value = "vesta")]
Vesta,

/// <summary>
/// VoPay Payments Management System
/// </summary>
/// <seealso href="https://vopay.com/"/>
[EnumMember(Value = "vopay")]
VoPay,
}
}
25 changes: 25 additions & 0 deletions src/Plaid/Management/ProcessorTokenRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Text.Json.Serialization;
using Going.Plaid.Entity;

namespace Going.Plaid.Management
{
/// <summary>
/// Represents a request for plaid's '<c>/processor/token/create</c>' endpoint. Exchange a Link <see cref="ExchangeTokenResponse.AccessToken"/> for a <see cref="ProcessorTokenResponse.ProcessorToken"/>.
/// </summary>
/// <seealso cref="RequestBase" />
/// <seealso href="https://plaid.com/docs/api/processors/#processortokencreate"/>
public class ProcessorTokenRequest : RequestBase
{
/// <summary>
/// The <see cref="Account.AccountId"/> for which to generate the processor token
/// </summary>
[JsonPropertyName("account_id")]
public string AccountId { get; set; } = string.Empty;

/// <summary>
/// The processor you are integrating with.
/// </summary>
[JsonPropertyName("processor")]
public Processor Processor { get; set; }
}
}
17 changes: 17 additions & 0 deletions src/Plaid/Management/ProcessorTokenResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Text.Json.Serialization;

namespace Going.Plaid.Management
{
/// <summary>
/// Represents a response from plaid's '<c>/processor/stripe/bank_account_token/create</c>' endpoint. Exchange a Link <see cref="ExchangeTokenResponse.AccessToken"/> for a <see cref="ProcessorTokenResponse.ProcessorToken"/>.
/// </summary>
/// <seealso cref="Going.Plaid.ResponseBase" />
public record ProcessorTokenResponse : ResponseBase
{
/// <summary>
/// The <c>processor_token</c> that can then be used by the Plaid partner to make API requests
/// </summary>
[JsonPropertyName("processor_token")]
public string ProcessorToken { get; init; } = string.Empty;
}
}
36 changes: 9 additions & 27 deletions src/Plaid/PlaidClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,48 +132,41 @@ public PlaidClient(
/// <summary>
/// Retrieves information about the status of an <see cref="Entity.Item"/>. Endpoint '<c>/item/get</c>'.
/// </summary>
/// <param name="request">The request.</param>
public Task<Management.GetItemResponse> FetchItemAsync(Management.GetItemRequest request) =>
PostAsync("item/get", request)
.ParseResponseAsync<Management.GetItemResponse>();

/// <summary>
/// Creates a token that can be used with the Link tool in the web client.
/// </summary>
/// <param name="request"></param>
public Task<Management.CreateLinkTokenResponse> CreateLinkTokenAsync(Management.CreateLinkTokenRequest request) =>
PostAsync("link/token/create", request)
.ParseResponseAsync<Management.CreateLinkTokenResponse>();

/// <summary>
/// Remove an <see cref="Entity.Item"/>. Once deleted, the access_token associated with the <see cref="Entity.Item"/> is no longer valid and cannot be used to access any data that was associated with the <see cref="Entity.Item"/>.
/// </summary>
/// <param name="request">The request.</param>
public Task<Management.RemoveItemResponse> RemoveItemAsync(Management.RemoveItemRequest request) =>
PostAsync("item/remove", request)
.ParseResponseAsync<Management.RemoveItemResponse>();

/// <summary>
/// Updates the webhook associated with an <see cref="Entity.Item"/>. This request triggers a WEBHOOK_UPDATE_ACKNOWLEDGED webhook.
/// </summary>
/// <param name="request">The request.</param>
public Task<Management.UpdateWebhookResponse> UpdateWebhookAsync(Management.UpdateWebhookRequest request) =>
PostAsync("item/webhook/update", request)
.ParseResponseAsync<Management.UpdateWebhookResponse>();

/// <summary>
/// Exchanges a Link public_token for an API access_token.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Management.ExchangeTokenResponse&gt;.</returns>
public Task<Management.ExchangeTokenResponse> ExchangeTokenAsync(Management.ExchangeTokenRequest request) =>
PostAsync("item/public_token/exchange", request)
.ParseResponseAsync<Management.ExchangeTokenResponse>();

/// <summary>
/// Rotates the access_token associated with an <see cref="Entity.Item"/>. The endpoint returns a new access_token and immediately invalidates the previous access_token.
/// </summary>
/// <param name="request">The request.</param>
public Task<Management.RotateAccessTokenResponse> RotateAccessTokenAsync(Management.RotateAccessTokenRequest request) =>
PostAsync("item/access_token/invalidate", request)
.ParseResponseAsync<Management.RotateAccessTokenResponse>();
Expand All @@ -183,23 +176,20 @@ public PlaidClient(
/// <summary>
/// Retrieves all institutions (the results will be paginated).
/// </summary>
/// <param name="request">The request.</param>
public Task<Institution.GetAllInstitutionsResponse> FetchAllInstitutionsAsync(Institution.GetAllInstitutionsRequest request) =>
PostAsync("institutions/get", request)
.ParseResponseAsync<Institution.GetAllInstitutionsResponse>();

/// <summary>
/// Retrieves the institutions that match the query parameters.
/// </summary>
/// <param name="request">The request.</param>
public Task<Institution.SearchResponse> FetchInstitutionsAsync(Institution.SearchRequest request) =>
PostAsync("institutions/search", request)
.ParseResponseAsync<Institution.SearchResponse>();

/// <summary>
/// Retrieves the institutions that match the id.
/// </summary>
/// <param name="request">The request.</param>
public Task<Institution.SearchByIdResponse> FetchInstitutionByIdAsync(Institution.SearchByIdRequest request) =>
PostAsync("institutions/get_by_id", request)
.ParseResponseAsync<Institution.SearchByIdResponse>();
Expand All @@ -209,7 +199,6 @@ public PlaidClient(
/// <summary>
/// Retrieves information pertaining to a <see cref="Entity.Item"/>’s income. In addition to the annual income, detailed information will be provided for each contributing income stream (or job).
/// </summary>
/// <param name="request">The request.</param>
public Task<Income.GetIncomeResponse> FetchUserIncomeAsync(Income.GetIncomeRequest request) =>
PostAsync("income/get", request)
.ParseResponseAsync<Income.GetIncomeResponse>();
Expand All @@ -235,8 +224,6 @@ public PlaidClient(
/// <summary>
/// Retrieves the bank account and routing numbers associated with an <see cref="Entity.Item"/>’s checking and savings accounts, along with high-level account data and balances.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Auth.GetAccountInfoResponse&gt;.</returns>
public Task<Auth.GetAccountInfoResponse> FetchAccountInfoAsync(Auth.GetAccountInfoRequest request) =>
PostAsync("auth/get", request)
.ParseResponseAsync<Auth.GetAccountInfoResponse>();
Expand All @@ -246,17 +233,13 @@ public PlaidClient(
/// <summary>
/// Retrieve high-level information about all accounts associated with an <see cref="Entity.Item"/>.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Balance.GetAccountResponse&gt;.</returns>
public Task<Balance.GetAccountResponse> FetchAccountAsync(Balance.GetAccountRequest request) =>
PostAsync("accounts/get", request)
.ParseResponseAsync<Balance.GetAccountResponse>();

/// <summary>
/// Retrieves the real-time balance for each of an <see cref="Entity.Item"/>’s accounts.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Balance.GetBalanceResponse&gt;.</returns>
public Task<Balance.GetBalanceResponse> FetchAccountBalanceAsync(Balance.GetBalanceRequest request) =>
PostAsync("accounts/balance/get", request)
.ParseResponseAsync<Balance.GetBalanceResponse>();
Expand All @@ -266,8 +249,6 @@ public PlaidClient(
/// <summary>
/// Retrieves detailed information on categories returned by Plaid.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Category.GetCategoriesResponse&gt;.</returns>
public Task<Category.GetCategoriesResponse> FetchCategoriesAsync(Category.GetCategoriesRequest request) =>
PostAsync("categories/get", request)
.ParseResponseAsync<Category.GetCategoriesResponse>();
Expand All @@ -277,8 +258,6 @@ public PlaidClient(
/// <summary>
/// Retrieves various account holder information on file with the financial institution, including names, emails, phone numbers, and addresses.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Identity.GetUserIdentityResponse&gt;.</returns>
public Task<Identity.GetUserIdentityResponse> FetchUserIdentityAsync(Identity.GetUserIdentityRequest request) =>
PostAsync("identity/get", request)
.ParseResponseAsync<Identity.GetUserIdentityResponse>();
Expand All @@ -288,19 +267,24 @@ public PlaidClient(
/// <summary>
/// Retrieves user-authorized transaction data for credit and depository-type <see cref="Entity.Account"/>.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Transactions.GetTransactionsResponse&gt;.</returns>
public Task<Transactions.GetTransactionsResponse> FetchTransactionsAsync(Transactions.GetTransactionsRequest request) =>
PostAsync("transactions/get", request)
.ParseResponseAsync<Transactions.GetTransactionsResponse>();

/* Processor */

/// <summary>
/// Exchanges a Link <see cref="Management.ExchangeTokenResponse.AccessToken"/> for a <see cref="Management.ProcessorTokenResponse.ProcessorToken"/>.Exchanges a Link access_token for an Stripe API stripe_bank_account_token.
/// </summary>
public Task<Management.ProcessorTokenResponse> FetchProcessorTokenAsync(Management.ProcessorTokenRequest request) =>
PostAsync("processor/token/create", request)
.ParseResponseAsync<Management.ProcessorTokenResponse>();

/* Stripe */

/// <summary>
/// Exchanges a Link access_token for an Stripe API stripe_bank_account_token.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Management.StripeTokenResponse&gt;.</returns>
public Task<Management.StripeTokenResponse> FetchStripeTokenAsync(Management.StripeTokenRequest request) =>
PostAsync("processor/stripe/bank_account_token/create", request)
.ParseResponseAsync<Management.StripeTokenResponse>();
Expand All @@ -313,8 +297,6 @@ public PlaidClient(
/// are account type credit with account subtype credit card or paypal, and account type loan
/// with account subtype student or mortgage.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task&lt;Management.LiabilitiesResponse&gt;.</returns>
public Task<Liabilities.GetLiabilitiesResponse> FetchLiabilitiesAsync(Liabilities.GetLiabilitiesRequest request) =>
PostAsync("liabilities/get", request)
.ParseResponseAsync<Liabilities.GetLiabilitiesResponse>();
Expand Down