voidPayment method

Future<Payment> voidPayment({
  1. required Payment payment,
  2. String? realmId,
  3. String? authToken,
})

Use a sparse update operation with include=void to void an existing Payment object; include a minimum of Payment.Id and Payment.SyncToken.The transaction remains active but all amounts and quantities are zeroed and the string, Voided, is injected into Payment.PrivateNote, prepended to existing text if present. If funds for the payment have been deposited, you must delete the associated deposit object before voiding the payment object.

Implementation

Future<Payment> voidPayment({
  required Payment payment,
  String? realmId,
  String? authToken,
}) async {

  authToken ??= authenticationService.getCachedToken()?.access_token;
  realmId ??= authenticationService.getCachedRealmId();

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

  };

  Map<String, String> params = {
    "minorversion": minorVersion.toString(),
    "operation": "void"
  };

  Uri endpoint = Uri.https(
      baseUrl, "/v3/company/$realmId/payment", params);

  //print (endpoint.toString());

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

  if (response.statusCode == 200) {
    //print (jsonDecode(response.body));
    return Payment.fromJson(jsonDecode(response.body)["Payment"]);
  }
  else {
    throw PaymentException(statusCode: response.statusCode, message: response.body);
  }
}