fetchInstantPaymentMethods function
Implementation
Future<ApiBaseResponse<DInstantPaymentMethod>> fetchInstantPaymentMethods(
String customerSyncCode, String refererKey) async {
// final url =
// isProduction == false ? envDemo().UrlCheckout : envPro().UrlCheckout;
// final url =
// "https://merchantapi-staging.bill24.io/instantpaymentsdk/instant_payment_methods";
final url = BaseUrl.baseUrl! + api().instantPaymentMethod;
final Map<String, dynamic> body = {
'customer_sync_code': customerSyncCode,
'filter_by_status': ''
};
final Map<String, String> headers = {
'token': envDemo().token,
'Content-Type': 'application/json',
'X-Referrer-Key': refererKey,
};
try {
final jsonData = await http.post(
Uri.parse(url),
body: jsonEncode(body),
headers: headers,
);
if (jsonData.statusCode == 200) {
final Map<String, dynamic> decodedJson = jsonDecode(jsonData.body);
final response = ApiBaseResponse<DInstantPaymentMethod>.fromJson(
decodedJson,
(dataJson) => DInstantPaymentMethod.fromJson(dataJson),
);
return response;
} else {
throw Exception('Failed to load data from API');
}
} catch (ex) {
throw Exception('Failed to load data from API ${ex.toString()}');
}
}