initializeSdk method
Initializes the SDK with the provided publishable key and client secret provider.
publishableKey is the key used to authenticate with the Ansa API.
clientSecretProvider is a function that provides the client secret for a given customer ID.
Implementation
@override
Future<void> initializeSdk({
required String publishableKey,
required Future<String?> Function(String customerId) clientSecretProvider,
}) async {
try {
// Set up the client secret provider
secretProviderChannel.setMethodCallHandler((call) async {
if (call.method == 'getClientSecret') {
final customerId = call.arguments['ansaCustomerId'] as String?;
if (customerId == null) {
throw PlatformException(
code: 'INVALID_ARGUMENTS', message: 'Missing customerId');
}
return await clientSecretProvider(customerId);
}
throw PlatformException(
code: 'NOT_IMPLEMENTED', message: 'Method not implemented');
});
// Initialize the SDK on the native side
await methodChannel.invokeMethod('initializeSdk', {
'publishableKey': publishableKey,
});
} on PlatformException {
rethrow;
}
}