save method
Persist invoice to the server
Implementation
Future<RecurringInvoice> save(
RecurringInvoice invoice, {
RecurringInvoiceAction? action,
}) async {
dynamic response;
String url;
if (invoice.id.isEmpty) {
url = '${InvoiceNinjaAdmin.url}/api/v1/recurring_invoices';
} else {
url = '${InvoiceNinjaAdmin.url}/api/v1/recurring_invoices/${invoice.id}';
}
if (action == RecurringInvoiceAction.sendNow) {
url += '?send_now=true';
} else if (action == RecurringInvoiceAction.start) {
url += '?start=true';
} else if (action == RecurringInvoiceAction.stop) {
url += '?stop=true';
}
if (invoice.id.isEmpty) {
response = await WebClient()
.post(url, token: InvoiceNinjaAdmin.token, data: invoice.toJson());
} else {
response = await WebClient()
.put(url, token: InvoiceNinjaAdmin.token, data: invoice.toJson());
}
return RecurringInvoiceItem.fromJson(response).data;
}