Manos Chorianopoulos

add getCouponSetsDealsAsync request

...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
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)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;
85 +- (void)getCouponsetsDealsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
85 - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; 86 - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
86 - (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 87 - (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
87 - (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 88 - (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -1477,6 +1477,19 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; ...@@ -1477,6 +1477,19 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
1477 }]; 1477 }];
1478 } 1478 }
1479 1479
1480 +- (void) getCouponsetsDealsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1481 +{
1482 + [[Warply sharedService] getCouponSetsDealsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) {
1483 + if (success) {
1484 + success(response);
1485 + }
1486 + } failureBlock:^(NSError *error) {
1487 + if (failure) {
1488 + failure(error);
1489 + }
1490 + }];
1491 +}
1492 +
1480 - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure 1493 - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure
1481 { 1494 {
1482 [[Warply sharedService] getInbox2WithSuccessBlock :^(NSArray *inbox) { 1495 [[Warply sharedService] getInbox2WithSuccessBlock :^(NSArray *inbox) {
......
...@@ -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) getCouponSetsDealsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
407 +
406 - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 408 - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
407 409
408 - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(NSString*)user_msisdn :(NSString*)businessService :(NSString*)offerName :(NSString*)productType :(NSString*)provDuration :(NSString*)noOfRecurrance :(NSString*)price :(NSString*)discount :(NSString*)voiceCategory :(NSString*)dataCategory :(NSString*)minsValue :(NSString*)dataValue :(NSString*)provStepValueMins :(NSString*)OfferAudienceLevel :(NSString*)UACIOfferTrackingCode :(NSString*)OFFERCODE1 :(NSString*)SCORE :(NSString*)ZONE :(NSString*)WAVE :(NSString*)VALIDITY :(NSString*)TREATMENT_CODE :(NSString*)ccms_session_id :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 410 - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(NSString*)user_msisdn :(NSString*)businessService :(NSString*)offerName :(NSString*)productType :(NSString*)provDuration :(NSString*)noOfRecurrance :(NSString*)price :(NSString*)discount :(NSString*)voiceCategory :(NSString*)dataCategory :(NSString*)minsValue :(NSString*)dataValue :(NSString*)provStepValueMins :(NSString*)OfferAudienceLevel :(NSString*)UACIOfferTrackingCode :(NSString*)OFFERCODE1 :(NSString*)SCORE :(NSString*)ZONE :(NSString*)WAVE :(NSString*)VALIDITY :(NSString*)TREATMENT_CODE :(NSString*)ccms_session_id :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -3320,6 +3320,68 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -3320,6 +3320,68 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
3320 }]; 3320 }];
3321 } 3321 }
3322 3322
3323 +- (void) getCouponSetsDealsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
3324 +{
3325 + NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
3326 +
3327 + [data setValue:active forKey:@"active"];
3328 + [data setValue:@"retrieve_multilingual" forKey:@"action"];
3329 + [data setValue:visible forKey:@"visible"];
3330 + [data setValue:LANG forKey:@"language"];
3331 + if (uuids && [uuids count] > 0) {
3332 + [data setValue:uuids forKey:@"uuids"];
3333 + }
3334 + [data setValue:@[@"supermarket"] forKey:@"couponset_types"];
3335 + NSMutableDictionary* dataCoupons = [[NSMutableDictionary alloc] init];
3336 + [dataCoupons setValue:data forKey:@"coupon"];
3337 + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataCoupons options:0 error:NULL];
3338 + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
3339 + if (success) {
3340 + success(contextResponse);
3341 + }
3342 + NSLog(@"**************** WARPLY Response *****************" );
3343 + NSLog(@"%@", contextResponse );
3344 + } failureBlock:^(NSError *error) {
3345 + if (failure) {
3346 + NSDictionary* dict = [NSDictionary alloc];
3347 + dict = [error userInfo];
3348 + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
3349 + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
3350 +
3351 +// NSString* errorDomain = [error domain];
3352 +// NSError *errorToken = [NSError errorWithDomain:errorDomain code:401 userInfo:dict];
3353 +//
3354 +// if (failure) {
3355 +// failure(errorToken);
3356 +// }
3357 +
3358 + [self refreshToken:^(NSDictionary *response) {
3359 + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
3360 + if (success) {
3361 + success(contextResponse);
3362 + }
3363 + NSLog(@"**************** WARPLY Response *****************" );
3364 + NSLog(@"%@", contextResponse );
3365 + } failureBlock:^(NSError *error) {
3366 + if (failure) {
3367 + failure(error);
3368 + }
3369 + }];
3370 + } failureBlock:^(NSError *error) {
3371 + if (failure) {
3372 + // [_db executeUpdate:@"DROP TABLE requestVariables"];
3373 + failure(error);
3374 + }
3375 + NSLog(@"Error at token %@", error );
3376 + }];
3377 + } else {
3378 + NSLog(@"Error at get couponset deals %@", error );
3379 + failure(error);
3380 + }
3381 + }
3382 + }];
3383 +}
3384 +
3323 - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 3385 - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
3324 { 3386 {
3325 NSDictionary *postDictionary = @{@"coupon": @{@"action": @"retrieve_coupon", @"coupon_set": uuid, @"communication_uuid": communication_uuid}}; 3387 NSDictionary *postDictionary = @{@"coupon": @{@"action": @"retrieve_coupon", @"coupon_set": uuid, @"communication_uuid": communication_uuid}};
......
...@@ -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 couponsetsDealsList: Array<swiftApi.CouponSetItemModel> = [] // Supermarket couponsets
20 static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = [] 21 static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = []
21 static var oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = [] 22 static var oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = []
22 static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel() 23 static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel()
...@@ -591,6 +592,76 @@ public class swiftApi { ...@@ -591,6 +592,76 @@ public class swiftApi {
591 return CouponSetsDataModel().getData 592 return CouponSetsDataModel().getData
592 } 593 }
593 594
595 + public func getCouponSetsDealsAsync(_ getCouponSetsCallback: @escaping (_ couponSetsData: Array<CouponSetItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
596 +
597 + let instanceOfMyApi = MyApi()
598 + var couponSets: [AnyHashable : Any]?
599 + var couponSetsArray:Array<CouponSetItemModel> = []
600 +
601 + instanceOfMyApi.getCouponsetsDealsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback)
602 +
603 + func couponSetsCallback(_ couponSetsData: [AnyHashable : Any]?) -> Void {
604 +
605 + if let responseDataDictionary = couponSetsData as? [String : AnyObject] {
606 + if (responseDataDictionary["status"] as? Int == 1) {
607 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
608 + dynatraceEvent._eventName = "custom_success_couponset_sm_loyalty"
609 + dynatraceEvent._parameters = nil
610 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
611 +
612 + if let responseDataResult = responseDataDictionary["result"] as? [[String : Any]?] {
613 +
614 + for couponset in responseDataResult {
615 + let tempCouponset = CouponSetItemModel(dictionary: couponset ?? [String : Any]())
616 + couponSetsArray.append(tempCouponset)
617 + }
618 + } else {
619 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
620 + dynatraceEvent._eventName = "custom_error_couponset_sm_loyalty"
621 + dynatraceEvent._parameters = nil
622 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
623 + }
624 +
625 + } else {
626 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
627 + dynatraceEvent._eventName = "custom_error_couponset_sm_loyalty"
628 + dynatraceEvent._parameters = nil
629 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
630 + }
631 +
632 + } else {
633 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
634 + dynatraceEvent._eventName = "custom_error_couponset_sm_loyalty"
635 + dynatraceEvent._parameters = nil
636 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
637 + }
638 +
639 + swiftApi().setCouponSetsDealsList(couponSetsArray)
640 + getCouponSetsCallback(couponSetsArray)
641 + }
642 +
643 + func couponSetsFailureCallback(_ error: Error?) -> Void {
644 + print("getCouponSetsDeals error: ")
645 +
646 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
647 + dynatraceEvent._eventName = "custom_error_couponset_sm_loyalty"
648 + dynatraceEvent._parameters = nil
649 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
650 +
651 + if let error = error as? NSError {
652 + // if (error.code == 401) {
653 + // let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel()
654 + // sessionEvent._sessionExpired = true
655 + // SwiftEventBus.post("sdk_session_expired", sender: sessionEvent)
656 + // }
657 +
658 + failureCallback(error.code)
659 + } else {
660 + failureCallback(-1)
661 + }
662 + }
663 + }
664 +
594 665
595 public class CouponItemModel: Codable { 666 public class CouponItemModel: Codable {
596 public let couponset_uuid: String? 667 public let couponset_uuid: String?
...@@ -4465,6 +4536,16 @@ public class swiftApi { ...@@ -4465,6 +4536,16 @@ public class swiftApi {
4465 } 4536 }
4466 4537
4467 4538
4539 + public func setCouponSetsDealsList(_ couponSets: Array<CouponSetItemModel>) {
4540 + GlobalVariables.couponsetsDealsList = couponSets
4541 + }
4542 +
4543 +
4544 + public func getCouponSetsDealsList() -> Array<CouponSetItemModel> {
4545 + return GlobalVariables.couponsetsDealsList
4546 + }
4547 +
4548 +
4468 public func getLoyaltyBadge() -> LoyaltyBadgeModel { 4549 public func getLoyaltyBadge() -> LoyaltyBadgeModel {
4469 return GlobalVariables.loyaltyBadge 4550 return GlobalVariables.loyaltyBadge
4470 } 4551 }
......