createOrder method

Future<PaymentOptionModel> createOrder(
  1. CreateOrderBody? body, {
  2. String? orderCreationUrl,
})

Implementation

Future<PaymentOptionModel> createOrder(CreateOrderBody? body,
    {String? orderCreationUrl}) async {
  final url = orderCreationUrl ?? DEFAULT_ORDER_CREATION_URL;
  final response = await httpClient.post(Uri.parse(url),
      body: createOrderBodyToJson(
          body!,
          environment
              .toString()
              .substring(environment.toString().indexOf('.') + 1)),
      headers: {"Content-Type": "application/json"});

  if (response.statusCode != 200) {
    throw Exception('error creating order');
  }

  final json = jsonDecode(response.body);
  if (kDebugMode) {
    print(json);
  }
  var model = CreatedOrderModel.fromJson(json);
  return await fetchOrder(model.orderId);
}