Showing
5 changed files
with
304 additions
and
1 deletions
... | @@ -80,6 +80,7 @@ | ... | @@ -80,6 +80,7 @@ |
80 | - (NSDictionary*)validateCouponWithCoupon:(NSString*)coupon; | 80 | - (NSDictionary*)validateCouponWithCoupon:(NSString*)coupon; |
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)getCouponsUniversalAsync:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
83 | - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 84 | - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
84 | - (void) getAvailableCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 85 | - (void) getAvailableCouponsAsync:(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; | 86 | - (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
... | @@ -1450,6 +1450,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; | ... | @@ -1450,6 +1450,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; |
1450 | }]; | 1450 | }]; |
1451 | } | 1451 | } |
1452 | 1452 | ||
1453 | +- (void)getCouponsUniversalAsync:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
1454 | +{ | ||
1455 | + | ||
1456 | + [[Warply sharedService] getCouponsUniversalWithSuccessBlock:language :^(NSDictionary *response) { | ||
1457 | + if (success) { | ||
1458 | + success(response); | ||
1459 | + } | ||
1460 | + } failureBlock:^(NSError *error) { | ||
1461 | + if (failure) { | ||
1462 | + failure(error); | ||
1463 | + } | ||
1464 | + }]; | ||
1465 | +} | ||
1466 | + | ||
1453 | - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1467 | - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
1454 | { | 1468 | { |
1455 | 1469 | ... | ... |
... | @@ -369,6 +369,8 @@ WL_VERSION_INTERFACE() | ... | @@ -369,6 +369,8 @@ WL_VERSION_INTERFACE() |
369 | 369 | ||
370 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 370 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
371 | 371 | ||
372 | +- (void)getCouponsUniversalWithSuccessBlock:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
373 | + | ||
372 | - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 374 | - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
373 | 375 | ||
374 | - (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 376 | - (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
... | @@ -2572,6 +2572,82 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -2572,6 +2572,82 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
2572 | }]; | 2572 | }]; |
2573 | } | 2573 | } |
2574 | 2574 | ||
2575 | +- (void)getCouponsUniversalWithSuccessBlock:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
2576 | +{ | ||
2577 | + // TODO: If pagination is needed in the future create new signature with the extra argument pagination | ||
2578 | + /* | ||
2579 | + { | ||
2580 | + "coupon": { | ||
2581 | + "action": "user_coupons", | ||
2582 | + "details":[ | ||
2583 | + "merchant" | ||
2584 | + ], | ||
2585 | + "language":"el", | ||
2586 | + "pagination":{ | ||
2587 | + "page":1, | ||
2588 | + "per_page":10 | ||
2589 | + } | ||
2590 | + } | ||
2591 | + } | ||
2592 | + */ | ||
2593 | + | ||
2594 | + NSMutableDictionary* couponDictionary = [[NSMutableDictionary alloc] init]; | ||
2595 | + [couponDictionary setValue:@"user_coupons" forKey:@"action"]; | ||
2596 | + [couponDictionary setValue:@[@"merchant"] forKey:@"details"]; | ||
2597 | + [couponDictionary setValue:language forKey:@"language"]; | ||
2598 | + | ||
2599 | + NSMutableDictionary* dataDictionary = [[NSMutableDictionary alloc] init]; | ||
2600 | + [dataDictionary setValue:couponDictionary forKey:@"coupon"]; | ||
2601 | + | ||
2602 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataDictionary options:0 error:NULL]; | ||
2603 | + | ||
2604 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
2605 | + if (success) { | ||
2606 | + success(contextResponse); | ||
2607 | + } | ||
2608 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
2609 | + NSLog(@"%@", contextResponse ); | ||
2610 | + } failureBlock:^(NSError *error) { | ||
2611 | + if (failure) { | ||
2612 | + NSDictionary* dict = [NSDictionary alloc]; | ||
2613 | + dict = [error userInfo]; | ||
2614 | + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"]; | ||
2615 | + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) { | ||
2616 | + | ||
2617 | +// NSString* errorDomain = [error domain]; | ||
2618 | +// NSError *errorToken = [NSError errorWithDomain:errorDomain code:401 userInfo:dict]; | ||
2619 | +// | ||
2620 | +// if (failure) { | ||
2621 | +// failure(errorToken); | ||
2622 | +// } | ||
2623 | + | ||
2624 | + [self refreshToken:^(NSDictionary *response) { | ||
2625 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
2626 | + if (success) { | ||
2627 | + success(contextResponse); | ||
2628 | + } | ||
2629 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
2630 | + NSLog(@"%@", contextResponse ); | ||
2631 | + } failureBlock:^(NSError *error) { | ||
2632 | + if (failure) { | ||
2633 | + failure(error); | ||
2634 | + } | ||
2635 | + }]; | ||
2636 | + } failureBlock:^(NSError *error) { | ||
2637 | + if (failure) { | ||
2638 | + // [_db executeUpdate:@"DROP TABLE requestVariables"]; | ||
2639 | + failure(error); | ||
2640 | + } | ||
2641 | + NSLog(@"Error at token %@", error ); | ||
2642 | + }]; | ||
2643 | + } else { | ||
2644 | + NSLog(@"Error at get coupons %@", error ); | ||
2645 | + failure(error); | ||
2646 | + } | ||
2647 | + } | ||
2648 | + }]; | ||
2649 | +} | ||
2650 | + | ||
2575 | - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 2651 | - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
2576 | { | 2652 | { |
2577 | NSMutableDictionary* data = [[NSMutableDictionary alloc] init]; | 2653 | NSMutableDictionary* data = [[NSMutableDictionary alloc] init]; | ... | ... |
... | @@ -1068,8 +1068,105 @@ public class swiftApi { | ... | @@ -1068,8 +1068,105 @@ public class swiftApi { |
1068 | }) | 1068 | }) |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | + // public func getCouponsAsync(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | ||
1072 | + // CouponsDataModel().getCouponsData(getCouponsCallback, failureCallback: failureCallback) | ||
1073 | + // } | ||
1074 | + | ||
1071 | public func getCouponsAsync(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | 1075 | public func getCouponsAsync(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { |
1072 | - CouponsDataModel().getCouponsData(getCouponsCallback, failureCallback: failureCallback) | 1076 | + let instanceOfMyApi = MyApi() |
1077 | + | ||
1078 | + swiftApi().getMultilingualMerchantsAsync([], false, 0.0, [], "", 0, [], getMerchantsCallback) | ||
1079 | + | ||
1080 | + func getMerchantsCallback (_ merchantsData: Array<swiftApi.MerchantModel>?) -> Void { | ||
1081 | + if (merchantsData != nil) { | ||
1082 | + DispatchQueue.main.async { | ||
1083 | + swiftApi().setMerchantList(merchantsData ?? []) | ||
1084 | + } | ||
1085 | + } else { | ||
1086 | + } | ||
1087 | + } | ||
1088 | + | ||
1089 | + swiftApi().getCouponsUniversalAsync(language: "el", getCouponsCallback, failureCallback: failureCallback) | ||
1090 | + | ||
1091 | + // swiftApi().getCouponsUniversalAsync(language: "el", getCouponsUniversalCallback) { errorCode in | ||
1092 | + // // TODO: DELETE LOGS | ||
1093 | + // print("========= getCouponsUniversalRequest ERROR CODE =========", errorCode) | ||
1094 | + | ||
1095 | + // failureCallback(errorCode) | ||
1096 | + // } | ||
1097 | + | ||
1098 | + // func getCouponsUniversalCallback (_ responseData: Array<swiftApi.CouponItemModel>?) -> Void { | ||
1099 | + // if (responseData != nil) { | ||
1100 | + // DispatchQueue.main.async { | ||
1101 | + // // TODO: DELETE LOGS | ||
1102 | + // print("========= getCouponsUniversalRequest responseData =========") | ||
1103 | + // print(responseData) | ||
1104 | + | ||
1105 | + // var activeCoupons = responseData.filter({ return $0.status == 1 }) | ||
1106 | + // // sort activeCoupons by expiration date | ||
1107 | + // let dateFormatter = DateFormatter() | ||
1108 | + // dateFormatter.dateFormat = "dd/MM/yyyy" | ||
1109 | + | ||
1110 | + // activeCoupons.sort(by: { | ||
1111 | + // let date1 = dateFormatter.date(from: $0.expiration ?? "") | ||
1112 | + // let date2 = dateFormatter.date(from: $1.expiration ?? "") | ||
1113 | + | ||
1114 | + // if ((date1 != nil) && (date2 != nil)) { | ||
1115 | + // return date1!.compare(date2!) == .orderedAscending | ||
1116 | + // } else { | ||
1117 | + // return false | ||
1118 | + // } | ||
1119 | + | ||
1120 | + // }) | ||
1121 | + // getCouponsCallback(activeCoupons) | ||
1122 | + // } | ||
1123 | + // } else { | ||
1124 | + // // TODO: DELETE LOGS | ||
1125 | + // print("========= getCouponsUniversalRequest ERROR =========") | ||
1126 | + | ||
1127 | + // getCouponsCallback(nil) | ||
1128 | + // } | ||
1129 | + // } | ||
1130 | + | ||
1131 | + instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback) | ||
1132 | + | ||
1133 | + func couponSetsCallback(_ couponSetsData: [AnyHashable : Any]?) -> Void { | ||
1134 | + var couponSetsArray:Array<CouponSetItemModel> = [] | ||
1135 | + | ||
1136 | + if let myCouponsSetsDictionary = couponSetsData as? [String : AnyObject] { | ||
1137 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
1138 | + dynatraceEvent._eventName = "custom_success_couponset_loyalty" | ||
1139 | + dynatraceEvent._parameters = nil | ||
1140 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
1141 | + | ||
1142 | + if let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as? NSArray) { | ||
1143 | + for couponset in couponSetsData { | ||
1144 | + | ||
1145 | + if let couponsetDictionairy = couponset as? [String : Any] { | ||
1146 | + let tempCouponset = CouponSetItemModel(dictionary: couponsetDictionairy) | ||
1147 | + couponSetsArray.append(tempCouponset) | ||
1148 | + } | ||
1149 | + } | ||
1150 | + } | ||
1151 | + | ||
1152 | + | ||
1153 | + } else { | ||
1154 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
1155 | + dynatraceEvent._eventName = "custom_error_couponset_loyalty" | ||
1156 | + dynatraceEvent._parameters = nil | ||
1157 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
1158 | + } | ||
1159 | + swiftApi().setCouponSetList(couponSetsArray) | ||
1160 | + } | ||
1161 | + | ||
1162 | + func couponSetsFailureCallback(_ error: Error?) -> Void { | ||
1163 | + print("getCouponSets error: ") | ||
1164 | + | ||
1165 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
1166 | + dynatraceEvent._eventName = "custom_error_couponset_loyalty" | ||
1167 | + dynatraceEvent._parameters = nil | ||
1168 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
1169 | + } | ||
1073 | } | 1170 | } |
1074 | 1171 | ||
1075 | public class func getCoupons() -> Array<CouponItemModel> { | 1172 | public class func getCoupons() -> Array<CouponItemModel> { |
... | @@ -8265,4 +8362,117 @@ public class swiftApi { | ... | @@ -8265,4 +8362,117 @@ public class swiftApi { |
8265 | } | 8362 | } |
8266 | 8363 | ||
8267 | 8364 | ||
8365 | + public func getCouponsUniversalAsync(language: String, _ successCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | ||
8366 | + | ||
8367 | + let instanceOfMyApi = MyApi() | ||
8368 | + instanceOfMyApi.getCouponsUniversalAsync(language, getCouponsUniversalCallback, failureBlock: getCouponsUniversalFailureCallback) | ||
8369 | + | ||
8370 | + func getCouponsUniversalCallback(_ responseData: [AnyHashable: Any]?) -> Void { | ||
8371 | + var couponsArray:Array<CouponItemModel> = [] | ||
8372 | + | ||
8373 | + if let responseDataDictionary = responseData as? [String: AnyObject] { | ||
8374 | + | ||
8375 | + // TODO: DELETE LOGS | ||
8376 | + print("=== responseDataDictionary ===") | ||
8377 | + print(responseDataDictionary) | ||
8378 | + print("=== responseDataDictionary result ===") | ||
8379 | + print(responseDataDictionary["result"]) | ||
8380 | + print("=== responseDataDictionary status ===") | ||
8381 | + print(responseDataDictionary["status"]) | ||
8382 | + | ||
8383 | + | ||
8384 | + if (responseDataDictionary["status"] as? Int == 1) { | ||
8385 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
8386 | + dynatraceEvent._eventName = "custom_success_user_coupons_loyalty" | ||
8387 | + dynatraceEvent._parameters = nil | ||
8388 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
8389 | + | ||
8390 | + if let responseDataResult = responseDataDictionary["result"] as? [[String : Any]?] { | ||
8391 | + for coupon in responseDataResult { | ||
8392 | + if let couponDictionary = coupon { | ||
8393 | + let tempCoupon = CouponItemModel(dictionary: couponDictionary) | ||
8394 | + couponsArray.append(tempCoupon) | ||
8395 | + } | ||
8396 | + } | ||
8397 | + | ||
8398 | + // TODO: DELETE LOGS | ||
8399 | + print("=== AllCoupons NEW ===") | ||
8400 | + print(couponsArray.count) | ||
8401 | + | ||
8402 | + // setAllOldCouponList uncluding Supermarkets ==> | ||
8403 | + swiftApi().setAllOldCouponList(couponsArray) | ||
8404 | + // <== | ||
8405 | + swiftApi().setCouponList(couponsArray) | ||
8406 | + swiftApi().setOldCouponList(couponsArray) | ||
8407 | + | ||
8408 | + var activeCoupons = couponsArray.filter({ return $0.status == 1 }) | ||
8409 | + // sort activeCoupons by expiration date | ||
8410 | + let dateFormatter = DateFormatter() | ||
8411 | + dateFormatter.dateFormat = "dd/MM/yyyy" | ||
8412 | + | ||
8413 | + activeCoupons.sort(by: { | ||
8414 | + let date1 = dateFormatter.date(from: $0.expiration ?? "") | ||
8415 | + let date2 = dateFormatter.date(from: $1.expiration ?? "") | ||
8416 | + | ||
8417 | + if ((date1 != nil) && (date2 != nil)) { | ||
8418 | + return date1!.compare(date2!) == .orderedAscending | ||
8419 | + } else { | ||
8420 | + return false | ||
8421 | + } | ||
8422 | + | ||
8423 | + }) | ||
8424 | + successCallback(activeCoupons) | ||
8425 | + | ||
8426 | + // successCallback(couponsArray) | ||
8427 | + | ||
8428 | + } else { | ||
8429 | + successCallback(nil) | ||
8430 | + } | ||
8431 | + | ||
8432 | + } else { | ||
8433 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
8434 | + dynatraceEvent._eventName = "custom_error_user_coupons_loyalty" | ||
8435 | + dynatraceEvent._parameters = nil | ||
8436 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
8437 | + | ||
8438 | + successCallback(nil) | ||
8439 | + } | ||
8440 | + | ||
8441 | + } else { | ||
8442 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
8443 | + dynatraceEvent._eventName = "custom_error_user_coupons_loyalty" | ||
8444 | + dynatraceEvent._parameters = nil | ||
8445 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
8446 | + | ||
8447 | + successCallback(nil) | ||
8448 | + } | ||
8449 | + | ||
8450 | + } | ||
8451 | + | ||
8452 | + func getCouponsUniversalFailureCallback(_ error: Error?) -> Void { | ||
8453 | + print("getCouponsUniversal error: ") | ||
8454 | + print(error) | ||
8455 | + print("====================") | ||
8456 | + | ||
8457 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
8458 | + dynatraceEvent._eventName = "custom_error_user_coupons_loyalty" | ||
8459 | + dynatraceEvent._parameters = nil | ||
8460 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
8461 | + | ||
8462 | + // successCallback(nil) | ||
8463 | + if let error = error as? NSError { | ||
8464 | +// if (error.code == 401) { | ||
8465 | +// let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel() | ||
8466 | +// sessionEvent._sessionExpired = true | ||
8467 | +// SwiftEventBus.post("sdk_session_expired", sender: sessionEvent) | ||
8468 | +// } | ||
8469 | + | ||
8470 | + failureCallback(error.code) | ||
8471 | + } else { | ||
8472 | + failureCallback(-1) | ||
8473 | + } | ||
8474 | + } | ||
8475 | + } | ||
8476 | + | ||
8477 | + | ||
8268 | } | 8478 | } | ... | ... |
-
Please register or login to post a comment