save method

Future<Payment> save(
  1. Payment payment, {
  2. PaymentAction? action,
})

Persist payment to the server

Implementation

Future<Payment> save(Payment payment, {PaymentAction? action}) async {
  dynamic response;
  String url;

  if (payment.id.isEmpty) {
    url = '${InvoiceNinjaAdmin.url}/api/v1/payments';
  } else {
    url = '${InvoiceNinjaAdmin.url}/api/v1/payments/${payment.id}';
  }

  if (action == PaymentAction.sendEmail) {
    url += '?email_receipt=true';
  }

  if (payment.id.isEmpty) {
    response = await WebClient()
        .post(url, token: InvoiceNinjaAdmin.token, data: payment.toJson());
  } else {
    response = await WebClient()
        .put(url, token: InvoiceNinjaAdmin.token, data: payment.toJson());
  }

  return PaymentItem.fromJson(response).data;
}