Skip to content

Commit fc73b1d

Browse files
committed
Add support for PlaidEU in UI also
- This looks like partial support atm
1 parent aaa92aa commit fc73b1d

File tree

3 files changed

+86
-17
lines changed

3 files changed

+86
-17
lines changed

app/models/provider/plaid_adapter.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1+
# PlaidAdapter serves dual purposes:
2+
#
3+
# 1. Configuration Manager (class-level):
4+
# - Manages Rails.application.config.plaid (US region)
5+
# - Exposes 3 configurable fields in "Plaid" section of settings UI
6+
# - PlaidEuAdapter separately manages EU region in "Plaid Eu" section
7+
#
8+
# 2. Instance Adapter (instance-level):
9+
# - Wraps ALL PlaidAccount instances regardless of region (US or EU)
10+
# - The PlaidAccount's plaid_item.plaid_region determines which config to use
11+
# - Delegates to Provider::Registry.plaid_provider_for_region(region)
112
class Provider::PlaidAdapter < Provider::Base
213
include Provider::Syncable
314
include Provider::InstitutionMetadata
415
include Provider::Configurable
516

6-
# Register this adapter with the factory
17+
# Register this adapter with the factory for ALL PlaidAccount instances
718
Provider::Factory.register("PlaidAccount", self)
819

920
# Configuration for Plaid US
1021
configure do
1122
description <<~DESC
1223
Setup instructions:
1324
1. Visit the [Plaid Dashboard](https://dashboard.plaid.com/team/keys) to get your API credentials
14-
2. Your Client ID and Secret Key are required to enable Plaid bank sync
25+
2. Your Client ID and Secret Key are required to enable Plaid bank sync for US/CA banks
1526
3. For production use, set environment to 'production', for testing use 'sandbox'
1627
DESC
1728

1829
field :client_id,
1930
label: "Client ID",
20-
required: true,
31+
required: false,
2132
env_key: "PLAID_CLIENT_ID",
2233
description: "Your Plaid Client ID from the Plaid Dashboard"
2334

2435
field :secret,
2536
label: "Secret Key",
26-
required: true,
37+
required: false,
2738
secret: true,
2839
env_key: "PLAID_SECRET",
2940
description: "Your Plaid Secret from the Plaid Dashboard"
@@ -40,7 +51,7 @@ def provider_name
4051
"plaid"
4152
end
4253

43-
# Reload Plaid configuration when settings are updated
54+
# Reload Plaid US configuration when settings are updated
4455
def self.reload_configuration
4556
client_id = config_value(:client_id).presence || ENV["PLAID_CLIENT_ID"]
4657
secret = config_value(:secret).presence || ENV["PLAID_SECRET"]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# PlaidEuAdapter is a configuration-only manager for Plaid EU credentials.
2+
#
3+
# It does NOT register as a provider type because:
4+
# - There's no separate "PlaidEuAccount" model
5+
# - All PlaidAccounts (regardless of region) use PlaidAdapter as their instance adapter
6+
#
7+
# This class only manages Rails.application.config.plaid_eu, which
8+
# Provider::Registry.plaid_provider_for_region(:eu) uses to create Provider::Plaid instances.
9+
#
10+
# This separation into a distinct adapter class provides:
11+
# - Clear UI separation: "Plaid" vs "Plaid Eu" sections in settings
12+
# - Better UX: Users only configure the region they need
13+
class Provider::PlaidEuAdapter
14+
include Provider::Configurable
15+
16+
# Configuration for Plaid EU
17+
configure do
18+
description <<~DESC
19+
Setup instructions:
20+
1. Visit the [Plaid Dashboard](https://dashboard.plaid.com/team/keys) to get your API credentials
21+
2. Your Client ID and Secret Key are required to enable Plaid bank sync for European banks
22+
3. For production use, set environment to 'production', for testing use 'sandbox'
23+
DESC
24+
25+
field :client_id,
26+
label: "Client ID",
27+
required: false,
28+
env_key: "PLAID_EU_CLIENT_ID",
29+
description: "Your Plaid Client ID from the Plaid Dashboard for EU region"
30+
31+
field :secret,
32+
label: "Secret Key",
33+
required: false,
34+
secret: true,
35+
env_key: "PLAID_EU_SECRET",
36+
description: "Your Plaid Secret from the Plaid Dashboard for EU region"
37+
38+
field :environment,
39+
label: "Environment",
40+
required: false,
41+
env_key: "PLAID_EU_ENV",
42+
default: "sandbox",
43+
description: "Plaid environment: sandbox, development, or production"
44+
end
45+
46+
# Reload Plaid EU configuration when settings are updated
47+
def self.reload_configuration
48+
client_id = config_value(:client_id).presence || ENV["PLAID_EU_CLIENT_ID"]
49+
secret = config_value(:secret).presence || ENV["PLAID_EU_SECRET"]
50+
environment = config_value(:environment).presence || ENV["PLAID_EU_ENV"] || "sandbox"
51+
52+
if client_id.present? && secret.present?
53+
Rails.application.config.plaid_eu = Plaid::Configuration.new
54+
Rails.application.config.plaid_eu.server_index = Plaid::Configuration::Environment[environment]
55+
Rails.application.config.plaid_eu.api_key["PLAID-CLIENT-ID"] = client_id
56+
Rails.application.config.plaid_eu.api_key["PLAID-SECRET"] = secret
57+
else
58+
Rails.application.config.plaid_eu = nil
59+
end
60+
end
61+
end

config/initializers/plaid.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
Rails.application.configure do
2+
# Initialize Plaid configuration to nil
23
config.plaid = nil
34
config.plaid_eu = nil
5+
end
46

5-
if ENV["PLAID_CLIENT_ID"].present? && ENV["PLAID_SECRET"].present?
6-
config.plaid = Plaid::Configuration.new
7-
config.plaid.server_index = Plaid::Configuration::Environment[ENV["PLAID_ENV"] || "sandbox"]
8-
config.plaid.api_key["PLAID-CLIENT-ID"] = ENV["PLAID_CLIENT_ID"]
9-
config.plaid.api_key["PLAID-SECRET"] = ENV["PLAID_SECRET"]
10-
end
7+
# Load Plaid configuration from adapters after initialization
8+
Rails.application.config.after_initialize do
9+
# Ensure provider adapters are loaded
10+
Provider::Factory.ensure_adapters_loaded
1111

12-
if ENV["PLAID_EU_CLIENT_ID"].present? && ENV["PLAID_EU_SECRET"].present?
13-
config.plaid_eu = Plaid::Configuration.new
14-
config.plaid_eu.server_index = Plaid::Configuration::Environment[ENV["PLAID_ENV"] || "sandbox"]
15-
config.plaid_eu.api_key["PLAID-CLIENT-ID"] = ENV["PLAID_EU_CLIENT_ID"]
16-
config.plaid_eu.api_key["PLAID-SECRET"] = ENV["PLAID_EU_SECRET"]
17-
end
12+
# Reload configurations from settings/ENV
13+
Provider::PlaidAdapter.reload_configuration # US region
14+
Provider::PlaidEuAdapter.reload_configuration # EU region
1815
end

0 commit comments

Comments
 (0)