initialise method

Future<void> initialise({
  1. String? merchantApiUrl,
})

Initializes the service with the IAM service URL from configuration. merchantApiUrl is the base URL for the merchant API (used for OTP endpoints). If not provided, it is read from the config_merchant_api_url config key.

Implementation

Future<void> initialise({String? merchantApiUrl}) async {
  if (_isInitialized) {
    logger.info(this, 'PinService is already initialised.');
    return;
  }

  ConfigService configService = core.get<ConfigService>();

  _iamServiceUrl = configService.getStringValue(
    key: 'config_iam_service_url',
    defaultValue: '',
  );

  _merchantApiUrl = merchantApiUrl ??
      configService.getStringValue(
        key: 'config_merchant_api_url',
        defaultValue: '',
      );

  defaultPinLength = configService.getIntValue(
    key: 'config_iam_service_pin_length',
    defaultValue: 4,
  );

  if (_iamServiceUrl.isEmpty) {
    logger.error(
      this,
      'IAM Service URL is not configured. PIN operations will be unavailable.',
    );
  }

  if (_merchantApiUrl.isEmpty) {
    logger.error(
      this,
      'Merchant API URL is not configured. OTP PIN reset will be unavailable.',
    );
  }

  _isInitialized = true;
  logger.info(this, 'PinService initialized.');
}