fetchSdkConfig method
Fetch SDK configuration from backend
Returns configuration including enableManualCapture, companyName, and companyLogoUrl
Implementation
Future<Map<String, dynamic>> fetchSdkConfig() async {
try {
final response = await _apiClient.get('/sdk/kyc-verification/config');
final jsonData = json.decode(response.body) as Map<String, dynamic>;
final rawLogoUrl = jsonData['companyLogoUrl'] as String?;
// Normalize logo URL:
// - If backend returns a relative path (e.g. /sdk/kyc-verification/logo/proxy?...),
// prefix it with the configured baseUrl.
// - If backend returns absolute URL, keep it as-is.
String? normalizedLogoUrl = rawLogoUrl;
if (rawLogoUrl != null &&
rawLogoUrl.isNotEmpty &&
rawLogoUrl.startsWith('/')) {
normalizedLogoUrl = '${ApexKycConfig.instance.baseUrl}$rawLogoUrl';
}
// Update config with fetched values
ApexKycConfig.updateFromBackend(
enableManualCapture: jsonData['enableManualCapture'] as bool?,
companyName: jsonData['companyName'] as String?,
companyLogoUrl: normalizedLogoUrl,
);
return jsonData;
} catch (e) {
if (e is ApexKycException) {
rethrow;
}
throw ApexKycException(
'Failed to fetch SDK config: ${e.toString()}',
originalError: e,
);
}
}