fetchDataFromApi function
Implementation
Future<DataResponseCheckout> fetchDataFromApi(
String transactionId, String referrerId,
{context}) async {
final bool? isProduction = B24PaymentSdk.storeIsProduction;
final url =
isProduction == false ? envDemo().UrlCheckout : envPro().UrlCheckout;
final Map<String, dynamic> data = {
'tran_id': transactionId,
};
final Map<String, String> headers = {
'token': envDemo().token,
'Content-Type': 'application/json',
'X-Referrer-Key': referrerId,
};
try {
final response = await http.post(Uri.parse(url),
body: jsonEncode(data), headers: headers);
if (response.statusCode == 200) {
final jsonData = json.decode(response.body);
errorCode = jsonData['code'];
Message = jsonData['message'];
MessageKh = jsonData['message_kh'];
cachedData = DataResponseCheckout.fromJson(jsonData);
return cachedData;
} else {
throw Exception('Failed to load data from API');
}
} catch (ex) {
throw Exception('Failed to load data from API ${ex.toString()}');
}
}