cancelInvoice method
Cancel invoice from Paylink.
transactionNo - The transaction number of the invoice to cancel.
Returns boolean
Implementation
Future<void> cancelInvoice({String? transactionNo}) async {
try {
if (transactionNo == null) {
throw ArgumentError('Transaction number cannot be null.');
}
if (paymentToken == null) await _authenticate();
/// Request body parameters
Map<String, dynamic> requestBody = {
'transactionNo': transactionNo,
};
final response = await http.post(
Uri.parse('$apiLink/api/cancelInvoice'),
headers: {
'accept': '*/*',
'content-type': 'application/json',
'Authorization': 'Bearer $paymentToken',
},
body: jsonEncode(requestBody),
);
if (response.statusCode != 200) {
throw Exception('Failed to cancel the invoice: ${response.body}');
}
Map<String, dynamic> responseBody = json.decode(response.body);
if (responseBody.isEmpty || responseBody['success'] != 'true') {
throw Exception('Failed to cancel the invoice: ${response.body}');
}
} catch (e) {
rethrow;
}
}