Manos Chorianopoulos

Add getAvailableCouponsAsync request

......@@ -81,6 +81,7 @@
- (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket;
- (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) getAvailableCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getCouponsetsDealsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) cancelUnifiedCouponAsync:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -1464,6 +1464,19 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
- (void) getAvailableCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] getAvailableCouponsWithSuccessBlock:^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
- (void) getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] getCouponSetsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) {
......
......@@ -403,6 +403,8 @@ WL_VERSION_INTERFACE()
- (void) getCouponSetsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) getAvailableCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) getCouponSetsDealsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) cancelUnifiedCouponWithSuccessBlock:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -3297,6 +3297,44 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
- (void) getAvailableCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
/*
"coupon": {
"action": "availability",
"filters": {
"uuids":null,
"availability_enabled":true
}
}
*/
NSMutableDictionary* filtersDictionary = [[NSMutableDictionary alloc] init];
[filtersDictionary setValue:[NSNull null] forKey:@"uuids"];
[filtersDictionary setValue:@YES forKey:@"availability_enabled"];
NSMutableDictionary* couponDictionary = [[NSMutableDictionary alloc] init];
[couponDictionary setValue:@"availability" forKey:@"action"];
[couponDictionary setValue:filtersDictionary forKey:@"filters"];
NSMutableDictionary* dataDictionary = [[NSMutableDictionary alloc] init];
[dataDictionary setValue:couponDictionary forKey:@"coupon"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataDictionary options:0 error:NULL];
[self sendContext:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
NSLog(@"**************** WARPLY Response *****************" );
NSLog(@"%@", contextResponse );
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
NSLog(@"Error at getAvailableCoupons %@", error );
}];
}
- (void) getCouponSetsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
......
......@@ -1106,6 +1106,8 @@ public class swiftApi {
private var banner_img: String?
private var banner_title: String?
private var unifiedCampaign: UnifiedCampaignModel?
private var coupon_availability: Int?
private var category_id: String?
public init() {
self.index_url = ""
......@@ -1133,6 +1135,8 @@ public class swiftApi {
self.banner_img = ""
self.banner_title = ""
self.unifiedCampaign = swiftApi.UnifiedCampaignModel()
self.coupon_availability = nil
self.category_id = ""
}
public init(dictionary: [String: Any]) {
......@@ -1149,6 +1153,7 @@ public class swiftApi {
self.sorting = dictionary["sorting"] as? Int? ?? 0
self.ccms = nil
self.unifiedCampaign = swiftApi.UnifiedCampaignModel()
self.coupon_availability = nil
// let extra_fields = dictionary["extra_fields"] as? [String: Any]? ?? ["":""]
if let extra_fields = dictionary["extra_fields"] as? [String: Any] {
......@@ -1162,6 +1167,7 @@ public class swiftApi {
self.category_title = extra_fields["category_title"] as? String ?? ""
self.banner_img = extra_fields["Banner_img"] as? String ?? ""
self.banner_title = extra_fields["Banner_title"] as? String ?? ""
self.category_id = extra_fields["category_id"] as? String ?? ""
} else {
self.subcategory = ""
self.loyaltyCampaignId = ""
......@@ -1400,6 +1406,24 @@ public class swiftApi {
self.unifiedCampaign = newValue
}
}
public var _coupon_availability: Int? {
get { // getter
return self.coupon_availability
}
set(newValue) { //setter
self.coupon_availability = newValue
}
}
public var _category_id: String? {
get { // getter
return self.category_id
}
set(newValue) { //setter
self.category_id = newValue
}
}
}
public class CampaignDataModel {
......@@ -1496,6 +1520,33 @@ public class swiftApi {
campaignsArray = campaignsArray + (campaignsPersonalizedData ?? [])
swiftApi().getAvailableCouponsAsync({responseDataAvailability in
if let availabilityData = responseDataAvailability {
for tempCampaign in campaignsArray {
for item in availabilityData {
if (tempCampaign._couponset == item.key) {
tempCampaign._coupon_availability = item.value as? Int ?? 0
}
}
}
}
let parsedCampagins = parseCampaigns()
getCampaignsCallback(parsedCampagins);
}, failureCallback: {errorCode in
let parsedCampagins = parseCampaigns()
getCampaignsCallback(parsedCampagins);
})
// SwiftEventBus.post("campaigns_retrieved")
}, failureCallback: {errorCode in
let parsedCampagins = parseCampaigns()
getCampaignsCallback(parsedCampagins);
})
func parseCampaigns() -> Array<CampaignItemModel> {
swiftApi().setUniqueCampaignList(campaignsArray)
carouselArray = campaignsArray.filter {
......@@ -1522,13 +1573,8 @@ public class swiftApi {
($0._sorting ?? 0) < ($1._sorting ?? 0)
}
getCampaignsCallback(sortedCampaigns);
// SwiftEventBus.post("campaigns_retrieved")
}, failureCallback: {errorCode in
failureCallback(errorCode)
})
return sortedCampaigns
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
......@@ -8062,4 +8108,73 @@ public class swiftApi {
}
public func getAvailableCouponsAsync(_ getAvailableCouponsCallback: @escaping (_ campaignsData: [String: Any]?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.getAvailableCouponsAsync(requestCallback, failureBlock: requestFailureCallback)
func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
// var availableCampaignsArray:Array<CampaignItemModel> = []
if let responseDataDictionary = responseData as? [String: AnyObject] {
if (responseDataDictionary["MAPP_COUPON-status"] as? Int == 1) {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_success_available_coupons"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
if let responseDataMapp = responseDataDictionary["MAPP_COUPON"] as? [String: Any] {
if let responseDataAvailability = responseDataMapp["availability"] as? [String: Any] {
// for tempCampaign in swiftApi().getAllCampaignList() {
// for item in responseDataAvailability {
// if (tempCampaign._couponset == item.key) {
// tempCampaign._coupon_availability = item.value as? Int ?? 0
// availableCampaignsArray.append(tempCampaign)
// }
// }
// }
//
getAvailableCouponsCallback(responseDataAvailability)
} else {
getAvailableCouponsCallback(nil)
}
} else {
getAvailableCouponsCallback(nil)
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_available_coupons"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
getAvailableCouponsCallback(nil)
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_available_coupons"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
getAvailableCouponsCallback(nil)
}
}
func requestFailureCallback(_ error: Error?) -> Void {
print("getAvailableCouponsCallback error: ")
print(error)
print("====================")
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_available_coupons"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
getAvailableCouponsCallback(nil)
}
}
}
......