startCheckoutRouter method

Future<StartCheckoutResponse> startCheckoutRouter(
  1. StartCheckoutRequest routerData
)

Implementation

Future<StartCheckoutResponse> startCheckoutRouter(StartCheckoutRequest routerData) async {
  try {
    _client = MyHttpClient(baseUrlTonder);
    Response? response = await _client?.post(
        Uri.parse('api/v1/checkout-router/'),
        body: json.encode(routerData.toMap()),
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Token $apiKeyTonder'
        }
    );

    if (response!.statusCode >= 200 ||response.statusCode < 300) {
      final jsonResponse = json.decode(response.body) as Map<String, dynamic>;
      List<Actions> actions = [];
      for (var i = 0; i <jsonResponse['actions']!.length; i++) {
        actions.add(Actions.fromJson(jsonResponse['actions'][i]));
      }
      jsonResponse['actions'] = actions;
      return StartCheckoutResponse.fromJson(jsonResponse);
    } else {
      throw Exception(response.statusCode);
    }
  } catch (e) {
    throw Exception(e);
  }
}