getInvoice method
Retrieves invoice details
Implementation
Future<PaylinkInvoice> getInvoice(String transactionNo) async {
try {
if (idToken == null) await _authenticate();
final response = await http.get(
Uri.parse('$apiBaseUrl/api/getInvoice/$transactionNo'),
headers: {
'accept': '*/*',
'content-type': 'application/json',
'Authorization': 'Bearer $idToken',
},
);
if (response.statusCode != 200) {
_handleResponseError(response, 'Failed to get the invoice');
}
if (response.body.isEmpty) {
throw Exception('Order details missing from the response');
}
/// Decode the JSON response and extract the order details
final orderDetails = json.decode(response.body);
if (orderDetails is! Map<String, dynamic>) {
throw Exception('Order details missing from the response');
}
return PaylinkInvoice.fromResponseData(orderDetails);
} catch (e) {
rethrow;
}
}