getCommerceInfo method
Implementation
Future<void> getCommerceInfo(GetCommerceInfo getCommerceInfo) async {
getCommerceInfo.onLoading();
final url = Uri.parse(
'https://api.plentrasphere.com/v2/client/?class=default&action=getCommerceInfo&appKey=$appKey');
try {
final response = await http.get(url);
if (response.statusCode == 200) {
final jsonData = json.decode(response.body);
final code = jsonData['response']['code'];
final status = jsonData['response']['status'];
final info = jsonData['info'];
if (code == 400) {
if (status == "app-expired") {
getCommerceInfo.onAppNotActive(info['appName']);
getCommerceInfo.onLoadfinished();
return;
}
getCommerceInfo.onError(status);
getCommerceInfo.onLoadfinished();
return;
}
if (info['homeCover']['status']) {
getCommerceInfo.onHomeCover(info['homeCover']['image']);
}
if (info['firebase']['status'] == true) {
getCommerceInfo.onfirebaseAuth(jsonEncode(info['firebase']));
}
if (info.containsKey('paymentGatewayKey') &&
info.containsKey('paymentGatewayType') &&
info.containsKey('paymentGatewayName')) {
getCommerceInfo.onPaymentGateway(info['paymentGatewayName'],
info['paymentGatewayType'], info['paymentGatewayKey']);
}
getCommerceInfo.onResult(
info['appName'],
info['appIcon'],
info['appType'],
info['appLocation'], // Pass the appLocation map directly
);
getCommerceInfo.onLoadfinished();
} else {
getCommerceInfo.onError('HTTP ${response.statusCode}');
getCommerceInfo.onLoadfinished();
}
} catch (e) {
getCommerceInfo.onError(e.toString());
getCommerceInfo.onLoadfinished();
}
}