fetchTransaction method

Future<Map<String, dynamic>> fetchTransaction(
  1. String orderNumber
)

Fetches transaction details.

Implementation

Future<Map<String, dynamic>> fetchTransaction(String orderNumber) async {
  try {
    final response = await http.post(
      Uri.parse('https://edrahmi.efawtara.com/api/fetch/transaction'),
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'x-app-key': appKey,
        'x-secret-key': secretKey,
      },
      body: jsonEncode({'order_number': orderNumber}),
    );

    if (response.statusCode != 200) {
      throw Exception("Transaction fetch failed: ${response.statusCode}");
    }

    return jsonDecode(response.body);
  } catch (e) {
    debugPrint("Error fetching transaction: $e");
    return {}; // Return empty map on failure
  }
}