|
|
|
|
@ -15,7 +15,8 @@ import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_retailer
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/location/Location.dart' as location;
|
|
|
|
|
|
|
|
|
|
class OffersAndDiscountsApiClient {
|
|
|
|
|
static final OffersAndDiscountsApiClient _instance = OffersAndDiscountsApiClient._internal();
|
|
|
|
|
static final OffersAndDiscountsApiClient _instance =
|
|
|
|
|
OffersAndDiscountsApiClient._internal();
|
|
|
|
|
static List<WalaPlusCategoryModel>? cachedCategories;
|
|
|
|
|
|
|
|
|
|
OffersAndDiscountsApiClient._internal();
|
|
|
|
|
@ -26,7 +27,12 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
List<GetCategoriesList> getSaleCategoriesList = [];
|
|
|
|
|
|
|
|
|
|
String url = "${ApiConsts.cocRest}Mohemm_ITG_GetCategories";
|
|
|
|
|
Map<String, dynamic> postParams = {"EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER, "ItgPageSize": 100, "ItgPageNo": 1, "ItgIsActive": true};
|
|
|
|
|
Map<String, dynamic> postParams = {
|
|
|
|
|
"EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER,
|
|
|
|
|
"ItgPageSize": 100,
|
|
|
|
|
"ItgPageNo": 1,
|
|
|
|
|
"ItgIsActive": true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
|
@ -53,11 +59,19 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<List<OffersListModel>> getOffersList(int categoryID, int pageSize) async {
|
|
|
|
|
Future<List<OffersListModel>> getOffersList(
|
|
|
|
|
int categoryID,
|
|
|
|
|
int pageSize,
|
|
|
|
|
) async {
|
|
|
|
|
List<OffersListModel> getSaleCategoriesList = [];
|
|
|
|
|
|
|
|
|
|
String url = "${ApiConsts.cocRest}GetOfferDiscountsConfigData";
|
|
|
|
|
Map<String, dynamic> postParams = {"EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER, "ItgPageSize": pageSize, "ItgPageNo": 1, "ItgCategoryID": categoryID};
|
|
|
|
|
Map<String, dynamic> postParams = {
|
|
|
|
|
"EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER,
|
|
|
|
|
"ItgPageSize": pageSize,
|
|
|
|
|
"ItgPageNo": 1,
|
|
|
|
|
"ItgCategoryID": categoryID,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
|
@ -81,7 +95,10 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
String _resolveUserName() {
|
|
|
|
|
String? pUserName = AppState().getUserName;
|
|
|
|
|
if (pUserName == null || pUserName.isEmpty) {
|
|
|
|
|
pUserName = AppState().postParamsObject?.userName ?? AppState().postParamsObject?.pUserName ?? AppState().memberInformationList?.eMPLOYEENUMBER;
|
|
|
|
|
pUserName =
|
|
|
|
|
AppState().postParamsObject?.userName ??
|
|
|
|
|
AppState().postParamsObject?.pUserName ??
|
|
|
|
|
AppState().memberInformationList?.eMPLOYEENUMBER;
|
|
|
|
|
}
|
|
|
|
|
return pUserName ?? "";
|
|
|
|
|
}
|
|
|
|
|
@ -97,12 +114,15 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
if (!enabledCompleter.isCompleted) enabledCompleter.complete(isEnabled);
|
|
|
|
|
});
|
|
|
|
|
bool isEnabled = await enabledCompleter.future;
|
|
|
|
|
debugPrint("_getCurrentPositionSilently: location service isEnabled=$isEnabled");
|
|
|
|
|
debugPrint(
|
|
|
|
|
"_getCurrentPositionSilently: location service isEnabled=$isEnabled",
|
|
|
|
|
);
|
|
|
|
|
if (!isEnabled) return null;
|
|
|
|
|
|
|
|
|
|
Completer<bool> permissionCompleter = Completer<bool>();
|
|
|
|
|
location.Location.havePermission((bool hasPermission) {
|
|
|
|
|
if (!permissionCompleter.isCompleted) permissionCompleter.complete(hasPermission);
|
|
|
|
|
if (!permissionCompleter.isCompleted)
|
|
|
|
|
permissionCompleter.complete(hasPermission);
|
|
|
|
|
});
|
|
|
|
|
bool hasPermission = await permissionCompleter.future;
|
|
|
|
|
debugPrint("_getCurrentPositionSilently: havePermission=$hasPermission");
|
|
|
|
|
@ -111,11 +131,16 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
Completer<Position?> positionCompleter = Completer<Position?>();
|
|
|
|
|
location.Location.getCurrentLocation(
|
|
|
|
|
(Position position, bool isMocked) {
|
|
|
|
|
debugPrint("_getCurrentPositionSilently: got position lat=${position.latitude}, lng=${position.longitude}, isMocked=$isMocked");
|
|
|
|
|
if (!positionCompleter.isCompleted) positionCompleter.complete(position);
|
|
|
|
|
debugPrint(
|
|
|
|
|
"_getCurrentPositionSilently: got position lat=${position.latitude}, lng=${position.longitude}, isMocked=$isMocked",
|
|
|
|
|
);
|
|
|
|
|
if (!positionCompleter.isCompleted)
|
|
|
|
|
positionCompleter.complete(position);
|
|
|
|
|
},
|
|
|
|
|
() {
|
|
|
|
|
debugPrint("_getCurrentPositionSilently: getCurrentLocation error callback fired");
|
|
|
|
|
debugPrint(
|
|
|
|
|
"_getCurrentPositionSilently: getCurrentLocation error callback fired",
|
|
|
|
|
);
|
|
|
|
|
if (!positionCompleter.isCompleted) positionCompleter.complete(null);
|
|
|
|
|
},
|
|
|
|
|
context,
|
|
|
|
|
@ -134,6 +159,19 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
if (overrideMobile != null && overrideMobile.trim().isNotEmpty) {
|
|
|
|
|
return overrideMobile.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// postParamsObject.mobileNumber/memberInformationList/memberLoginList are only ever set by
|
|
|
|
|
// the employee login flow and never cleared on logout - for a dependent session, the only
|
|
|
|
|
// legitimate source is the sponsor's mobile captured at dependent login (walaplusDepInfoModel),
|
|
|
|
|
// same reasoning as _resolveUserReference above.
|
|
|
|
|
if (ApiConsts.isDependetLogin) {
|
|
|
|
|
String? depMobile = AppState().walaplusDepInfoModel?.pEmpMobileNumber;
|
|
|
|
|
if (depMobile != null && depMobile.trim().isNotEmpty) {
|
|
|
|
|
return depMobile.trim();
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String? mobile = AppState().postParamsObject?.mobileNumber;
|
|
|
|
|
if (mobile != null && mobile.trim().isNotEmpty) {
|
|
|
|
|
return mobile.trim();
|
|
|
|
|
@ -161,7 +199,9 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
Map<String, dynamic> base = {};
|
|
|
|
|
base.addAll(AppState().postParamsJson);
|
|
|
|
|
if (ApiConsts.isDependetLogin) {
|
|
|
|
|
String? token = AppState().postParamsObject?.tokenID ?? AppState().authenticationTokenID;
|
|
|
|
|
String? token =
|
|
|
|
|
AppState().postParamsObject?.tokenID ??
|
|
|
|
|
AppState().authenticationTokenID;
|
|
|
|
|
if (token != null && token.isNotEmpty) {
|
|
|
|
|
base["TokenID"] = token;
|
|
|
|
|
}
|
|
|
|
|
@ -185,7 +225,11 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
|
|
|
|
|
// Pass parentId to fetch the subcategories under a given main category (WP_ParentId) -
|
|
|
|
|
// omit it (the default) to fetch the top-level main categories, same as before.
|
|
|
|
|
Future<List<WalaPlusCategoryModel>> getWalaPlusCategories({BuildContext? context, String? mobileNumber, String? parentId}) async {
|
|
|
|
|
Future<List<WalaPlusCategoryModel>> getWalaPlusCategories({
|
|
|
|
|
BuildContext? context,
|
|
|
|
|
String? mobileNumber,
|
|
|
|
|
String? parentId,
|
|
|
|
|
}) async {
|
|
|
|
|
String url = ApiConsts.walaPlusCategories;
|
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
|
String pMobileNumber = _resolveMobileNumber(overrideMobile: mobileNumber);
|
|
|
|
|
@ -209,7 +253,11 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
(response) {
|
|
|
|
|
List<WalaPlusCategoryModel> categories = [];
|
|
|
|
|
if (response != null) {
|
|
|
|
|
dynamic cats = response['WalaPlus_Categories'] ?? response['walaPlus_Categories'] ?? response['WalaPlusCategories'] ?? response['result'];
|
|
|
|
|
dynamic cats =
|
|
|
|
|
response['WalaPlus_Categories'] ??
|
|
|
|
|
response['walaPlus_Categories'] ??
|
|
|
|
|
response['WalaPlusCategories'] ??
|
|
|
|
|
response['result'];
|
|
|
|
|
if (cats is String) {
|
|
|
|
|
try {
|
|
|
|
|
cats = json.decode(cats);
|
|
|
|
|
@ -222,7 +270,9 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
if (v is Map<String, dynamic>) {
|
|
|
|
|
categories.add(WalaPlusCategoryModel.fromJson(v));
|
|
|
|
|
} else if (v is Map) {
|
|
|
|
|
categories.add(WalaPlusCategoryModel.fromJson(Map<String, dynamic>.from(v)));
|
|
|
|
|
categories.add(
|
|
|
|
|
WalaPlusCategoryModel.fromJson(Map<String, dynamic>.from(v)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -279,7 +329,10 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
|
String pMobileNumber = _resolveMobileNumber(overrideMobile: mobileNumber);
|
|
|
|
|
String pDepNationalId = _resolveDepNationalId();
|
|
|
|
|
String effectiveCatId = (categoryId == "all" || categoryId == "0" || categoryId == null) ? "" : categoryId;
|
|
|
|
|
String effectiveCatId =
|
|
|
|
|
(categoryId == "all" || categoryId == "0" || categoryId == null)
|
|
|
|
|
? ""
|
|
|
|
|
: categoryId;
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> postParams = _getBaseWalaPlusParams();
|
|
|
|
|
postParams["UserName"] = pUserName;
|
|
|
|
|
@ -315,7 +368,8 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
try {
|
|
|
|
|
Position? position = await _getCurrentPositionSilently(context);
|
|
|
|
|
if (position != null) {
|
|
|
|
|
postParams["WP_Geo_Location"] = "${position.latitude},${position.longitude}";
|
|
|
|
|
postParams["WP_Geo_Location"] =
|
|
|
|
|
"${position.latitude},${position.longitude}";
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint("getWalaPlusRetailers: unable to get current location: $e");
|
|
|
|
|
@ -333,7 +387,12 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
|
(response) {
|
|
|
|
|
if (response != null) {
|
|
|
|
|
dynamic val = response['WalaPlus_Retailers'] ?? response['walaPlus_Retailers'] ?? response['WalaPlusRetailers'] ?? response['WP_Retailers'] ?? response['result'];
|
|
|
|
|
dynamic val =
|
|
|
|
|
response['WalaPlus_Retailers'] ??
|
|
|
|
|
response['walaPlus_Retailers'] ??
|
|
|
|
|
response['WalaPlusRetailers'] ??
|
|
|
|
|
response['WP_Retailers'] ??
|
|
|
|
|
response['result'];
|
|
|
|
|
if (val is String) {
|
|
|
|
|
try {
|
|
|
|
|
val = json.decode(val);
|
|
|
|
|
@ -344,17 +403,26 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
if (val is Map<String, dynamic>) {
|
|
|
|
|
return WalaPlusRetailersResponse.fromJson(val);
|
|
|
|
|
} else if (val is Map) {
|
|
|
|
|
return WalaPlusRetailersResponse.fromJson(Map<String, dynamic>.from(val));
|
|
|
|
|
return WalaPlusRetailersResponse.fromJson(
|
|
|
|
|
Map<String, dynamic>.from(val),
|
|
|
|
|
);
|
|
|
|
|
} else if (val is List) {
|
|
|
|
|
List<WalaPlusRetailerModel> retailers = [];
|
|
|
|
|
for (var v in val) {
|
|
|
|
|
if (v is Map<String, dynamic>) {
|
|
|
|
|
retailers.add(WalaPlusRetailerModel.fromJson(v));
|
|
|
|
|
} else if (v is Map) {
|
|
|
|
|
retailers.add(WalaPlusRetailerModel.fromJson(Map<String, dynamic>.from(v)));
|
|
|
|
|
retailers.add(
|
|
|
|
|
WalaPlusRetailerModel.fromJson(Map<String, dynamic>.from(v)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return WalaPlusRetailersResponse(retailers: retailers, page: 1, pagesCount: 1, perPage: retailers.length);
|
|
|
|
|
return WalaPlusRetailersResponse(
|
|
|
|
|
retailers: retailers,
|
|
|
|
|
page: 1,
|
|
|
|
|
pagesCount: 1,
|
|
|
|
|
perPage: retailers.length,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
@ -364,12 +432,19 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<WalaPlusRetailerModel?> getWalaPlusRetailerById({required String retailerId, BuildContext? context, String? mobileNumber, String? userReference}) async {
|
|
|
|
|
Future<WalaPlusRetailerModel?> getWalaPlusRetailerById({
|
|
|
|
|
required String retailerId,
|
|
|
|
|
BuildContext? context,
|
|
|
|
|
String? mobileNumber,
|
|
|
|
|
String? userReference,
|
|
|
|
|
}) async {
|
|
|
|
|
String url = ApiConsts.walaPlusRetailersByID;
|
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
|
String pMobileNumber = _resolveMobileNumber(overrideMobile: mobileNumber);
|
|
|
|
|
String pDepNationalId = _resolveDepNationalId();
|
|
|
|
|
String pUserReference = _resolveUserReference(overrideUserReference: userReference);
|
|
|
|
|
String pUserReference = _resolveUserReference(
|
|
|
|
|
overrideUserReference: userReference,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> postParams = _getBaseWalaPlusParams();
|
|
|
|
|
postParams["WP_RetailerID"] = retailerId;
|
|
|
|
|
@ -390,10 +465,13 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
log("context position: $position");
|
|
|
|
|
|
|
|
|
|
if (position != null) {
|
|
|
|
|
postParams["WP_Geo_Location"] = "${position.latitude},${position.longitude}";
|
|
|
|
|
postParams["WP_Geo_Location"] =
|
|
|
|
|
"${position.latitude},${position.longitude}";
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint("getWalaPlusRetailerById: unable to get current location: $e");
|
|
|
|
|
debugPrint(
|
|
|
|
|
"getWalaPlusRetailerById: unable to get current location: $e",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -406,18 +484,29 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
postParams["WP_User_Reference"] = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
debugPrint("getWalaPlusRetailerById: calling $url with params: $postParams");
|
|
|
|
|
debugPrint(
|
|
|
|
|
"getWalaPlusRetailerById: calling $url with params: $postParams",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
|
(response) {
|
|
|
|
|
if (response != null) {
|
|
|
|
|
debugPrint("getWalaPlusRetailerById response keys: ${response is Map ? response.keys.toList() : 'non-map'}");
|
|
|
|
|
dynamic val = response['WalaPlus_RetailersByID'] ?? response['walaPlus_RetailersByID'] ?? response['WalaPlusRetailersByID'] ?? response['WP_RetailersByID'] ?? response['result'];
|
|
|
|
|
debugPrint(
|
|
|
|
|
"getWalaPlusRetailerById response keys: ${response is Map ? response.keys.toList() : 'non-map'}",
|
|
|
|
|
);
|
|
|
|
|
dynamic val =
|
|
|
|
|
response['WalaPlus_RetailersByID'] ??
|
|
|
|
|
response['walaPlus_RetailersByID'] ??
|
|
|
|
|
response['WalaPlusRetailersByID'] ??
|
|
|
|
|
response['WP_RetailersByID'] ??
|
|
|
|
|
response['result'];
|
|
|
|
|
if (val is String) {
|
|
|
|
|
try {
|
|
|
|
|
val = json.decode(val);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint("Error decoding WalaPlus_RetailersByID JSON string: $e");
|
|
|
|
|
debugPrint(
|
|
|
|
|
"Error decoding WalaPlus_RetailersByID JSON string: $e",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
WalaPlusRetailerModel? model;
|
|
|
|
|
@ -426,47 +515,106 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
if (item is Map<String, dynamic>) {
|
|
|
|
|
model = WalaPlusRetailerModel.fromJson(item);
|
|
|
|
|
} else if (item is Map) {
|
|
|
|
|
model = WalaPlusRetailerModel.fromJson(Map<String, dynamic>.from(item));
|
|
|
|
|
model = WalaPlusRetailerModel.fromJson(
|
|
|
|
|
Map<String, dynamic>.from(item),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else if (val is Map) {
|
|
|
|
|
Map<String, dynamic> map = (val is Map<String, dynamic>) ? val : Map<String, dynamic>.from(val);
|
|
|
|
|
Map<String, dynamic> map =
|
|
|
|
|
(val is Map<String, dynamic>)
|
|
|
|
|
? val
|
|
|
|
|
: Map<String, dynamic>.from(val);
|
|
|
|
|
if (map.containsKey('retailer')) {
|
|
|
|
|
var byIdResponse = WalaPlusRetailersByIDResponse.fromJson(map);
|
|
|
|
|
model = byIdResponse.primaryRetailer ?? WalaPlusRetailerModel.fromJson(map);
|
|
|
|
|
model =
|
|
|
|
|
byIdResponse.primaryRetailer ??
|
|
|
|
|
WalaPlusRetailerModel.fromJson(map);
|
|
|
|
|
} else {
|
|
|
|
|
model = WalaPlusRetailerModel.fromJson(map);
|
|
|
|
|
}
|
|
|
|
|
if (model?.isFavorite == null) {
|
|
|
|
|
if (map.containsKey('isfavorite')) {
|
|
|
|
|
model?.isFavorite = map['isfavorite'] == true || map['isfavorite'] == 1 || map['isfavorite'] == 'true' || map['isfavorite'] == '1';
|
|
|
|
|
model?.isFavorite =
|
|
|
|
|
map['isfavorite'] == true ||
|
|
|
|
|
map['isfavorite'] == 1 ||
|
|
|
|
|
map['isfavorite'] == 'true' ||
|
|
|
|
|
map['isfavorite'] == '1';
|
|
|
|
|
} else if (map.containsKey('is_favorite')) {
|
|
|
|
|
model?.isFavorite = map['is_favorite'] == true || map['is_favorite'] == 1 || map['is_favorite'] == 'true' || map['is_favorite'] == '1';
|
|
|
|
|
model?.isFavorite =
|
|
|
|
|
map['is_favorite'] == true ||
|
|
|
|
|
map['is_favorite'] == 1 ||
|
|
|
|
|
map['is_favorite'] == 'true' ||
|
|
|
|
|
map['is_favorite'] == '1';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ((model?.offers == null || model!.offers!.isEmpty) && (map.containsKey('offers') || map.containsKey('Offers'))) {
|
|
|
|
|
model?.offers = WalaPlusRetailerModel.parseOffersList(map['offers'] ?? map['Offers']);
|
|
|
|
|
if ((model?.offers == null || model!.offers!.isEmpty) &&
|
|
|
|
|
(map.containsKey('offers') || map.containsKey('Offers'))) {
|
|
|
|
|
model?.offers = WalaPlusRetailerModel.parseOffersList(
|
|
|
|
|
map['offers'] ?? map['Offers'],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ((model?.locations == null || model!.locations!.isEmpty) &&
|
|
|
|
|
(map.containsKey('locations') || map.containsKey('Locations') || map.containsKey('location') || map.containsKey('Location'))) {
|
|
|
|
|
model?.locations = WalaPlusRetailerModel.parseLocationsList(map['locations'] ?? map['Locations'] ?? map['location'] ?? map['Location']);
|
|
|
|
|
(map.containsKey('locations') ||
|
|
|
|
|
map.containsKey('Locations') ||
|
|
|
|
|
map.containsKey('location') ||
|
|
|
|
|
map.containsKey('Location'))) {
|
|
|
|
|
model?.locations = WalaPlusRetailerModel.parseLocationsList(
|
|
|
|
|
map['locations'] ??
|
|
|
|
|
map['Locations'] ??
|
|
|
|
|
map['location'] ??
|
|
|
|
|
map['Location'],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ((model?.website == null || model!.website!.isEmpty || model!.website == "null")) {
|
|
|
|
|
String? web = (map['website'] ?? map['merchant_website'] ?? map['website_url'] ?? map['url'] ?? map['merchant_url'])?.toString();
|
|
|
|
|
if ((model?.website == null ||
|
|
|
|
|
model!.website!.isEmpty ||
|
|
|
|
|
model!.website == "null")) {
|
|
|
|
|
String? web =
|
|
|
|
|
(map['website'] ??
|
|
|
|
|
map['merchant_website'] ??
|
|
|
|
|
map['website_url'] ??
|
|
|
|
|
map['url'] ??
|
|
|
|
|
map['merchant_url'])
|
|
|
|
|
?.toString();
|
|
|
|
|
if (web != null && web.trim().isNotEmpty && web != "null") {
|
|
|
|
|
model?.website = web.trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ((model?.categories == null || model!.categories!.isEmpty) && (map.containsKey('categories') || map.containsKey('Categories') || map.containsKey('category') || map.containsKey('Category'))) {
|
|
|
|
|
dynamic catData = map['categories'] ?? map['Categories'] ?? map['category'] ?? map['Category'];
|
|
|
|
|
if ((model?.categories == null || model!.categories!.isEmpty) &&
|
|
|
|
|
(map.containsKey('categories') ||
|
|
|
|
|
map.containsKey('Categories') ||
|
|
|
|
|
map.containsKey('category') ||
|
|
|
|
|
map.containsKey('Category'))) {
|
|
|
|
|
dynamic catData =
|
|
|
|
|
map['categories'] ??
|
|
|
|
|
map['Categories'] ??
|
|
|
|
|
map['category'] ??
|
|
|
|
|
map['Category'];
|
|
|
|
|
if (catData is List) {
|
|
|
|
|
model?.categories = catData.map((c) => c is Map ? WalaPlusCategoryModel.fromJson(Map<String, dynamic>.from(c)) : WalaPlusCategoryModel(name: c.toString())).toList();
|
|
|
|
|
model?.categories =
|
|
|
|
|
catData
|
|
|
|
|
.map(
|
|
|
|
|
(c) =>
|
|
|
|
|
c is Map
|
|
|
|
|
? WalaPlusCategoryModel.fromJson(
|
|
|
|
|
Map<String, dynamic>.from(c),
|
|
|
|
|
)
|
|
|
|
|
: WalaPlusCategoryModel(name: c.toString()),
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
} else if (catData is Map) {
|
|
|
|
|
model?.categories = [WalaPlusCategoryModel.fromJson(Map<String, dynamic>.from(catData))];
|
|
|
|
|
model?.categories = [
|
|
|
|
|
WalaPlusCategoryModel.fromJson(
|
|
|
|
|
Map<String, dynamic>.from(catData),
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
} else if (catData is String && catData.trim().isNotEmpty) {
|
|
|
|
|
model?.categories = [WalaPlusCategoryModel(name: catData.trim())];
|
|
|
|
|
model?.categories = [
|
|
|
|
|
WalaPlusCategoryModel(name: catData.trim()),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (response is Map<String, dynamic> && response.containsKey('name')) {
|
|
|
|
|
} else if (response is Map<String, dynamic> &&
|
|
|
|
|
response.containsKey('name')) {
|
|
|
|
|
model = WalaPlusRetailerModel.fromJson(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -474,36 +622,90 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
if (response is Map) {
|
|
|
|
|
if (model.isFavorite == null) {
|
|
|
|
|
if (response.containsKey('isfavorite')) {
|
|
|
|
|
model.isFavorite = response['isfavorite'] == true || response['isfavorite'] == 1 || response['isfavorite'] == 'true' || response['isfavorite'] == '1';
|
|
|
|
|
model.isFavorite =
|
|
|
|
|
response['isfavorite'] == true ||
|
|
|
|
|
response['isfavorite'] == 1 ||
|
|
|
|
|
response['isfavorite'] == 'true' ||
|
|
|
|
|
response['isfavorite'] == '1';
|
|
|
|
|
} else if (response.containsKey('is_favorite')) {
|
|
|
|
|
model.isFavorite = response['is_favorite'] == true || response['is_favorite'] == 1 || response['is_favorite'] == 'true' || response['is_favorite'] == '1';
|
|
|
|
|
model.isFavorite =
|
|
|
|
|
response['is_favorite'] == true ||
|
|
|
|
|
response['is_favorite'] == 1 ||
|
|
|
|
|
response['is_favorite'] == 'true' ||
|
|
|
|
|
response['is_favorite'] == '1';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (model.website == null || model.website!.isEmpty || model.website == "null") {
|
|
|
|
|
String? web = (response['website'] ?? response['merchant_website'] ?? response['website_url'] ?? response['url'] ?? response['merchant_url'])?.toString();
|
|
|
|
|
if (model.website == null ||
|
|
|
|
|
model.website!.isEmpty ||
|
|
|
|
|
model.website == "null") {
|
|
|
|
|
String? web =
|
|
|
|
|
(response['website'] ??
|
|
|
|
|
response['merchant_website'] ??
|
|
|
|
|
response['website_url'] ??
|
|
|
|
|
response['url'] ??
|
|
|
|
|
response['merchant_url'])
|
|
|
|
|
?.toString();
|
|
|
|
|
if (web != null && web.trim().isNotEmpty && web != "null") {
|
|
|
|
|
model.website = web.trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ((model.offers == null || model.offers!.isEmpty) && (response.containsKey('offers') || response.containsKey('Offers'))) {
|
|
|
|
|
model.offers = WalaPlusRetailerModel.parseOffersList(response['offers'] ?? response['Offers']);
|
|
|
|
|
if ((model.offers == null || model.offers!.isEmpty) &&
|
|
|
|
|
(response.containsKey('offers') ||
|
|
|
|
|
response.containsKey('Offers'))) {
|
|
|
|
|
model.offers = WalaPlusRetailerModel.parseOffersList(
|
|
|
|
|
response['offers'] ?? response['Offers'],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ((model.locations == null || model.locations!.isEmpty) &&
|
|
|
|
|
(response.containsKey('locations') || response.containsKey('Locations') || response.containsKey('location') || response.containsKey('Location'))) {
|
|
|
|
|
model.locations = WalaPlusRetailerModel.parseLocationsList(response['locations'] ?? response['Locations'] ?? response['location'] ?? response['Location']);
|
|
|
|
|
(response.containsKey('locations') ||
|
|
|
|
|
response.containsKey('Locations') ||
|
|
|
|
|
response.containsKey('location') ||
|
|
|
|
|
response.containsKey('Location'))) {
|
|
|
|
|
model.locations = WalaPlusRetailerModel.parseLocationsList(
|
|
|
|
|
response['locations'] ??
|
|
|
|
|
response['Locations'] ??
|
|
|
|
|
response['location'] ??
|
|
|
|
|
response['Location'],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ((model.categories == null || model.categories!.isEmpty) && (response.containsKey('categories') || response.containsKey('Categories') || response.containsKey('category') || response.containsKey('Category'))) {
|
|
|
|
|
dynamic catData = response['categories'] ?? response['Categories'] ?? response['category'] ?? response['Category'];
|
|
|
|
|
if ((model.categories == null || model.categories!.isEmpty) &&
|
|
|
|
|
(response.containsKey('categories') ||
|
|
|
|
|
response.containsKey('Categories') ||
|
|
|
|
|
response.containsKey('category') ||
|
|
|
|
|
response.containsKey('Category'))) {
|
|
|
|
|
dynamic catData =
|
|
|
|
|
response['categories'] ??
|
|
|
|
|
response['Categories'] ??
|
|
|
|
|
response['category'] ??
|
|
|
|
|
response['Category'];
|
|
|
|
|
if (catData is List) {
|
|
|
|
|
model.categories = catData.map((c) => c is Map ? WalaPlusCategoryModel.fromJson(Map<String, dynamic>.from(c)) : WalaPlusCategoryModel(name: c.toString())).toList();
|
|
|
|
|
model.categories =
|
|
|
|
|
catData
|
|
|
|
|
.map(
|
|
|
|
|
(c) =>
|
|
|
|
|
c is Map
|
|
|
|
|
? WalaPlusCategoryModel.fromJson(
|
|
|
|
|
Map<String, dynamic>.from(c),
|
|
|
|
|
)
|
|
|
|
|
: WalaPlusCategoryModel(name: c.toString()),
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
} else if (catData is Map) {
|
|
|
|
|
model.categories = [WalaPlusCategoryModel.fromJson(Map<String, dynamic>.from(catData))];
|
|
|
|
|
model.categories = [
|
|
|
|
|
WalaPlusCategoryModel.fromJson(
|
|
|
|
|
Map<String, dynamic>.from(catData),
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
} else if (catData is String && catData.trim().isNotEmpty) {
|
|
|
|
|
model.categories = [WalaPlusCategoryModel(name: catData.trim())];
|
|
|
|
|
model.categories = [
|
|
|
|
|
WalaPlusCategoryModel(name: catData.trim()),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
debugPrint("getWalaPlusRetailerById: parsed retailer '${model.name}', isFavorite: ${model.isFavorite}, offers: ${model.offers?.length ?? 0}, locations: ${model.locations?.length ?? 0}");
|
|
|
|
|
debugPrint(
|
|
|
|
|
"getWalaPlusRetailerById: parsed retailer '${model.name}', isFavorite: ${model.isFavorite}, offers: ${model.offers?.length ?? 0}, locations: ${model.locations?.length ?? 0}",
|
|
|
|
|
);
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -519,9 +721,24 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String _resolveUserReference({String? overrideUserReference}) {
|
|
|
|
|
if (overrideUserReference != null && overrideUserReference.trim().isNotEmpty) {
|
|
|
|
|
if (overrideUserReference != null &&
|
|
|
|
|
overrideUserReference.trim().isNotEmpty) {
|
|
|
|
|
return overrideUserReference.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AppState().memberInformationList is never cleared on logout, so after logging out of an
|
|
|
|
|
// employee session and logging back in as a dependent (without a full app restart) it can
|
|
|
|
|
// still be sitting there from the previous session. Checking the CURRENT session type first
|
|
|
|
|
// - rather than just whichever field happens to be non-empty - prevents a dependent session
|
|
|
|
|
// from ever resolving to the previous employee's number.
|
|
|
|
|
if (ApiConsts.isDependetLogin) {
|
|
|
|
|
String? depRef = AppState().getUserName;
|
|
|
|
|
if (depRef != null && depRef.trim().isNotEmpty) {
|
|
|
|
|
return depRef.trim();
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String? ref = AppState().memberInformationList?.eMPLOYEENUMBER?.toString();
|
|
|
|
|
if (ref != null && ref.trim().isNotEmpty) {
|
|
|
|
|
return ref.trim();
|
|
|
|
|
@ -533,15 +750,25 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<Map<String, dynamic>?> redeemWalaPlusOffer({required String offerId, String? offerType, String? userReference, BuildContext? context}) async {
|
|
|
|
|
Future<Map<String, dynamic>?> redeemWalaPlusOffer({
|
|
|
|
|
required String offerId,
|
|
|
|
|
String? offerType,
|
|
|
|
|
String? userReference,
|
|
|
|
|
BuildContext? context,
|
|
|
|
|
}) async {
|
|
|
|
|
String url = ApiConsts.walaPlusOfferRedeem;
|
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
|
String pUserReference = _resolveUserReference(overrideUserReference: userReference);
|
|
|
|
|
String pUserReference = _resolveUserReference(
|
|
|
|
|
overrideUserReference: userReference,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> postParams = _getBaseWalaPlusParams();
|
|
|
|
|
postParams["WP_User_Reference"] = pUserReference;
|
|
|
|
|
postParams["WP_Offer_Id"] = offerId;
|
|
|
|
|
postParams["WP_Offer_Type"] = (offerType != null && offerType.trim().isNotEmpty) ? offerType.trim() : "promo";
|
|
|
|
|
postParams["WP_Offer_Type"] =
|
|
|
|
|
(offerType != null && offerType.trim().isNotEmpty)
|
|
|
|
|
? offerType.trim()
|
|
|
|
|
: "promo";
|
|
|
|
|
postParams["UserName"] = pUserName;
|
|
|
|
|
postParams["P_USER_NAME"] = pUserName;
|
|
|
|
|
|
|
|
|
|
@ -563,7 +790,11 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
(response) {
|
|
|
|
|
if (response != null) {
|
|
|
|
|
debugPrint("redeemWalaPlusOffer response: $response");
|
|
|
|
|
dynamic val = response['WalaPlus_OfferRedeem'] ?? response['walaPlus_OfferRedeem'] ?? response['WalaPlusOfferRedeem'] ?? response['result'];
|
|
|
|
|
dynamic val =
|
|
|
|
|
response['WalaPlus_OfferRedeem'] ??
|
|
|
|
|
response['walaPlus_OfferRedeem'] ??
|
|
|
|
|
response['WalaPlusOfferRedeem'] ??
|
|
|
|
|
response['result'];
|
|
|
|
|
if (val is String) {
|
|
|
|
|
try {
|
|
|
|
|
val = json.decode(val);
|
|
|
|
|
@ -584,11 +815,19 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<GenericResponseModel?> addWalaPlusFavorite({Object? retailerId, List<String>? retailerIds, BuildContext? context, String? mobileNumber, String? userReference}) async {
|
|
|
|
|
Future<GenericResponseModel?> addWalaPlusFavorite({
|
|
|
|
|
Object? retailerId,
|
|
|
|
|
List<String>? retailerIds,
|
|
|
|
|
BuildContext? context,
|
|
|
|
|
String? mobileNumber,
|
|
|
|
|
String? userReference,
|
|
|
|
|
}) async {
|
|
|
|
|
String url = ApiConsts.walaPlusFavoritesAdd;
|
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
|
String pMobileNumber = _resolveMobileNumber(overrideMobile: mobileNumber);
|
|
|
|
|
String pUserReference = _resolveUserReference(overrideUserReference: userReference);
|
|
|
|
|
String pUserReference = _resolveUserReference(
|
|
|
|
|
overrideUserReference: userReference,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
List<String> ids = [];
|
|
|
|
|
if (retailerIds != null && retailerIds.isNotEmpty) {
|
|
|
|
|
@ -643,11 +882,19 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<GenericResponseModel?> removeWalaPlusFavorite({Object? retailerId, List<String>? retailerIds, BuildContext? context, String? mobileNumber, String? userReference}) async {
|
|
|
|
|
Future<GenericResponseModel?> removeWalaPlusFavorite({
|
|
|
|
|
Object? retailerId,
|
|
|
|
|
List<String>? retailerIds,
|
|
|
|
|
BuildContext? context,
|
|
|
|
|
String? mobileNumber,
|
|
|
|
|
String? userReference,
|
|
|
|
|
}) async {
|
|
|
|
|
String url = ApiConsts.walaPlusFavoritesRemove;
|
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
|
String pMobileNumber = _resolveMobileNumber(overrideMobile: mobileNumber);
|
|
|
|
|
String pUserReference = _resolveUserReference(overrideUserReference: userReference);
|
|
|
|
|
String pUserReference = _resolveUserReference(
|
|
|
|
|
overrideUserReference: userReference,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
List<String> ids = [];
|
|
|
|
|
if (retailerIds != null && retailerIds.isNotEmpty) {
|
|
|
|
|
|