deleteInvoice method
Deletes the specified invoice.
When an invoice is deleted, the associated order status changes to CANCELED. You can only delete a draft invoice (you cannot delete a published invoice, including one that is scheduled for processing).
Implementation
Future<bool> deleteInvoice({
required int invoiceId,
required int version,
String? authToken,
}) async {
authToken ??= authenticationService.getCachedToken()?.accessToken;
Map<String, String> headers = {
"Authorization": "Bearer ${authToken ?? ""}",
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
};
var params = {
"version": version
};
Uri endpoint = Uri.https(
baseUrl, "/v2/invoices/$invoiceId", params);
//print (endpoint.toString());
var response = await
http.delete(endpoint, headers: headers);
if (response.statusCode == 200) {
print (jsonDecode(response.body));
//return InvoiceResponse.fromJson(jsonDecode(response.body)).invoice!;
return true;
}
else {
print (response.body);
throw InvoiceException(statusCode: response.statusCode, message: InvoiceResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
}
}