1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-21 22:29:38 +02:00

Enable consent for additional plaid products
Some checks failed
Publish Docker image / ci (push) Has been cancelled
Publish Docker image / Build docker image (push) Has been cancelled

This commit is contained in:
Zach Gollwitzer 2024-11-15 17:33:18 -05:00
parent cbba2ba675
commit 69f6d7f8ea
2 changed files with 13 additions and 6 deletions

View file

@ -19,6 +19,8 @@ export default class extends Controller {
} }
handleSuccess(public_token, metadata) { handleSuccess(public_token, metadata) {
window.location.href = "/accounts";
fetch("/plaid_items", { fetch("/plaid_items", {
method: "POST", method: "POST",
headers: { headers: {

View file

@ -1,9 +1,9 @@
class Provider::Plaid class Provider::Plaid
attr_reader :client attr_reader :client
MAYBE_SUPPORTED_PLAID_PRODUCTS = %w[transactions investments liabilities].freeze
PLAID_COUNTRY_CODES = %w[US GB ES NL FR IE CA DE IT PL DK NO SE EE LT LV PT BE].freeze PLAID_COUNTRY_CODES = %w[US GB ES NL FR IE CA DE IT PL DK NO SE EE LT LV PT BE].freeze
PLAID_LANGUAGES = %w[da nl en et fr de hi it lv lt no pl pt ro es sv vi].freeze PLAID_LANGUAGES = %w[da nl en et fr de hi it lv lt no pl pt ro es sv vi].freeze
PLAID_PRODUCTS = %w[transactions investments liabilities].freeze
MAX_HISTORY_DAYS = Rails.env.development? ? 90 : 730 MAX_HISTORY_DAYS = Rails.env.development? ? 90 : 730
class << self class << self
@ -74,7 +74,8 @@ class Provider::Plaid
request = Plaid::LinkTokenCreateRequest.new({ request = Plaid::LinkTokenCreateRequest.new({
user: { client_user_id: user_id }, user: { client_user_id: user_id },
client_name: "Maybe Finance", client_name: "Maybe Finance",
products: get_products(accountable_type), products: [ get_primary_product(accountable_type) ],
additional_consented_products: get_additional_consented_products(accountable_type),
country_codes: [ get_plaid_country_code(country) ], country_codes: [ get_plaid_country_code(country) ],
language: get_plaid_language(language), language: get_plaid_language(language),
webhook: webhooks_url, webhook: webhooks_url,
@ -198,17 +199,21 @@ class Provider::Plaid
[ transactions, securities ] [ transactions, securities ]
end end
def get_products(accountable_type) def get_primary_product(accountable_type)
case accountable_type case accountable_type
when "Investment" when "Investment"
%w[investments] "investments"
when "CreditCard", "Loan" when "CreditCard", "Loan"
%w[liabilities] "liabilities"
else else
%w[transactions] "transactions"
end end
end end
def get_additional_consented_products(accountable_type)
MAYBE_SUPPORTED_PLAID_PRODUCTS - [ get_primary_product(accountable_type) ]
end
def get_plaid_country_code(country_code) def get_plaid_country_code(country_code)
PLAID_COUNTRY_CODES.include?(country_code) ? country_code : "US" PLAID_COUNTRY_CODES.include?(country_code) ? country_code : "US"
end end