I'm working on an application that accepts various payment methods via different payment providers.
One of the payment methods is Mobile Money. Mobile Money is accepted in a number of different countries and I have a settings table that holds the different mobile networks and currencies for each country.
All countries only accept one currency but can have different mobile networks.
For example, Ireland could have two different mobile networks and one currency.
My database structure is as follows:
payment_methods
| id | name |
|---|---|
| 1 | Mobile Money |
countries
| id | name | iso_code |
|---|---|---|
| 1 | Ireland | IE |
| 2 | UK | UK |
country_payment_method
| id | country_id | payment_method_id | is_active |
|---|---|---|---|
| 1 | 1 | 1 | true |
| 2 | 2 | 1 | true |
mobile_networks
| id | name |
|---|---|
| 1 | Eir |
| 2 | Three |
| 3 | 02 |
currencies
| id | name | code |
|---|---|---|
| 1 | Euro | EUR |
| 2 | Pound | GBP |
payment_method_configurations
| id | country_payment_method_id | config_key | config_value |
|---|---|---|---|
| 1 | 1 | mobile_network_id | 1 |
| 2 | 1 | mobile_network_id | 2 |
| 3 | 1 | currency_id | 1 |
| 4 | 2 | mobile_network_id | 2 |
| 5 | 2 | mobile_network_id | 3 |
| 6 | 2 | currency_id | 2 |
My question is, how do I access the configurations for a country/payment_method using either Eloquent relationship or DB query if I know the country?