Class: ComplyanceSDK::Models::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/complyance_sdk/models/country.rb

Overview

Country enumeration for supported countries

Constant Summary collapse

SA =

Supported countries

:sa
MY =

Saudi Arabia

:my
AE =

Malaysia

:ae
SG =

United Arab Emirates

:sg
EG =

Singapore

:eg
IN =

Egypt

:in
PH =

India

:ph
TH =

Philippines

:th
VN =

Thailand

:vn
ID =

Vietnam

:id
BD =

Indonesia

:bd
LK =

Bangladesh

:lk
PK =

Sri Lanka

:pk
NP =

Pakistan

:np
MM =

Nepal

:mm
KH =

Myanmar

:kh
LA =

Cambodia

:la
BN =

Laos

:bn
MV =

Brunei

:mv
BT =

Maldives

:bt
ALL_COUNTRIES =

All supported countries

[
  SA, MY, AE, SG, EG, IN, PH, TH, VN, ID,
  BD, LK, PK, NP, MM, KH, LA, BN, MV, BT
].freeze

Class Method Summary collapse

Class Method Details

.allowed_for_environment?(country, environment) ⇒ Boolean

Check if country is allowed for production environments Based on the Java SDK’s validation rules Implements the three-tier country access control:

  • SA: Allowed in all production environments (SANDBOX, SIMULATION, PRODUCTION)

  • MY: Allowed in SANDBOX and PRODUCTION only (blocked in SIMULATION)

  • AE: Allowed in SANDBOX and PRODUCTION only (blocked in SIMULATION)

  • Others: Blocked in all production environments

Parameters:

  • country (Symbol)

    The country

  • environment (Symbol)

    The environment

Returns:

  • (Boolean)

    True if allowed



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/complyance_sdk/models/country.rb', line 162

def allowed_for_environment?(country, environment)
  case environment
  when :dev, :test, :stage, :local
    # Development environments allow all countries
    true
  when :sandbox, :simulation, :production
    # Production environments have restrictions
    case country
    when SA
      # SA is allowed in all production environments
      true
    when MY, AE
      # MY and AE are allowed in SANDBOX and PRODUCTION only (not SIMULATION)
      environment != :simulation
    else
      # Other countries are blocked in production environments
      false
    end
  else
    # Unknown environment, default to allowing
    true
  end
end

.default_tax_authority(country) ⇒ String?

Get the default tax authority for a country

Parameters:

  • country (Symbol)

    The country

Returns:

  • (String, nil)

    The tax authority name or nil if not mapped



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/complyance_sdk/models/country.rb', line 73

def default_tax_authority(country)
  case country
  when SA
    'ZATCA'
  when MY
    'LHDN'
  when AE
    'FTA'
  when SG
    'IRAS'
  when EG
    'ETA'
  when IN
    'GSTN'
  when PH
    'BIR'
  when TH
    'RD'
  when VN
    'GDT'
  when ID
    'DJP'
  else
    nil
  end
end

.from_string(str) ⇒ Symbol

Parse a string to a country symbol

Parameters:

  • str (String)

    The string to parse

Returns:

  • (Symbol)

    The country symbol

Raises:

  • (ArgumentError)

    If the string is invalid



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/complyance_sdk/models/country.rb', line 49

def from_string(str)
  return str if str.is_a?(Symbol)
  
  country = str.to_s.downcase.to_sym
  
  unless valid?(country)
    raise ArgumentError, "Invalid country: #{str}. Valid countries: #{ALL_COUNTRIES.join(', ')}"
  end
  
  country
end

.full_name(country) ⇒ String

Get the full country name

Parameters:

  • country (Symbol)

    The country code

Returns:

  • (String)

    The full country name



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/complyance_sdk/models/country.rb', line 104

def full_name(country)
  case country
  when SA
    'Saudi Arabia'
  when MY
    'Malaysia'
  when AE
    'United Arab Emirates'
  when SG
    'Singapore'
  when EG
    'Egypt'
  when IN
    'India'
  when PH
    'Philippines'
  when TH
    'Thailand'
  when VN
    'Vietnam'
  when ID
    'Indonesia'
  when BD
    'Bangladesh'
  when LK
    'Sri Lanka'
  when PK
    'Pakistan'
  when NP
    'Nepal'
  when MM
    'Myanmar'
  when KH
    'Cambodia'
  when LA
    'Laos'
  when BN
    'Brunei'
  when MV
    'Maldives'
  when BT
    'Bhutan'
  else
    country.to_s.upcase
  end
end

.to_string(country) ⇒ String

Convert a country to string format

Parameters:

  • country (Symbol)

    The country

Returns:

  • (String)

    The string representation



65
66
67
# File 'lib/complyance_sdk/models/country.rb', line 65

def to_string(country)
  country.to_s.upcase
end

.valid?(country) ⇒ Boolean

Check if a country is valid

Parameters:

  • country (Symbol)

    The country code to validate

Returns:

  • (Boolean)

    True if valid, false otherwise



40
41
42
# File 'lib/complyance_sdk/models/country.rb', line 40

def valid?(country)
  ALL_COUNTRIES.include?(country)
end

.validation_error_message(country, environment) ⇒ String?

Get validation error message for country/environment combination

Parameters:

  • country (Symbol)

    The country

  • environment (Symbol)

    The environment

Returns:

  • (String, nil)

    Error message or nil if allowed



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/complyance_sdk/models/country.rb', line 191

def validation_error_message(country, environment)
  return nil if allowed_for_environment?(country, environment)

  case environment
  when :simulation
    case country
    when MY
      "MY (Malaysia) is not allowed in SIMULATION environment. Use SANDBOX or PRODUCTION."
    when AE
      "AE (UAE) is not allowed in SIMULATION environment. Use SANDBOX or PRODUCTION."
    else
      "Only SA, MY, and AE are allowed for #{environment.to_s.upcase}. Use DEV/TEST/STAGE for other countries."
    end
  when :sandbox, :production
    "Only SA, MY, and AE are allowed for #{environment.to_s.upcase}. Use DEV/TEST/STAGE for other countries."
  else
    "Country #{country.to_s.upcase} is not allowed for environment #{environment.to_s.upcase}."
  end
end