Manos Chorianopoulos

add createUnifiedCouponAsync request

...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
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 :(NSString*)couponsetType :(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) createUnifiedCouponAsync:(NSArray*)couponCodes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
85 - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 86 - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
86 - (void) getAvailableCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 87 - (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; 88 - (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -1477,6 +1477,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; ...@@ -1477,6 +1477,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
1477 }]; 1477 }];
1478 } 1478 }
1479 1479
1480 +- (void) createUnifiedCouponAsync:(NSArray*)couponCodes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1481 +{
1482 +
1483 + [[Warply sharedService] createUnifiedCouponWithSuccessBlock:couponCodes :^(NSDictionary *response) {
1484 + if (success) {
1485 + success(response);
1486 + }
1487 + } failureBlock:^(NSError *error) {
1488 + if (failure) {
1489 + failure(error);
1490 + }
1491 + }];
1492 +}
1493 +
1480 - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 1494 - (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1481 { 1495 {
1482 1496
......
...@@ -373,6 +373,8 @@ WL_VERSION_INTERFACE() ...@@ -373,6 +373,8 @@ WL_VERSION_INTERFACE()
373 373
374 - (void)getCouponsUniversalWithSuccessBlock:(NSString*)language :(NSString*)couponsetType :(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)createUnifiedCouponWithSuccessBlock:(NSArray*)couponCodes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
377 +
376 - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 378 - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
377 379
378 - (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 380 - (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -2721,6 +2721,75 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -2721,6 +2721,75 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
2721 }]; 2721 }];
2722 } 2722 }
2723 2723
2724 +- (void)createUnifiedCouponWithSuccessBlock:(NSArray*)couponCodes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
2725 +{
2726 + /*
2727 + {
2728 + "coupon": {
2729 + "action": "unify_coupons",
2730 + "coupon_codes":[
2731 + "...", "..."
2732 + ]
2733 + }
2734 + }
2735 + */
2736 +
2737 + NSMutableDictionary* couponDictionary = [[NSMutableDictionary alloc] init];
2738 + [couponDictionary setValue:@"unify_coupons" forKey:@"action"];
2739 + [couponDictionary setValue:couponCodes forKey:@"coupon_codes"];
2740 +
2741 + NSMutableDictionary* dataDictionary = [[NSMutableDictionary alloc] init];
2742 + [dataDictionary setValue:couponDictionary forKey:@"coupon"];
2743 +
2744 + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataDictionary options:0 error:NULL];
2745 +
2746 + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
2747 + if (success) {
2748 + success(contextResponse);
2749 + }
2750 + NSLog(@"**************** WARPLY Response *****************" );
2751 + NSLog(@"%@", contextResponse );
2752 + } failureBlock:^(NSError *error) {
2753 + if (failure) {
2754 + NSDictionary* dict = [NSDictionary alloc];
2755 + dict = [error userInfo];
2756 + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
2757 + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
2758 +
2759 +// NSString* errorDomain = [error domain];
2760 +// NSError *errorToken = [NSError errorWithDomain:errorDomain code:401 userInfo:dict];
2761 +//
2762 +// if (failure) {
2763 +// failure(errorToken);
2764 +// }
2765 +
2766 + [self refreshToken:^(NSDictionary *response) {
2767 + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
2768 + if (success) {
2769 + success(contextResponse);
2770 + }
2771 + NSLog(@"**************** WARPLY Response *****************" );
2772 + NSLog(@"%@", contextResponse );
2773 + } failureBlock:^(NSError *error) {
2774 + if (failure) {
2775 + failure(error);
2776 + }
2777 + }];
2778 + } failureBlock:^(NSError *error) {
2779 + if (failure) {
2780 + // [_db executeUpdate:@"DROP TABLE requestVariables"];
2781 + failure(error);
2782 + }
2783 + NSLog(@"Error at token %@", error );
2784 + }];
2785 + } else {
2786 + NSLog(@"Error at createUnifiedCoupon %@", error );
2787 + failure(error);
2788 + }
2789 + }
2790 + }];
2791 +}
2792 +
2724 - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 2793 - (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
2725 { 2794 {
2726 NSMutableDictionary* data = [[NSMutableDictionary alloc] init]; 2795 NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
......
...@@ -8833,6 +8833,85 @@ public class swiftApi { ...@@ -8833,6 +8833,85 @@ public class swiftApi {
8833 } 8833 }
8834 8834
8835 8835
8836 + public func createUnifiedCouponAsync(couponCodes: Array<String>, _ successCallback: @escaping (_ responseData: GenericResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
8837 +
8838 + let instanceOfMyApi = MyApi()
8839 + instanceOfMyApi.createUnifiedCouponAsync(couponCodes, requestCallback, failureBlock: requestFailureCallback)
8840 +
8841 + func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
8842 +
8843 + if let responseDataDictionary = responseData as? [String: Any] {
8844 +
8845 + let tempResponse = GenericResponseModel(dictionary: responseDataDictionary)
8846 +
8847 + if (tempResponse != nil) {
8848 + DispatchQueue.main.async {
8849 + if (tempResponse.getStatus == 1) {
8850 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8851 + dynatraceEvent._eventName = "custom_success_create_unified_loyalty"
8852 + dynatraceEvent._parameters = nil
8853 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8854 +
8855 + swiftApi().getUnifiedCouponsDeals { unifiedCoupons in
8856 +
8857 + } failureCallback: { errorCode in
8858 +
8859 + }
8860 +
8861 +
8862 + } else {
8863 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8864 + dynatraceEvent._eventName = "custom_error_create_unified_loyalty"
8865 + dynatraceEvent._parameters = nil
8866 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8867 +
8868 + }
8869 + }
8870 + } else {
8871 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8872 + dynatraceEvent._eventName = "custom_error_create_unified_loyalty"
8873 + dynatraceEvent._parameters = nil
8874 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8875 + }
8876 +
8877 + successCallback(tempResponse);
8878 +
8879 + } else {
8880 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8881 + dynatraceEvent._eventName = "custom_error_create_unified_loyalty"
8882 + dynatraceEvent._parameters = nil
8883 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8884 +
8885 + successCallback(nil)
8886 + }
8887 +
8888 + }
8889 +
8890 + func requestFailureCallback(_ error: Error?) -> Void {
8891 + print("CreateUnifiedCoupon error: ")
8892 + print(error)
8893 + print("====================")
8894 +
8895 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
8896 + dynatraceEvent._eventName = "custom_error_create_unified_loyalty"
8897 + dynatraceEvent._parameters = nil
8898 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
8899 +
8900 + if let error = error as? NSError {
8901 +// if (error.code == 401) {
8902 +// let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel()
8903 +// sessionEvent._sessionExpired = true
8904 +// SwiftEventBus.post("sdk_session_expired", sender: sessionEvent)
8905 +// }
8906 +
8907 + failureCallback(error.code)
8908 + } else {
8909 + failureCallback(-1)
8910 + }
8911 + }
8912 + }
8913 +
8914 +
8836 public class ActiveBoxCouponModel { 8915 public class ActiveBoxCouponModel {
8837 private var value: String 8916 private var value: String
8838 private var code: String 8917 private var code: String
......