|
| 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 |
0 commit comments