init method

Future<void> init()

Call this function before using Enzona APIs

Implementation

Future<void> init() async {
  if(isInitialized) return;

  /// Oauth2 httpClient does token refresh automatically, but due to the lack
  /// of a proper refresh token implementation from Enzona API the token refresh
  /// should be done as new clientCredentialsGrant.
  /// CustomOauth2Client is a wrapper that does exactly the same as official
  /// Oauth2 Client but in addition it ensures token refresh by doing a
  /// clientCredentialsGrant.

  http.Client? baseClient;
  if(!PlatformUtils.isWeb) {
    baseClient = IOClient(httpClient);
  }
  oauth2Client = CustomOauth2Client.fromOauth2Client(
    await oauth2.clientCredentialsGrant(
      Uri.parse(accessTokenUrl),
      consumerKey,
      consumerSecret,
      scopes: scopes,
      httpClient: baseClient,
    ),
    httpClient: baseClient,
  );

  // oauth2Client = CustomOauth2Client(
  //   oauth2.Credentials(
  //     '1c50c1ef-a6e4-3cb2-9be0-b227b04e88b9',
  //     scopes: scopes,
  //   ),
  //   identifier: consumerKey,
  //   secret: consumerSecret,
  //   httpClient: baseClient,
  // );

  restAPI.init(
    baseClient: oauth2Client,
    httpClient: httpClient,
    apiUrl: apiUrl,
    timeout: timeout,
  );

  paymentAPI = PaymentAPIChopper();
  _initialized = true;
}