CountryProvider
In this page you can understand the structure and logics behind the CountryProvider model.
Its purpose is to store credential for external providers, for different type, for many countries. The idea is to prevent using ENV variables for it.
Available fields
country_id: reference to linked Countryprovider_name: this string stores the external provider's name (e.g.: customerio, messagebird, stripe, etc.)provider_type: the type string defines the purpose of this provider (e.g.: email, sms, online_payment, etc.)client_idandclient_key: these two are used to store provider's access data (id, access_token, etc.)client_url: URL to be used to communicate with external provideradditional_data: a JSONB field that can store more information about the provider (many of them exposed withstore_accessor), such as webhook endpoint, provider's configuration, additional filters for provider's type, etc.
Loading the provider
CountryProvider can be used in multiple occasions, but most of the time they're used in services linked to the provider_type. Services that use them define a *_module.rb that contains the logic to load the provider:
Notifications
:::code source="../../uala-main/app/services/notifications/notification_module.rb" title="uala-main/app/services/notifications/notification_module.rb" range="27-55" :::
Payments
:::code source="../../uala-main/app/services/payments/payment_module.rb" title="uala-main/app/services/payments/payment_module.rb" range="5-44" :::
Adding a new provider
Other that business logic to make use of it, it's needed to allow this provider to be valid in terms of provider_type and provider_name, in uala-main/app/models/country_providers/validations.rb.