Showing
8 changed files
with
167 additions
and
8 deletions
... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
8 | <dict> | 8 | <dict> |
9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
10 | - <integer>1</integer> | 10 | + <integer>0</integer> |
11 | </dict> | 11 | </dict> |
12 | </dict> | 12 | </dict> |
13 | </dict> | 13 | </dict> | ... | ... |
... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
8 | <dict> | 8 | <dict> |
9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
10 | - <integer>0</integer> | 10 | + <integer>1</integer> |
11 | </dict> | 11 | </dict> |
12 | </dict> | 12 | </dict> |
13 | </dict> | 13 | </dict> | ... | ... |
No preview for this file type
... | @@ -81,7 +81,7 @@ | ... | @@ -81,7 +81,7 @@ |
81 | - (NSDictionary*)validateCouponWithCoupon:(NSString*)coupon; | 81 | - (NSDictionary*)validateCouponWithCoupon:(NSString*)coupon; |
82 | - (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket; | 82 | - (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket; |
83 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 83 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
84 | -- (void)getCouponsUniversalAsync:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 84 | +- (void)getCouponsUniversalAsync:(NSString*)language :(NSString*)couponsetType :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
85 | - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 85 | - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
86 | - (void) getAvailableCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 86 | - (void) getAvailableCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
87 | - (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 87 | - (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
... | @@ -1463,10 +1463,10 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; | ... | @@ -1463,10 +1463,10 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; |
1463 | }]; | 1463 | }]; |
1464 | } | 1464 | } |
1465 | 1465 | ||
1466 | -- (void)getCouponsUniversalAsync:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1466 | +- (void)getCouponsUniversalAsync:(NSString*)language :(NSString*)couponsetType :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
1467 | { | 1467 | { |
1468 | 1468 | ||
1469 | - [[Warply sharedService] getCouponsUniversalWithSuccessBlock:language :^(NSDictionary *response) { | 1469 | + [[Warply sharedService] getCouponsUniversalWithSuccessBlock:language :couponsetType :^(NSDictionary *response) { |
1470 | if (success) { | 1470 | if (success) { |
1471 | success(response); | 1471 | success(response); |
1472 | } | 1472 | } | ... | ... |
... | @@ -371,7 +371,7 @@ WL_VERSION_INTERFACE() | ... | @@ -371,7 +371,7 @@ WL_VERSION_INTERFACE() |
371 | 371 | ||
372 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 372 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
373 | 373 | ||
374 | -- (void)getCouponsUniversalWithSuccessBlock:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 374 | +- (void)getCouponsUniversalWithSuccessBlock:(NSString*)language :(NSString*)couponsetType :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
375 | 375 | ||
376 | - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 376 | - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
377 | 377 | ... | ... |
... | @@ -2642,7 +2642,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -2642,7 +2642,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
2642 | }]; | 2642 | }]; |
2643 | } | 2643 | } |
2644 | 2644 | ||
2645 | -- (void)getCouponsUniversalWithSuccessBlock:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 2645 | +- (void)getCouponsUniversalWithSuccessBlock:(NSString*)language :(NSString*)couponsetType :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
2646 | { | 2646 | { |
2647 | // TODO: If pagination is needed in the future create new signature with the extra argument pagination | 2647 | // TODO: If pagination is needed in the future create new signature with the extra argument pagination |
2648 | /* | 2648 | /* |
... | @@ -2665,6 +2665,9 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -2665,6 +2665,9 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
2665 | [couponDictionary setValue:@"user_coupons" forKey:@"action"]; | 2665 | [couponDictionary setValue:@"user_coupons" forKey:@"action"]; |
2666 | [couponDictionary setValue:@[@"merchant"] forKey:@"details"]; | 2666 | [couponDictionary setValue:@[@"merchant"] forKey:@"details"]; |
2667 | [couponDictionary setValue:language forKey:@"language"]; | 2667 | [couponDictionary setValue:language forKey:@"language"]; |
2668 | + if ([couponsetType isEqual: @"supermarket"]) { | ||
2669 | + [couponDictionary setValue:@[@"supermarket"] forKey:@"couponset_types"]; | ||
2670 | + } | ||
2668 | 2671 | ||
2669 | NSMutableDictionary* dataDictionary = [[NSMutableDictionary alloc] init]; | 2672 | NSMutableDictionary* dataDictionary = [[NSMutableDictionary alloc] init]; |
2670 | [dataDictionary setValue:couponDictionary forKey:@"coupon"]; | 2673 | [dataDictionary setValue:couponDictionary forKey:@"coupon"]; | ... | ... |
... | @@ -17,6 +17,7 @@ public struct GlobalVariables { | ... | @@ -17,6 +17,7 @@ public struct GlobalVariables { |
17 | static var boxCoupons: Array<swiftApi.ActiveBoxCouponModel> = [] | 17 | static var boxCoupons: Array<swiftApi.ActiveBoxCouponModel> = [] |
18 | static var couponList: Array<swiftApi.CouponItemModel> = [] | 18 | static var couponList: Array<swiftApi.CouponItemModel> = [] |
19 | static var oldCouponList: Array<swiftApi.CouponItemModel> = [] | 19 | static var oldCouponList: Array<swiftApi.CouponItemModel> = [] |
20 | + static var smCouponList: Array<swiftApi.CouponItemModel> = [] | ||
20 | static var smOldCouponList: Array<swiftApi.CouponItemModel> = [] | 21 | static var smOldCouponList: Array<swiftApi.CouponItemModel> = [] |
21 | static var allOldCouponList: Array<swiftApi.CouponItemModel> = [] | 22 | static var allOldCouponList: Array<swiftApi.CouponItemModel> = [] |
22 | static var couponSetList: Array<swiftApi.CouponSetItemModel> = [] | 23 | static var couponSetList: Array<swiftApi.CouponSetItemModel> = [] |
... | @@ -5403,6 +5404,34 @@ public class swiftApi { | ... | @@ -5403,6 +5404,34 @@ public class swiftApi { |
5403 | public func getCouponList() -> Array<CouponItemModel> { | 5404 | public func getCouponList() -> Array<CouponItemModel> { |
5404 | return GlobalVariables.couponList | 5405 | return GlobalVariables.couponList |
5405 | } | 5406 | } |
5407 | + | ||
5408 | + | ||
5409 | + public func setSMCouponList(_ coupons: Array<CouponItemModel>) { | ||
5410 | + // let filteredCoupons = coupons.filter { CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: $0.discount ?? "")) } | ||
5411 | + var activeCoupons = coupons.filter({ return $0.status == 1 }) | ||
5412 | + | ||
5413 | + // sort activeCoupons by expiration date | ||
5414 | + let dateFormatter = DateFormatter() | ||
5415 | + dateFormatter.dateFormat = "dd/MM/yyyy" | ||
5416 | + | ||
5417 | + activeCoupons.sort(by: { | ||
5418 | + let date1 = dateFormatter.date(from: $0.expiration ?? "") | ||
5419 | + let date2 = dateFormatter.date(from: $1.expiration ?? "") | ||
5420 | + | ||
5421 | + if ((date1 != nil) && (date2 != nil)) { | ||
5422 | + return date1!.compare(date2!) == .orderedAscending | ||
5423 | + } else { | ||
5424 | + return false | ||
5425 | + } | ||
5426 | + | ||
5427 | + }) | ||
5428 | + GlobalVariables.smCouponList = activeCoupons | ||
5429 | + } | ||
5430 | + | ||
5431 | + | ||
5432 | + public func getSMCouponList() -> Array<CouponItemModel> { | ||
5433 | + return GlobalVariables.smCouponList | ||
5434 | + } | ||
5406 | 5435 | ||
5407 | 5436 | ||
5408 | public func setOldCouponList(_ coupons: Array<CouponItemModel>) { | 5437 | public func setOldCouponList(_ coupons: Array<CouponItemModel>) { |
... | @@ -8305,6 +8334,37 @@ public class swiftApi { | ... | @@ -8305,6 +8334,37 @@ public class swiftApi { |
8305 | func getUnifiedCouponsCallback (_ couponsData: Array<swiftApi.UnifiedCouponModel>?) -> Void { | 8334 | func getUnifiedCouponsCallback (_ couponsData: Array<swiftApi.UnifiedCouponModel>?) -> Void { |
8306 | if (couponsData != nil) { | 8335 | if (couponsData != nil) { |
8307 | DispatchQueue.main.async { | 8336 | DispatchQueue.main.async { |
8337 | + var usedCouponsArray:Array<CouponItemModel> = [] | ||
8338 | + | ||
8339 | + if let uniCouponsData = couponsData { | ||
8340 | + for unifiedCoupon in uniCouponsData { | ||
8341 | + for usedCoupon in unifiedCoupon._coupons { | ||
8342 | + usedCouponsArray.append(usedCoupon) | ||
8343 | + } | ||
8344 | + } | ||
8345 | + } | ||
8346 | + | ||
8347 | + swiftApi().getSMCouponsUniversalAsync(language: "el", getSMCouponsCallback, failureCallback: failureCallback) | ||
8348 | + | ||
8349 | + func getSMCouponsCallback (_ smCouponsData: Array<swiftApi.CouponItemModel>?) -> Void { | ||
8350 | + if (smCouponsData != nil) { | ||
8351 | + DispatchQueue.main.async { | ||
8352 | + var notUsedCouponsArray:Array<CouponItemModel> = [] | ||
8353 | + if let tempSMCouponsData = smCouponsData { | ||
8354 | + for smCoupon in tempSMCouponsData { | ||
8355 | + if (!usedCouponsArray.contains { $0.coupon == smCoupon.coupon }) { | ||
8356 | + notUsedCouponsArray.append(smCoupon) | ||
8357 | + } | ||
8358 | + } | ||
8359 | + } | ||
8360 | + | ||
8361 | + swiftApi().setSMCouponList(notUsedCouponsArray) | ||
8362 | + SwiftEventBus.post("sm_coupons_fetched") | ||
8363 | + } | ||
8364 | + } else { | ||
8365 | + } | ||
8366 | + } | ||
8367 | + | ||
8308 | // self.matchOldSMCoupons() | 8368 | // self.matchOldSMCoupons() |
8309 | SwiftEventBus.post("unified_coupons_fetched") | 8369 | SwiftEventBus.post("unified_coupons_fetched") |
8310 | successCallback(couponsData) | 8370 | successCallback(couponsData) |
... | @@ -8575,7 +8635,7 @@ public class swiftApi { | ... | @@ -8575,7 +8635,7 @@ public class swiftApi { |
8575 | public func getCouponsUniversalAsync(language: String, _ successCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | 8635 | public func getCouponsUniversalAsync(language: String, _ successCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { |
8576 | 8636 | ||
8577 | let instanceOfMyApi = MyApi() | 8637 | let instanceOfMyApi = MyApi() |
8578 | - instanceOfMyApi.getCouponsUniversalAsync(language, getCouponsUniversalCallback, failureBlock: getCouponsUniversalFailureCallback) | 8638 | + instanceOfMyApi.getCouponsUniversalAsync(language, "", getCouponsUniversalCallback, failureBlock: getCouponsUniversalFailureCallback) |
8579 | 8639 | ||
8580 | func getCouponsUniversalCallback(_ responseData: [AnyHashable: Any]?) -> Void { | 8640 | func getCouponsUniversalCallback(_ responseData: [AnyHashable: Any]?) -> Void { |
8581 | var couponsArray:Array<CouponItemModel> = [] | 8641 | var couponsArray:Array<CouponItemModel> = [] |
... | @@ -8676,6 +8736,102 @@ public class swiftApi { | ... | @@ -8676,6 +8736,102 @@ public class swiftApi { |
8676 | } | 8736 | } |
8677 | } | 8737 | } |
8678 | 8738 | ||
8739 | + public func getSMCouponsUniversalAsync(language: String, _ successCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | ||
8740 | + | ||
8741 | + let instanceOfMyApi = MyApi() | ||
8742 | + instanceOfMyApi.getCouponsUniversalAsync(language, "supermarket", getCouponsUniversalCallback, failureBlock: getCouponsUniversalFailureCallback) | ||
8743 | + | ||
8744 | + func getCouponsUniversalCallback(_ responseData: [AnyHashable: Any]?) -> Void { | ||
8745 | + var couponsArray:Array<CouponItemModel> = [] | ||
8746 | + | ||
8747 | + if let responseDataDictionary = responseData as? [String: AnyObject] { | ||
8748 | + | ||
8749 | + if (responseDataDictionary["status"] as? Int == 1) { | ||
8750 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
8751 | + dynatraceEvent._eventName = "custom_success_user_sm_coupons_loyalty" | ||
8752 | + dynatraceEvent._parameters = nil | ||
8753 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
8754 | + | ||
8755 | + if let responseDataResult = responseDataDictionary["result"] as? [[String : Any]?] { | ||
8756 | + for coupon in responseDataResult { | ||
8757 | + if let couponDictionary = coupon { | ||
8758 | + let tempCoupon = CouponItemModel(dictionary: couponDictionary) | ||
8759 | + couponsArray.append(tempCoupon) | ||
8760 | + } | ||
8761 | + } | ||
8762 | + | ||
8763 | + swiftApi().setSMOldCouponList(couponsArray) | ||
8764 | + // swiftApi().setSMCouponList(couponsArray) | ||
8765 | + | ||
8766 | + var activeCoupons = couponsArray.filter({ return $0.status == 1 }) | ||
8767 | + // sort activeCoupons by expiration date | ||
8768 | + let dateFormatter = DateFormatter() | ||
8769 | + dateFormatter.dateFormat = "dd/MM/yyyy" | ||
8770 | + | ||
8771 | + activeCoupons.sort(by: { | ||
8772 | + let date1 = dateFormatter.date(from: $0.expiration ?? "") | ||
8773 | + let date2 = dateFormatter.date(from: $1.expiration ?? "") | ||
8774 | + | ||
8775 | + if ((date1 != nil) && (date2 != nil)) { | ||
8776 | + return date1!.compare(date2!) == .orderedAscending | ||
8777 | + } else { | ||
8778 | + return false | ||
8779 | + } | ||
8780 | + | ||
8781 | + }) | ||
8782 | + | ||
8783 | + // returns ALL active SM coupons (used and unused) | ||
8784 | + successCallback(activeCoupons) | ||
8785 | + | ||
8786 | + } else { | ||
8787 | + successCallback(nil) | ||
8788 | + } | ||
8789 | + | ||
8790 | + } else { | ||
8791 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
8792 | + dynatraceEvent._eventName = "custom_error_user_sm_coupons_loyalty" | ||
8793 | + dynatraceEvent._parameters = nil | ||
8794 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
8795 | + | ||
8796 | + successCallback(nil) | ||
8797 | + } | ||
8798 | + | ||
8799 | + } else { | ||
8800 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
8801 | + dynatraceEvent._eventName = "custom_error_user_sm_coupons_loyalty" | ||
8802 | + dynatraceEvent._parameters = nil | ||
8803 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
8804 | + | ||
8805 | + successCallback(nil) | ||
8806 | + } | ||
8807 | + | ||
8808 | + } | ||
8809 | + | ||
8810 | + func getCouponsUniversalFailureCallback(_ error: Error?) -> Void { | ||
8811 | + print("getSMCouponsUniversal error: ") | ||
8812 | + print(error) | ||
8813 | + print("====================") | ||
8814 | + | ||
8815 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
8816 | + dynatraceEvent._eventName = "custom_error_user_sm_coupons_loyalty" | ||
8817 | + dynatraceEvent._parameters = nil | ||
8818 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
8819 | + | ||
8820 | + // successCallback(nil) | ||
8821 | + if let error = error as? NSError { | ||
8822 | +// if (error.code == 401) { | ||
8823 | +// let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel() | ||
8824 | +// sessionEvent._sessionExpired = true | ||
8825 | +// SwiftEventBus.post("sdk_session_expired", sender: sessionEvent) | ||
8826 | +// } | ||
8827 | + | ||
8828 | + failureCallback(error.code) | ||
8829 | + } else { | ||
8830 | + failureCallback(-1) | ||
8831 | + } | ||
8832 | + } | ||
8833 | + } | ||
8834 | + | ||
8679 | 8835 | ||
8680 | public class ActiveBoxCouponModel { | 8836 | public class ActiveBoxCouponModel { |
8681 | private var value: String | 8837 | private var value: String | ... | ... |
-
Please register or login to post a comment