Manos Chorianopoulos

Add getAvailableCouponsAsync request

...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
81 - (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket; 81 - (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket;
82 - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 82 - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
83 - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 83 - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
84 +- (void) getAvailableCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
84 - (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 85 - (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
85 - (void)getCouponsetsDealsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 86 - (void)getCouponsetsDealsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
86 - (void) cancelUnifiedCouponAsync:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 87 - (void) cancelUnifiedCouponAsync:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -1464,6 +1464,19 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; ...@@ -1464,6 +1464,19 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
1464 }]; 1464 }];
1465 } 1465 }
1466 1466
1467 +- (void) getAvailableCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1468 +{
1469 + [[Warply sharedService] getAvailableCouponsWithSuccessBlock:^(NSDictionary *response) {
1470 + if (success) {
1471 + success(response);
1472 + }
1473 + } failureBlock:^(NSError *error) {
1474 + if (failure) {
1475 + failure(error);
1476 + }
1477 + }];
1478 +}
1479 +
1467 - (void) getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 1480 - (void) getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1468 { 1481 {
1469 [[Warply sharedService] getCouponSetsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) { 1482 [[Warply sharedService] getCouponSetsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) {
......
...@@ -403,6 +403,8 @@ WL_VERSION_INTERFACE() ...@@ -403,6 +403,8 @@ WL_VERSION_INTERFACE()
403 403
404 - (void) getCouponSetsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 404 - (void) getCouponSetsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
405 405
406 +- (void) getAvailableCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
407 +
406 - (void) getCouponSetsDealsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 408 - (void) getCouponSetsDealsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
407 409
408 - (void) cancelUnifiedCouponWithSuccessBlock:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 410 - (void) cancelUnifiedCouponWithSuccessBlock:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -3297,6 +3297,44 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -3297,6 +3297,44 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
3297 }]; 3297 }];
3298 } 3298 }
3299 3299
3300 +- (void) getAvailableCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
3301 +{
3302 + /*
3303 + "coupon": {
3304 + "action": "availability",
3305 + "filters": {
3306 + "uuids":null,
3307 + "availability_enabled":true
3308 + }
3309 + }
3310 + */
3311 +
3312 + NSMutableDictionary* filtersDictionary = [[NSMutableDictionary alloc] init];
3313 + [filtersDictionary setValue:[NSNull null] forKey:@"uuids"];
3314 + [filtersDictionary setValue:@YES forKey:@"availability_enabled"];
3315 +
3316 + NSMutableDictionary* couponDictionary = [[NSMutableDictionary alloc] init];
3317 + [couponDictionary setValue:@"availability" forKey:@"action"];
3318 + [couponDictionary setValue:filtersDictionary forKey:@"filters"];
3319 +
3320 + NSMutableDictionary* dataDictionary = [[NSMutableDictionary alloc] init];
3321 + [dataDictionary setValue:couponDictionary forKey:@"coupon"];
3322 +
3323 + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataDictionary options:0 error:NULL];
3324 + [self sendContext:jsonData successBlock:^(NSDictionary *contextResponse) {
3325 + if (success) {
3326 + success(contextResponse);
3327 + }
3328 + NSLog(@"**************** WARPLY Response *****************" );
3329 + NSLog(@"%@", contextResponse );
3330 + } failureBlock:^(NSError *error) {
3331 + if (failure) {
3332 + failure(error);
3333 + }
3334 + NSLog(@"Error at getAvailableCoupons %@", error );
3335 + }];
3336 +}
3337 +
3300 - (void) getCouponSetsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 3338 - (void) getCouponSetsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
3301 { 3339 {
3302 NSMutableDictionary* data = [[NSMutableDictionary alloc] init]; 3340 NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
......
...@@ -1106,6 +1106,8 @@ public class swiftApi { ...@@ -1106,6 +1106,8 @@ public class swiftApi {
1106 private var banner_img: String? 1106 private var banner_img: String?
1107 private var banner_title: String? 1107 private var banner_title: String?
1108 private var unifiedCampaign: UnifiedCampaignModel? 1108 private var unifiedCampaign: UnifiedCampaignModel?
1109 + private var coupon_availability: Int?
1110 + private var category_id: String?
1109 1111
1110 public init() { 1112 public init() {
1111 self.index_url = "" 1113 self.index_url = ""
...@@ -1133,6 +1135,8 @@ public class swiftApi { ...@@ -1133,6 +1135,8 @@ public class swiftApi {
1133 self.banner_img = "" 1135 self.banner_img = ""
1134 self.banner_title = "" 1136 self.banner_title = ""
1135 self.unifiedCampaign = swiftApi.UnifiedCampaignModel() 1137 self.unifiedCampaign = swiftApi.UnifiedCampaignModel()
1138 + self.coupon_availability = nil
1139 + self.category_id = ""
1136 } 1140 }
1137 1141
1138 public init(dictionary: [String: Any]) { 1142 public init(dictionary: [String: Any]) {
...@@ -1149,6 +1153,7 @@ public class swiftApi { ...@@ -1149,6 +1153,7 @@ public class swiftApi {
1149 self.sorting = dictionary["sorting"] as? Int? ?? 0 1153 self.sorting = dictionary["sorting"] as? Int? ?? 0
1150 self.ccms = nil 1154 self.ccms = nil
1151 self.unifiedCampaign = swiftApi.UnifiedCampaignModel() 1155 self.unifiedCampaign = swiftApi.UnifiedCampaignModel()
1156 + self.coupon_availability = nil
1152 1157
1153 // let extra_fields = dictionary["extra_fields"] as? [String: Any]? ?? ["":""] 1158 // let extra_fields = dictionary["extra_fields"] as? [String: Any]? ?? ["":""]
1154 if let extra_fields = dictionary["extra_fields"] as? [String: Any] { 1159 if let extra_fields = dictionary["extra_fields"] as? [String: Any] {
...@@ -1162,6 +1167,7 @@ public class swiftApi { ...@@ -1162,6 +1167,7 @@ public class swiftApi {
1162 self.category_title = extra_fields["category_title"] as? String ?? "" 1167 self.category_title = extra_fields["category_title"] as? String ?? ""
1163 self.banner_img = extra_fields["Banner_img"] as? String ?? "" 1168 self.banner_img = extra_fields["Banner_img"] as? String ?? ""
1164 self.banner_title = extra_fields["Banner_title"] as? String ?? "" 1169 self.banner_title = extra_fields["Banner_title"] as? String ?? ""
1170 + self.category_id = extra_fields["category_id"] as? String ?? ""
1165 } else { 1171 } else {
1166 self.subcategory = "" 1172 self.subcategory = ""
1167 self.loyaltyCampaignId = "" 1173 self.loyaltyCampaignId = ""
...@@ -1400,6 +1406,24 @@ public class swiftApi { ...@@ -1400,6 +1406,24 @@ public class swiftApi {
1400 self.unifiedCampaign = newValue 1406 self.unifiedCampaign = newValue
1401 } 1407 }
1402 } 1408 }
1409 +
1410 + public var _coupon_availability: Int? {
1411 + get { // getter
1412 + return self.coupon_availability
1413 + }
1414 + set(newValue) { //setter
1415 + self.coupon_availability = newValue
1416 + }
1417 + }
1418 +
1419 + public var _category_id: String? {
1420 + get { // getter
1421 + return self.category_id
1422 + }
1423 + set(newValue) { //setter
1424 + self.category_id = newValue
1425 + }
1426 + }
1403 } 1427 }
1404 1428
1405 public class CampaignDataModel { 1429 public class CampaignDataModel {
...@@ -1496,6 +1520,33 @@ public class swiftApi { ...@@ -1496,6 +1520,33 @@ public class swiftApi {
1496 1520
1497 campaignsArray = campaignsArray + (campaignsPersonalizedData ?? []) 1521 campaignsArray = campaignsArray + (campaignsPersonalizedData ?? [])
1498 1522
1523 + swiftApi().getAvailableCouponsAsync({responseDataAvailability in
1524 + if let availabilityData = responseDataAvailability {
1525 + for tempCampaign in campaignsArray {
1526 + for item in availabilityData {
1527 + if (tempCampaign._couponset == item.key) {
1528 + tempCampaign._coupon_availability = item.value as? Int ?? 0
1529 + }
1530 + }
1531 + }
1532 + }
1533 +
1534 + let parsedCampagins = parseCampaigns()
1535 + getCampaignsCallback(parsedCampagins);
1536 +
1537 + }, failureCallback: {errorCode in
1538 + let parsedCampagins = parseCampaigns()
1539 + getCampaignsCallback(parsedCampagins);
1540 + })
1541 +
1542 + // SwiftEventBus.post("campaigns_retrieved")
1543 + }, failureCallback: {errorCode in
1544 +
1545 + let parsedCampagins = parseCampaigns()
1546 + getCampaignsCallback(parsedCampagins);
1547 + })
1548 +
1549 + func parseCampaigns() -> Array<CampaignItemModel> {
1499 swiftApi().setUniqueCampaignList(campaignsArray) 1550 swiftApi().setUniqueCampaignList(campaignsArray)
1500 1551
1501 carouselArray = campaignsArray.filter { 1552 carouselArray = campaignsArray.filter {
...@@ -1521,14 +1572,9 @@ public class swiftApi { ...@@ -1521,14 +1572,9 @@ public class swiftApi {
1521 let sortedCampaigns = filteredCampaigns.sorted { 1572 let sortedCampaigns = filteredCampaigns.sorted {
1522 ($0._sorting ?? 0) < ($1._sorting ?? 0) 1573 ($0._sorting ?? 0) < ($1._sorting ?? 0)
1523 } 1574 }
1524 -
1525 - getCampaignsCallback(sortedCampaigns);
1526 -
1527 - // SwiftEventBus.post("campaigns_retrieved")
1528 - }, failureCallback: {errorCode in
1529 1575
1530 - failureCallback(errorCode) 1576 + return sortedCampaigns
1531 - }) 1577 + }
1532 1578
1533 } else { 1579 } else {
1534 let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() 1580 let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
...@@ -8062,4 +8108,73 @@ public class swiftApi { ...@@ -8062,4 +8108,73 @@ public class swiftApi {
8062 } 8108 }
8063 8109
8064 8110
8111 + public func getAvailableCouponsAsync(_ getAvailableCouponsCallback: @escaping (_ campaignsData: [String: Any]?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
8112 + let instanceOfMyApi = MyApi()
8113 + instanceOfMyApi.getAvailableCouponsAsync(requestCallback, failureBlock: requestFailureCallback)
8114 +
8115 +
8116 + func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
8117 +// var availableCampaignsArray:Array<CampaignItemModel> = []
8118 +
8119 + if let responseDataDictionary = responseData as? [String: AnyObject] {
8120 + if (responseDataDictionary["MAPP_COUPON-status"] as? Int == 1) {
8121 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8122 + dynatraceEvent._eventName = "custom_success_available_coupons"
8123 + dynatraceEvent._parameters = nil
8124 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8125 +
8126 + if let responseDataMapp = responseDataDictionary["MAPP_COUPON"] as? [String: Any] {
8127 + if let responseDataAvailability = responseDataMapp["availability"] as? [String: Any] {
8128 +// for tempCampaign in swiftApi().getAllCampaignList() {
8129 +// for item in responseDataAvailability {
8130 +// if (tempCampaign._couponset == item.key) {
8131 +// tempCampaign._coupon_availability = item.value as? Int ?? 0
8132 +// availableCampaignsArray.append(tempCampaign)
8133 +// }
8134 +// }
8135 +// }
8136 +//
8137 + getAvailableCouponsCallback(responseDataAvailability)
8138 +
8139 + } else {
8140 + getAvailableCouponsCallback(nil)
8141 + }
8142 + } else {
8143 + getAvailableCouponsCallback(nil)
8144 + }
8145 +
8146 + } else {
8147 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8148 + dynatraceEvent._eventName = "custom_error_available_coupons"
8149 + dynatraceEvent._parameters = nil
8150 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8151 +
8152 + getAvailableCouponsCallback(nil)
8153 + }
8154 +
8155 + } else {
8156 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8157 + dynatraceEvent._eventName = "custom_error_available_coupons"
8158 + dynatraceEvent._parameters = nil
8159 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8160 +
8161 + getAvailableCouponsCallback(nil)
8162 + }
8163 + }
8164 +
8165 + func requestFailureCallback(_ error: Error?) -> Void {
8166 + print("getAvailableCouponsCallback error: ")
8167 + print(error)
8168 + print("====================")
8169 +
8170 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8171 + dynatraceEvent._eventName = "custom_error_available_coupons"
8172 + dynatraceEvent._parameters = nil
8173 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8174 +
8175 + getAvailableCouponsCallback(nil)
8176 + }
8177 + }
8178 +
8179 +
8065 } 8180 }
......