cloneOrder method

Future<Order> cloneOrder({
  1. required CloneOrderRequest request,
  2. String? authToken,
})

Creates a new order, in the DRAFT state, by duplicating an existing order.

The newly created order has only the core fields (such as line items, taxes, and discounts) copied from the original order.

Implementation

Future<Order> cloneOrder({
  required CloneOrderRequest request,
  String? authToken,
}) async {

  authToken ??= authenticationService.getCachedToken()?.accessToken;

  Map<String, String> headers = {
    "Authorization": "Bearer ${authToken ?? ""}",
    'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',

  };

  Uri endpoint = Uri.https(
      baseUrl, "/v2/orders/clone");

  //print (endpoint.toString());

  var response = await
  http.post(endpoint, body: jsonEncode(request.toJson()), headers: headers);

  if (response.statusCode == 200) {
    print (jsonDecode(response.body));
    return OrderResponse.fromJson(jsonDecode(response.body)).order!;
  }
  else {
    print (response.body);
    throw OrderException(statusCode: response.statusCode, message: TerminalCheckoutResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
  }
}