Showing
5 changed files
with
239 additions
and
0 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)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
| 83 | - (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(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; |
| 84 | - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; | 85 | - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; |
| 85 | - (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 86 | - (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(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)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
| 1454 | +{ | ||
| 1455 | + | ||
| 1456 | + [[Warply sharedService] getUnifiedCouponsWithSuccessBlock:^(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) getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1467 | - (void) getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
| 1454 | { | 1468 | { |
| 1455 | [[Warply sharedService] getCouponSetsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) { | 1469 | [[Warply sharedService] getCouponSetsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) { | ... | ... |
| ... | @@ -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)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
| 373 | + | ||
| 372 | - (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 374 | - (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
| 373 | 375 | ||
| 374 | - (void)getPointsHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 376 | - (void)getPointsHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
| ... | @@ -2566,6 +2566,64 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -2566,6 +2566,64 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 2566 | }]; | 2566 | }]; |
| 2567 | } | 2567 | } |
| 2568 | 2568 | ||
| 2569 | +- (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
| 2570 | +{ | ||
| 2571 | + NSMutableDictionary* data = [[NSMutableDictionary alloc] init]; | ||
| 2572 | + [data setValue:@"retrieve_unified_coupons" forKey:@"action"]; | ||
| 2573 | + [data setValue:LANG forKey:@"language"]; | ||
| 2574 | + | ||
| 2575 | + NSMutableDictionary* postDictionary = [[NSMutableDictionary alloc] init]; | ||
| 2576 | + [postDictionary setValue:data forKey:@"coupon"]; | ||
| 2577 | + | ||
| 2578 | +// NSDictionary *postDictionary = @{@"coupon":@{@"action": @"get_user_coupons", @"fetch_data": @[@"transaction",@"communication"]}}; | ||
| 2579 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
| 2580 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
| 2581 | + if (success) { | ||
| 2582 | + success(contextResponse); | ||
| 2583 | + } | ||
| 2584 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
| 2585 | + NSLog(@"%@", contextResponse ); | ||
| 2586 | + } failureBlock:^(NSError *error) { | ||
| 2587 | + if (failure) { | ||
| 2588 | + NSDictionary* dict = [NSDictionary alloc]; | ||
| 2589 | + dict = [error userInfo]; | ||
| 2590 | + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"]; | ||
| 2591 | + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) { | ||
| 2592 | + | ||
| 2593 | +// NSString* errorDomain = [error domain]; | ||
| 2594 | +// NSError *errorToken = [NSError errorWithDomain:errorDomain code:401 userInfo:dict]; | ||
| 2595 | +// | ||
| 2596 | +// if (failure) { | ||
| 2597 | +// failure(errorToken); | ||
| 2598 | +// } | ||
| 2599 | + | ||
| 2600 | + [self refreshToken:^(NSDictionary *response) { | ||
| 2601 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
| 2602 | + if (success) { | ||
| 2603 | + success(contextResponse); | ||
| 2604 | + } | ||
| 2605 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
| 2606 | + NSLog(@"%@", contextResponse ); | ||
| 2607 | + } failureBlock:^(NSError *error) { | ||
| 2608 | + if (failure) { | ||
| 2609 | + failure(error); | ||
| 2610 | + } | ||
| 2611 | + }]; | ||
| 2612 | + } failureBlock:^(NSError *error) { | ||
| 2613 | + if (failure) { | ||
| 2614 | + // [_db executeUpdate:@"DROP TABLE requestVariables"]; | ||
| 2615 | + failure(error); | ||
| 2616 | + } | ||
| 2617 | + NSLog(@"Error at token %@", error ); | ||
| 2618 | + }]; | ||
| 2619 | + } else { | ||
| 2620 | + NSLog(@"Error at get unified coupons %@", error ); | ||
| 2621 | + failure(error); | ||
| 2622 | + } | ||
| 2623 | + } | ||
| 2624 | + }]; | ||
| 2625 | +} | ||
| 2626 | + | ||
| 2569 | - (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 2627 | - (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
| 2570 | { | 2628 | { |
| 2571 | NSDictionary *postDictionary = @{@"consumer_data": @{@"action": @"get_transaction_history", @"product_detail": @"minimal"}}; | 2629 | NSDictionary *postDictionary = @{@"consumer_data": @{@"action": @"get_transaction_history", @"product_detail": @"minimal"}}; | ... | ... |
| ... | @@ -17,6 +17,7 @@ public struct GlobalVariables { | ... | @@ -17,6 +17,7 @@ public struct GlobalVariables { |
| 17 | static var couponList: Array<swiftApi.CouponItemModel> = [] | 17 | static var couponList: Array<swiftApi.CouponItemModel> = [] |
| 18 | static var oldCouponList: Array<swiftApi.CouponItemModel> = [] | 18 | static var oldCouponList: Array<swiftApi.CouponItemModel> = [] |
| 19 | static var couponSetList: Array<swiftApi.CouponSetItemModel> = [] | 19 | static var couponSetList: Array<swiftApi.CouponSetItemModel> = [] |
| 20 | + static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = [] | ||
| 20 | static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel() | 21 | static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel() |
| 21 | static var consumer: swiftApi.ProfileModel? | 22 | static var consumer: swiftApi.ProfileModel? |
| 22 | static var consumerInternal: swiftApi.ProfileModel? | 23 | static var consumerInternal: swiftApi.ProfileModel? |
| ... | @@ -142,6 +143,16 @@ public class swiftApi { | ... | @@ -142,6 +143,16 @@ public class swiftApi { |
| 142 | } | 143 | } |
| 143 | 144 | ||
| 144 | 145 | ||
| 146 | + public func setUnifiedCouponList(_ unifiedCoupons: Array<UnifiedCouponModel>) { | ||
| 147 | + GlobalVariables.unifiedCouponList = unifiedCoupons | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + | ||
| 151 | + public func getUnifiedCouponList() -> Array<UnifiedCouponModel> { | ||
| 152 | + return GlobalVariables.unifiedCouponList | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + | ||
| 145 | public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { | 156 | public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { |
| 146 | 157 | ||
| 147 | if (GlobalVariables.trackingStepsEnabled == false) { | 158 | if (GlobalVariables.trackingStepsEnabled == false) { |
| ... | @@ -6751,5 +6762,158 @@ public class swiftApi { | ... | @@ -6751,5 +6762,158 @@ public class swiftApi { |
| 6751 | } | 6762 | } |
| 6752 | } | 6763 | } |
| 6753 | 6764 | ||
| 6765 | + public class UnifiedCouponModel { | ||
| 6766 | + private var barcode: String? | ||
| 6767 | + private var code: Int? | ||
| 6768 | + private var coupons: Array<CouponItemModel>? | ||
| 6769 | + private var created: String? | ||
| 6770 | + | ||
| 6771 | + public init() { | ||
| 6772 | + self.barcode = "" | ||
| 6773 | + self.code = 0 | ||
| 6774 | + self.coupons = [] | ||
| 6775 | + self.created = "" | ||
| 6776 | + } | ||
| 6777 | + | ||
| 6778 | + public init(dictionary: [String: Any]) { | ||
| 6779 | + self.barcode = dictionary["barcode"] as? String? ?? "" | ||
| 6780 | + self.code = dictionary["code"] as? Int? ?? 0 | ||
| 6781 | + | ||
| 6782 | + if let couponsData = dictionary["coupons"] as? [[String : Any]?] { | ||
| 6783 | + var couponsArray:Array<CouponItemModel> = [] | ||
| 6784 | + for item in couponsData { | ||
| 6785 | + if let itemDictionary = item { | ||
| 6786 | + let tempCoupon = CouponItemModel(dictionary: itemDictionary) | ||
| 6787 | + couponsArray.append(tempCoupon) | ||
| 6788 | + } | ||
| 6789 | + } | ||
| 6790 | + self.coupons = couponsArray | ||
| 6791 | + } else { | ||
| 6792 | + self.coupons = [] | ||
| 6793 | + } | ||
| 6794 | + | ||
| 6795 | + // Example "created":"Mon, 03 Apr 2023 15:05:14 GMT" | ||
| 6796 | + let dateString = dictionary["created"] as? String? ?? "" | ||
| 6797 | + let dateFormatter = DateFormatter() | ||
| 6798 | + dateFormatter.locale = Locale(identifier: "en_US_POSSIX") | ||
| 6799 | + dateFormatter.dateFormat = "E, MMM dd yyyy HH:mm:ss" | ||
| 6800 | + if let date = dateFormatter.date(from: dateString ?? "") { | ||
| 6801 | + dateFormatter.dateFormat = "dd/MM/yyyy" | ||
| 6802 | + let resultString = dateFormatter.string(from: date) | ||
| 6803 | + self.created = resultString | ||
| 6804 | + } else { | ||
| 6805 | + self.created = "" | ||
| 6806 | + } | ||
| 6807 | + | ||
| 6808 | + } | ||
| 6809 | + | ||
| 6810 | + public var _barcode: String { | ||
| 6811 | + get { // getter | ||
| 6812 | + return self.barcode ?? "" | ||
| 6813 | + } | ||
| 6814 | + set(newValue) { //setter | ||
| 6815 | + self.barcode = newValue | ||
| 6816 | + } | ||
| 6817 | + } | ||
| 6818 | + | ||
| 6819 | + public var _code: Int { | ||
| 6820 | + get { // getter | ||
| 6821 | + return self.code ?? 0 | ||
| 6822 | + } | ||
| 6823 | + set(newValue) { //setter | ||
| 6824 | + self.code = newValue | ||
| 6825 | + } | ||
| 6826 | + } | ||
| 6827 | + | ||
| 6828 | + public var _coupons: Array<CouponItemModel> { | ||
| 6829 | + get { // getter | ||
| 6830 | + return self.coupons ?? [] | ||
| 6831 | + } | ||
| 6832 | + set(newValue) { //setter | ||
| 6833 | + self.coupons = newValue | ||
| 6834 | + } | ||
| 6835 | + } | ||
| 6836 | + | ||
| 6837 | + public var _created: String { | ||
| 6838 | + get { // getter | ||
| 6839 | + return self.created ?? "" | ||
| 6840 | + } | ||
| 6841 | + set(newValue) { //setter | ||
| 6842 | + self.created = newValue | ||
| 6843 | + } | ||
| 6844 | + } | ||
| 6845 | + } | ||
| 6846 | + | ||
| 6847 | + | ||
| 6848 | + public func getUnifiedCouponsAsync(_ successCallback: @escaping (_ responseData: Array<UnifiedCouponModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | ||
| 6849 | + let instanceOfMyApi = MyApi() | ||
| 6850 | + instanceOfMyApi.getUnifiedCouponsAsync(getUnifiedCallback, failureBlock: getUnifiedFailureCallback) | ||
| 6851 | + | ||
| 6852 | + | ||
| 6853 | + func getUnifiedCallback(_ responseData: [AnyHashable: Any]?) -> Void { | ||
| 6854 | + var unifiedCouponsArray:Array<UnifiedCouponModel> = [] | ||
| 6855 | + | ||
| 6856 | + if let responseDataDictionary = responseData as? [String: AnyObject] { | ||
| 6857 | + | ||
| 6858 | + if (responseDataDictionary["status"] as? Int == 1) { | ||
| 6859 | +// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 6860 | +// dynatraceEvent._eventName = "custom_success_campaigns_loyalty" | ||
| 6861 | +// dynatraceEvent._parameters = nil | ||
| 6862 | +// SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 6863 | + | ||
| 6864 | + if let responseDataResult = responseDataDictionary["result"] as? [String: Any] { | ||
| 6865 | + if let responseDataCoupons = responseDataResult["coupons"] as? [[String : Any]?] { | ||
| 6866 | + | ||
| 6867 | + for item in responseDataCoupons { | ||
| 6868 | + if let itemDictionary = item { | ||
| 6869 | + if let itemDictionaryStauts = itemDictionary["status"] as? String { | ||
| 6870 | + if (itemDictionaryStauts == "active") { | ||
| 6871 | + let tempCampaign = UnifiedCouponModel(dictionary: itemDictionary) | ||
| 6872 | + unifiedCouponsArray.append(tempCampaign) | ||
| 6873 | + } | ||
| 6874 | + } | ||
| 6875 | + } | ||
| 6876 | + } | ||
| 6877 | + | ||
| 6878 | + swiftApi().setUnifiedCouponList(unifiedCouponsArray) | ||
| 6879 | + successCallback(unifiedCouponsArray) | ||
| 6880 | + } | ||
| 6881 | + } else { | ||
| 6882 | + successCallback(nil) | ||
| 6883 | + } | ||
| 6884 | + | ||
| 6885 | + } else { | ||
| 6886 | +// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 6887 | +// dynatraceEvent._eventName = "custom_error_campaigns_loyalty" | ||
| 6888 | +// dynatraceEvent._parameters = nil | ||
| 6889 | +// SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 6890 | + | ||
| 6891 | + successCallback(nil) | ||
| 6892 | + } | ||
| 6893 | + | ||
| 6894 | + } else { | ||
| 6895 | +// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 6896 | +// dynatraceEvent._eventName = "custom_error_campaigns_loyalty" | ||
| 6897 | +// dynatraceEvent._parameters = nil | ||
| 6898 | +// SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 6899 | + | ||
| 6900 | + successCallback(nil) | ||
| 6901 | + } | ||
| 6902 | + } | ||
| 6903 | + | ||
| 6904 | + func getUnifiedFailureCallback(_ error: Error?) -> Void { | ||
| 6905 | + print("getUnifiedCouponsAsync error: ") | ||
| 6906 | + print(error) | ||
| 6907 | + print("====================") | ||
| 6908 | + | ||
| 6909 | +// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 6910 | +// dynatraceEvent._eventName = "custom_error_campaigns_loyalty" | ||
| 6911 | +// dynatraceEvent._parameters = nil | ||
| 6912 | +// SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 6913 | + | ||
| 6914 | + successCallback(nil) | ||
| 6915 | + } | ||
| 6916 | + } | ||
| 6917 | + | ||
| 6754 | 6918 | ||
| 6755 | } | 6919 | } | ... | ... |
-
Please register or login to post a comment