Manos Chorianopoulos

add getCouponSetsDealsAsync request

......@@ -82,6 +82,7 @@
- (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getCouponsetsDealsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
- (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -1477,6 +1477,19 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
- (void) getCouponsetsDealsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] getCouponSetsDealsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
- (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure
{
[[Warply sharedService] getInbox2WithSuccessBlock :^(NSArray *inbox) {
......
......@@ -403,6 +403,8 @@ WL_VERSION_INTERFACE()
- (void) getCouponSetsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) getCouponSetsDealsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (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)
}];
}
- (void) getCouponSetsDealsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
[data setValue:active forKey:@"active"];
[data setValue:@"retrieve_multilingual" forKey:@"action"];
[data setValue:visible forKey:@"visible"];
[data setValue:LANG forKey:@"language"];
if (uuids && [uuids count] > 0) {
[data setValue:uuids forKey:@"uuids"];
}
[data setValue:@[@"supermarket"] forKey:@"couponset_types"];
NSMutableDictionary* dataCoupons = [[NSMutableDictionary alloc] init];
[dataCoupons setValue:data forKey:@"coupon"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataCoupons options:0 error:NULL];
[self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
NSLog(@"**************** WARPLY Response *****************" );
NSLog(@"%@", contextResponse );
} failureBlock:^(NSError *error) {
if (failure) {
NSDictionary* dict = [NSDictionary alloc];
dict = [error userInfo];
NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
// NSString* errorDomain = [error domain];
// NSError *errorToken = [NSError errorWithDomain:errorDomain code:401 userInfo:dict];
//
// if (failure) {
// failure(errorToken);
// }
[self refreshToken:^(NSDictionary *response) {
[self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
NSLog(@"**************** WARPLY Response *****************" );
NSLog(@"%@", contextResponse );
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
} failureBlock:^(NSError *error) {
if (failure) {
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
}];
} else {
NSLog(@"Error at get couponset deals %@", error );
failure(error);
}
}
}];
}
- (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSDictionary *postDictionary = @{@"coupon": @{@"action": @"retrieve_coupon", @"coupon_set": uuid, @"communication_uuid": communication_uuid}};
......
......@@ -17,6 +17,7 @@ public struct GlobalVariables {
static var couponList: Array<swiftApi.CouponItemModel> = []
static var oldCouponList: Array<swiftApi.CouponItemModel> = []
static var couponSetList: Array<swiftApi.CouponSetItemModel> = []
static var couponsetsDealsList: Array<swiftApi.CouponSetItemModel> = [] // Supermarket couponsets
static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = []
static var oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = []
static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel()
......@@ -591,6 +592,76 @@ public class swiftApi {
return CouponSetsDataModel().getData
}
public func getCouponSetsDealsAsync(_ getCouponSetsCallback: @escaping (_ couponSetsData: Array<CouponSetItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
var couponSets: [AnyHashable : Any]?
var couponSetsArray:Array<CouponSetItemModel> = []
instanceOfMyApi.getCouponsetsDealsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback)
func couponSetsCallback(_ couponSetsData: [AnyHashable : Any]?) -> Void {
if let responseDataDictionary = couponSetsData as? [String : AnyObject] {
if (responseDataDictionary["status"] as? Int == 1) {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_success_couponset_sm_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
if let responseDataResult = responseDataDictionary["result"] as? [[String : Any]?] {
for couponset in responseDataResult {
let tempCouponset = CouponSetItemModel(dictionary: couponset ?? [String : Any]())
couponSetsArray.append(tempCouponset)
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_couponset_sm_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_couponset_sm_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_couponset_sm_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
swiftApi().setCouponSetsDealsList(couponSetsArray)
getCouponSetsCallback(couponSetsArray)
}
func couponSetsFailureCallback(_ error: Error?) -> Void {
print("getCouponSetsDeals error: ")
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_couponset_sm_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
if let error = error as? NSError {
// if (error.code == 401) {
// let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel()
// sessionEvent._sessionExpired = true
// SwiftEventBus.post("sdk_session_expired", sender: sessionEvent)
// }
failureCallback(error.code)
} else {
failureCallback(-1)
}
}
}
public class CouponItemModel: Codable {
public let couponset_uuid: String?
......@@ -4465,6 +4536,16 @@ public class swiftApi {
}
public func setCouponSetsDealsList(_ couponSets: Array<CouponSetItemModel>) {
GlobalVariables.couponsetsDealsList = couponSets
}
public func getCouponSetsDealsList() -> Array<CouponSetItemModel> {
return GlobalVariables.couponsetsDealsList
}
public func getLoyaltyBadge() -> LoyaltyBadgeModel {
return GlobalVariables.loyaltyBadge
}
......