save method
Persist credit to the server
Implementation
Future<Credit> save(Credit credit, {CreditAction? action}) async {
dynamic response;
String url;
if (credit.id.isEmpty) {
url = '${InvoiceNinjaAdmin.url}/api/v1/credits';
} else {
url = '${InvoiceNinjaAdmin.url}/api/v1/credits/${credit.id}';
}
if (action == CreditAction.markSent) {
url += '?mark_sent=true';
} else if (action == CreditAction.sendEmail) {
url += '?send_email=true';
}
if (credit.id.isEmpty) {
response = await WebClient()
.post(url, token: InvoiceNinjaAdmin.token, data: credit.toJson());
} else {
response = await WebClient()
.put(url, token: InvoiceNinjaAdmin.token, data: credit.toJson());
}
return CreditItem.fromJson(response).data;
}