Manos Chorianopoulos

add createUnifiedCouponAsync request

......@@ -82,6 +82,7 @@
- (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket;
- (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getCouponsUniversalAsync:(NSString*)language :(NSString*)couponsetType :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) createUnifiedCouponAsync:(NSArray*)couponCodes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) getAvailableCouponsAsync:(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;
......
......@@ -1477,6 +1477,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
- (void) createUnifiedCouponAsync:(NSArray*)couponCodes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] createUnifiedCouponWithSuccessBlock:couponCodes :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
- (void)getUnifiedCouponsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
......
......@@ -373,6 +373,8 @@ WL_VERSION_INTERFACE()
- (void)getCouponsUniversalWithSuccessBlock:(NSString*)language :(NSString*)couponsetType :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)createUnifiedCouponWithSuccessBlock:(NSArray*)couponCodes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getTransactionHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -2721,6 +2721,75 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
- (void)createUnifiedCouponWithSuccessBlock:(NSArray*)couponCodes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
/*
{
"coupon": {
"action": "unify_coupons",
"coupon_codes":[
"...", "..."
]
}
}
*/
NSMutableDictionary* couponDictionary = [[NSMutableDictionary alloc] init];
[couponDictionary setValue:@"unify_coupons" forKey:@"action"];
[couponDictionary setValue:couponCodes forKey:@"coupon_codes"];
NSMutableDictionary* dataDictionary = [[NSMutableDictionary alloc] init];
[dataDictionary setValue:couponDictionary forKey:@"coupon"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataDictionary 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 createUnifiedCoupon %@", error );
failure(error);
}
}
}];
}
- (void)getUnifiedCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
......
......@@ -8833,6 +8833,85 @@ public class swiftApi {
}
public func createUnifiedCouponAsync(couponCodes: Array<String>, _ successCallback: @escaping (_ responseData: GenericResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.createUnifiedCouponAsync(couponCodes, requestCallback, failureBlock: requestFailureCallback)
func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
if let responseDataDictionary = responseData as? [String: Any] {
let tempResponse = GenericResponseModel(dictionary: responseDataDictionary)
if (tempResponse != nil) {
DispatchQueue.main.async {
if (tempResponse.getStatus == 1) {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_success_create_unified_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
swiftApi().getUnifiedCouponsDeals { unifiedCoupons in
} failureCallback: { errorCode in
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_create_unified_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_create_unified_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
successCallback(tempResponse);
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_create_unified_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
successCallback(nil)
}
}
func requestFailureCallback(_ error: Error?) -> Void {
print("CreateUnifiedCoupon error: ")
print(error)
print("====================")
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_create_unified_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 ActiveBoxCouponModel {
private var value: String
private var code: String
......