getConfiguration method

Future<QuickbooksConnectConfiguration> getConfiguration({
  1. bool? isProduction,
})

Gets the Oauth configuration from Quickbooks.

isProduction Specifies if the config you want is in production or in sandbox. This will define the base endpoint url used by the service. If not given, takes the environement value QUICKBOOKS_IS_PRODUCTION or is true by default.

Implementation

Future<QuickbooksConnectConfiguration> getConfiguration(
    {bool? isProduction}) async {
  isProduction ??= QuickbooksEnvironment.isProduction;

  String uri = !isProduction ? _sandboxLink : _productionLink;

  try {
    return await http.get(
        Uri.parse(
          uri,
        ),
        headers: {
          'content-type': 'application/json',
        }).then((response) async {
      switch (response.statusCode) {
        case 200:
          var body = jsonDecode(response.body) as Map<String, dynamic>;
          var newConfig = QuickbooksConnectConfiguration.fromMap(body);
          return newConfig;
        default:
          throw StateError(
              'Failed to get configuration, error: ${response.body}');
      }
    });
  } catch (e) {
    rethrow;
  }
}