|
|
|
@ -7,6 +7,7 @@ import 'package:geolocator/geolocator.dart';
|
|
|
|
import 'package:mohem_flutter_app/api/api_client.dart';
|
|
|
|
import 'package:mohem_flutter_app/api/api_client.dart';
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
|
|
|
|
|
|
import 'package:mohem_flutter_app/models/generic_response_model.dart';
|
|
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/get_categories_list.dart';
|
|
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/get_categories_list.dart';
|
|
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart';
|
|
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart';
|
|
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_category_model.dart';
|
|
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_category_model.dart';
|
|
|
|
@ -259,6 +260,7 @@ class OffersAndDiscountsApiClient {
|
|
|
|
BuildContext? context,
|
|
|
|
BuildContext? context,
|
|
|
|
String? mobileNumber,
|
|
|
|
String? mobileNumber,
|
|
|
|
String? query,
|
|
|
|
String? query,
|
|
|
|
|
|
|
|
String? userReference,
|
|
|
|
}) async {
|
|
|
|
}) async {
|
|
|
|
String url = ApiConsts.walaPlusRetailers;
|
|
|
|
String url = ApiConsts.walaPlusRetailers;
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
@ -299,6 +301,13 @@ class OffersAndDiscountsApiClient {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_cleanWalaPlusParams(postParams);
|
|
|
|
_cleanWalaPlusParams(postParams);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pass WP_User_Reference: if filled then user ID, else null value
|
|
|
|
|
|
|
|
if (userReference != null && userReference.trim().isNotEmpty) {
|
|
|
|
|
|
|
|
postParams["WP_User_Reference"] = userReference.trim();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
postParams["WP_User_Reference"] = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
(response) {
|
|
|
|
(response) {
|
|
|
|
if (response != null) {
|
|
|
|
if (response != null) {
|
|
|
|
@ -333,11 +342,17 @@ class OffersAndDiscountsApiClient {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<WalaPlusRetailerModel?> getWalaPlusRetailerById({required String retailerId, BuildContext? context, String? mobileNumber}) async {
|
|
|
|
Future<WalaPlusRetailerModel?> getWalaPlusRetailerById({
|
|
|
|
|
|
|
|
required String retailerId,
|
|
|
|
|
|
|
|
BuildContext? context,
|
|
|
|
|
|
|
|
String? mobileNumber,
|
|
|
|
|
|
|
|
String? userReference,
|
|
|
|
|
|
|
|
}) async {
|
|
|
|
String url = ApiConsts.walaPlusRetailersByID;
|
|
|
|
String url = ApiConsts.walaPlusRetailersByID;
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
String pUserName = _resolveUserName();
|
|
|
|
String pMobileNumber = _resolveMobileNumber(overrideMobile: mobileNumber);
|
|
|
|
String pMobileNumber = _resolveMobileNumber(overrideMobile: mobileNumber);
|
|
|
|
String pDepNationalId = _resolveDepNationalId();
|
|
|
|
String pDepNationalId = _resolveDepNationalId();
|
|
|
|
|
|
|
|
String pUserReference = _resolveUserReference(overrideUserReference: userReference);
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> postParams = _getBaseWalaPlusParams();
|
|
|
|
Map<String, dynamic> postParams = _getBaseWalaPlusParams();
|
|
|
|
postParams["WP_RetailerID"] = retailerId;
|
|
|
|
postParams["WP_RetailerID"] = retailerId;
|
|
|
|
@ -352,6 +367,7 @@ class OffersAndDiscountsApiClient {
|
|
|
|
postParams["CompanyID"] = 1;
|
|
|
|
postParams["CompanyID"] = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (context != null) {
|
|
|
|
if (context != null) {
|
|
|
|
|
|
|
|
postParams["LanguageID"] = AppState().getLanguageID(context);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Position? position = await _getCurrentPositionSilently(context);
|
|
|
|
Position? position = await _getCurrentPositionSilently(context);
|
|
|
|
log("context position: $position");
|
|
|
|
log("context position: $position");
|
|
|
|
@ -366,7 +382,14 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
|
|
|
|
|
|
|
_cleanWalaPlusParams(postParams);
|
|
|
|
_cleanWalaPlusParams(postParams);
|
|
|
|
|
|
|
|
|
|
|
|
debugPrint("getWalaPlusRetailerById: calling $url with WP_RetailerID: $retailerId");
|
|
|
|
// Pass WP_User_Reference: if filled then user ID, else null value
|
|
|
|
|
|
|
|
if (pUserReference.isNotEmpty) {
|
|
|
|
|
|
|
|
postParams["WP_User_Reference"] = pUserReference;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
postParams["WP_User_Reference"] = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debugPrint("getWalaPlusRetailerById: calling $url with params: $postParams");
|
|
|
|
|
|
|
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
(response) {
|
|
|
|
(response) {
|
|
|
|
@ -396,6 +419,13 @@ class OffersAndDiscountsApiClient {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
model = WalaPlusRetailerModel.fromJson(map);
|
|
|
|
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';
|
|
|
|
|
|
|
|
} else if (map.containsKey('is_favorite')) {
|
|
|
|
|
|
|
|
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'))) {
|
|
|
|
if ((model?.offers == null || model!.offers!.isEmpty) && (map.containsKey('offers') || map.containsKey('Offers'))) {
|
|
|
|
model?.offers = WalaPlusRetailerModel.parseOffersList(map['offers'] ?? map['Offers']);
|
|
|
|
model?.offers = WalaPlusRetailerModel.parseOffersList(map['offers'] ?? map['Offers']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -415,6 +445,13 @@ class OffersAndDiscountsApiClient {
|
|
|
|
|
|
|
|
|
|
|
|
if (model != null) {
|
|
|
|
if (model != null) {
|
|
|
|
if (response is Map) {
|
|
|
|
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';
|
|
|
|
|
|
|
|
} else if (response.containsKey('is_favorite')) {
|
|
|
|
|
|
|
|
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") {
|
|
|
|
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();
|
|
|
|
String? web = (response['website'] ?? response['merchant_website'] ?? response['website_url'] ?? response['url'] ?? response['merchant_url'])?.toString();
|
|
|
|
if (web != null && web.trim().isNotEmpty && web != "null") {
|
|
|
|
if (web != null && web.trim().isNotEmpty && web != "null") {
|
|
|
|
@ -429,7 +466,7 @@ class OffersAndDiscountsApiClient {
|
|
|
|
model.locations = WalaPlusRetailerModel.parseLocationsList(response['locations'] ?? response['Locations'] ?? response['location'] ?? response['Location']);
|
|
|
|
model.locations = WalaPlusRetailerModel.parseLocationsList(response['locations'] ?? response['Locations'] ?? response['location'] ?? response['Location']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debugPrint("getWalaPlusRetailerById: parsed retailer '${model.name}', 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;
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -440,6 +477,10 @@ class OffersAndDiscountsApiClient {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String resolveUserReference({String? overrideUserReference}) {
|
|
|
|
|
|
|
|
return _resolveUserReference(overrideUserReference: overrideUserReference);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String _resolveUserReference({String? overrideUserReference}) {
|
|
|
|
String _resolveUserReference({String? overrideUserReference}) {
|
|
|
|
if (overrideUserReference != null && overrideUserReference.trim().isNotEmpty) {
|
|
|
|
if (overrideUserReference != null && overrideUserReference.trim().isNotEmpty) {
|
|
|
|
return overrideUserReference.trim();
|
|
|
|
return overrideUserReference.trim();
|
|
|
|
@ -505,4 +546,134 @@ class OffersAndDiscountsApiClient {
|
|
|
|
postParams,
|
|
|
|
postParams,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> ids = [];
|
|
|
|
|
|
|
|
if (retailerIds != null && retailerIds.isNotEmpty) {
|
|
|
|
|
|
|
|
ids.addAll(retailerIds);
|
|
|
|
|
|
|
|
} else if (retailerId != null) {
|
|
|
|
|
|
|
|
if (retailerId is List) {
|
|
|
|
|
|
|
|
ids.addAll(retailerId.map((e) => e.toString()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ids.add(retailerId.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> postParams = _getBaseWalaPlusParams();
|
|
|
|
|
|
|
|
postParams["P_USER_NAME"] = pUserName;
|
|
|
|
|
|
|
|
postParams["UserName"] = pUserName;
|
|
|
|
|
|
|
|
if (pMobileNumber.isNotEmpty) {
|
|
|
|
|
|
|
|
postParams["MobileNumber"] = pMobileNumber;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pUserReference.isNotEmpty) {
|
|
|
|
|
|
|
|
postParams["WP_User_Reference"] = pUserReference;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
postParams["WP_Retailer_Ids"] = ids;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (context != null) {
|
|
|
|
|
|
|
|
postParams["LanguageID"] = AppState().getLanguageID(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ApiConsts.isDependetLogin) {
|
|
|
|
|
|
|
|
String pDepNationalId = _resolveDepNationalId();
|
|
|
|
|
|
|
|
if (pDepNationalId.isNotEmpty) {
|
|
|
|
|
|
|
|
postParams["P_DEP_NATIONAL_ID"] = pDepNationalId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
postParams["MemberType"] = 2;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
postParams["MemberType"] = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_cleanWalaPlusParams(postParams);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debugPrint("addWalaPlusFavorite calling $url with params: $postParams");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
|
|
|
|
(response) {
|
|
|
|
|
|
|
|
if (response != null) {
|
|
|
|
|
|
|
|
debugPrint("addWalaPlusFavorite response: $response");
|
|
|
|
|
|
|
|
return GenericResponseModel.fromJson(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
url,
|
|
|
|
|
|
|
|
postParams,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> ids = [];
|
|
|
|
|
|
|
|
if (retailerIds != null && retailerIds.isNotEmpty) {
|
|
|
|
|
|
|
|
ids.addAll(retailerIds);
|
|
|
|
|
|
|
|
} else if (retailerId != null) {
|
|
|
|
|
|
|
|
if (retailerId is List) {
|
|
|
|
|
|
|
|
ids.addAll(retailerId.map((e) => e.toString()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ids.add(retailerId.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> postParams = _getBaseWalaPlusParams();
|
|
|
|
|
|
|
|
postParams["P_USER_NAME"] = pUserName;
|
|
|
|
|
|
|
|
postParams["UserName"] = pUserName;
|
|
|
|
|
|
|
|
if (pMobileNumber.isNotEmpty) {
|
|
|
|
|
|
|
|
postParams["MobileNumber"] = pMobileNumber;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pUserReference.isNotEmpty) {
|
|
|
|
|
|
|
|
postParams["WP_User_Reference"] = pUserReference;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
postParams["WP_Retailer_Ids"] = ids;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (context != null) {
|
|
|
|
|
|
|
|
postParams["LanguageID"] = AppState().getLanguageID(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ApiConsts.isDependetLogin) {
|
|
|
|
|
|
|
|
String pDepNationalId = _resolveDepNationalId();
|
|
|
|
|
|
|
|
if (pDepNationalId.isNotEmpty) {
|
|
|
|
|
|
|
|
postParams["P_DEP_NATIONAL_ID"] = pDepNationalId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
postParams["MemberType"] = 2;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
postParams["MemberType"] = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_cleanWalaPlusParams(postParams);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debugPrint("removeWalaPlusFavorite calling $url with params: $postParams");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
|
|
|
|
(response) {
|
|
|
|
|
|
|
|
if (response != null) {
|
|
|
|
|
|
|
|
debugPrint("removeWalaPlusFavorite response: $response");
|
|
|
|
|
|
|
|
return GenericResponseModel.fromJson(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
url,
|
|
|
|
|
|
|
|
postParams,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|