Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2024-03-06 10:38:02 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
485220e7600082a56a8291f934705c9285220947
485220e7
1 parent
a26bb5ba
Add new coupons request
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
304 additions
and
1 deletions
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.h
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.h
View file @
485220e
...
...
@@ -80,6 +80,7 @@
-
(
NSDictionary
*
)
validateCouponWithCoupon
:(
NSString
*
)
coupon
;
-
(
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
:
(
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
;
...
...
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
View file @
485220e
...
...
@@ -1450,6 +1450,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
-
(
void
)
getCouponsUniversalAsync
:
(
NSString
*
)
language
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
[[
Warply
sharedService
]
getCouponsUniversalWithSuccessBlock
:
language
:
^
(
NSDictionary
*
response
)
{
if
(
success
)
{
success
(
response
);
}
}
failureBlock
:^
(
NSError
*
error
)
{
if
(
failure
)
{
failure
(
error
);
}
}];
}
-
(
void
)
getUnifiedCouponsAsync
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
View file @
485220e
...
...
@@ -369,6 +369,8 @@ WL_VERSION_INTERFACE()
-
(
void
)
getCouponsWithSuccessBlock
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
getCouponsUniversalWithSuccessBlock
:(
NSString
*
)
language
:
(
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
;
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
View file @
485220e
...
...
@@ -2572,6 +2572,82 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
-
(
void
)
getCouponsUniversalWithSuccessBlock
:
(
NSString
*
)
language
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
// TODO: If pagination is needed in the future create new signature with the extra argument pagination
/*
{
"coupon": {
"action": "user_coupons",
"details":[
"merchant"
],
"language":"el",
"pagination":{
"page":1,
"per_page":10
}
}
}
*/
NSMutableDictionary
*
couponDictionary
=
[[
NSMutableDictionary
alloc
]
init
];
[
couponDictionary
setValue
:
@"user_coupons"
forKey
:
@"action"
];
[
couponDictionary
setValue
:@[
@"merchant"
]
forKey
:
@"details"
];
[
couponDictionary
setValue
:
language
forKey
:
@"language"
];
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 get coupons %@"
,
error
);
failure
(
error
);
}
}
}];
}
-
(
void
)
getUnifiedCouponsWithSuccessBlock
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
NSMutableDictionary
*
data
=
[[
NSMutableDictionary
alloc
]
init
];
...
...
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
View file @
485220e
...
...
@@ -1068,8 +1068,105 @@ public class swiftApi {
})
}
// public func getCouponsAsync(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
// CouponsDataModel().getCouponsData(getCouponsCallback, failureCallback: failureCallback)
// }
public
func
getCouponsAsync
(
_
getCouponsCallback
:
@escaping
(
_
couponsData
:
Array
<
CouponItemModel
>
?)
->
Void
,
failureCallback
:
@escaping
(
_
errorCode
:
Int
)
->
Void
)
->
Void
{
CouponsDataModel
()
.
getCouponsData
(
getCouponsCallback
,
failureCallback
:
failureCallback
)
let
instanceOfMyApi
=
MyApi
()
swiftApi
()
.
getMultilingualMerchantsAsync
([],
false
,
0.0
,
[],
""
,
0
,
[],
getMerchantsCallback
)
func
getMerchantsCallback
(
_
merchantsData
:
Array
<
swiftApi
.
MerchantModel
>
?)
->
Void
{
if
(
merchantsData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
swiftApi
()
.
setMerchantList
(
merchantsData
??
[])
}
}
else
{
}
}
swiftApi
()
.
getCouponsUniversalAsync
(
language
:
"el"
,
getCouponsCallback
,
failureCallback
:
failureCallback
)
// swiftApi().getCouponsUniversalAsync(language: "el", getCouponsUniversalCallback) { errorCode in
// // TODO: DELETE LOGS
// print("========= getCouponsUniversalRequest ERROR CODE =========", errorCode)
// failureCallback(errorCode)
// }
// func getCouponsUniversalCallback (_ responseData: Array<swiftApi.CouponItemModel>?) -> Void {
// if (responseData != nil) {
// DispatchQueue.main.async {
// // TODO: DELETE LOGS
// print("========= getCouponsUniversalRequest responseData =========")
// print(responseData)
// var activeCoupons = responseData.filter({ return $0.status == 1 })
// // sort activeCoupons by expiration date
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "dd/MM/yyyy"
// activeCoupons.sort(by: {
// let date1 = dateFormatter.date(from: $0.expiration ?? "")
// let date2 = dateFormatter.date(from: $1.expiration ?? "")
// if ((date1 != nil) && (date2 != nil)) {
// return date1!.compare(date2!) == .orderedAscending
// } else {
// return false
// }
// })
// getCouponsCallback(activeCoupons)
// }
// } else {
// // TODO: DELETE LOGS
// print("========= getCouponsUniversalRequest ERROR =========")
// getCouponsCallback(nil)
// }
// }
instanceOfMyApi
.
getCouponsetsAsync
(
true
,
andVisible
:
true
,
andUuids
:
nil
,
couponSetsCallback
,
failureBlock
:
couponSetsFailureCallback
)
func
couponSetsCallback
(
_
couponSetsData
:
[
AnyHashable
:
Any
]?)
->
Void
{
var
couponSetsArray
:
Array
<
CouponSetItemModel
>
=
[]
if
let
myCouponsSetsDictionary
=
couponSetsData
as?
[
String
:
AnyObject
]
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_success_couponset_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
if
let
couponSetsData
=
(
myCouponsSetsDictionary
[
"MAPP_COUPON"
]
as?
NSArray
)
{
for
couponset
in
couponSetsData
{
if
let
couponsetDictionairy
=
couponset
as?
[
String
:
Any
]
{
let
tempCouponset
=
CouponSetItemModel
(
dictionary
:
couponsetDictionairy
)
couponSetsArray
.
append
(
tempCouponset
)
}
}
}
}
else
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_couponset_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
}
swiftApi
()
.
setCouponSetList
(
couponSetsArray
)
}
func
couponSetsFailureCallback
(
_
error
:
Error
?)
->
Void
{
print
(
"getCouponSets error: "
)
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_couponset_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
}
}
public
class
func
getCoupons
()
->
Array
<
CouponItemModel
>
{
...
...
@@ -8265,4 +8362,117 @@ public class swiftApi {
}
public
func
getCouponsUniversalAsync
(
language
:
String
,
_
successCallback
:
@escaping
(
_
couponsData
:
Array
<
CouponItemModel
>
?)
->
Void
,
failureCallback
:
@escaping
(
_
errorCode
:
Int
)
->
Void
)
->
Void
{
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
getCouponsUniversalAsync
(
language
,
getCouponsUniversalCallback
,
failureBlock
:
getCouponsUniversalFailureCallback
)
func
getCouponsUniversalCallback
(
_
responseData
:
[
AnyHashable
:
Any
]?)
->
Void
{
var
couponsArray
:
Array
<
CouponItemModel
>
=
[]
if
let
responseDataDictionary
=
responseData
as?
[
String
:
AnyObject
]
{
// TODO: DELETE LOGS
print
(
"=== responseDataDictionary ==="
)
print
(
responseDataDictionary
)
print
(
"=== responseDataDictionary result ==="
)
print
(
responseDataDictionary
[
"result"
])
print
(
"=== responseDataDictionary status ==="
)
print
(
responseDataDictionary
[
"status"
])
if
(
responseDataDictionary
[
"status"
]
as?
Int
==
1
)
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_success_user_coupons_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
if
let
responseDataResult
=
responseDataDictionary
[
"result"
]
as?
[[
String
:
Any
]?]
{
for
coupon
in
responseDataResult
{
if
let
couponDictionary
=
coupon
{
let
tempCoupon
=
CouponItemModel
(
dictionary
:
couponDictionary
)
couponsArray
.
append
(
tempCoupon
)
}
}
// TODO: DELETE LOGS
print
(
"=== AllCoupons NEW ==="
)
print
(
couponsArray
.
count
)
// setAllOldCouponList uncluding Supermarkets ==>
swiftApi
()
.
setAllOldCouponList
(
couponsArray
)
// <==
swiftApi
()
.
setCouponList
(
couponsArray
)
swiftApi
()
.
setOldCouponList
(
couponsArray
)
var
activeCoupons
=
couponsArray
.
filter
({
return
$0
.
status
==
1
})
// sort activeCoupons by expiration date
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"dd/MM/yyyy"
activeCoupons
.
sort
(
by
:
{
let
date1
=
dateFormatter
.
date
(
from
:
$0
.
expiration
??
""
)
let
date2
=
dateFormatter
.
date
(
from
:
$1
.
expiration
??
""
)
if
((
date1
!=
nil
)
&&
(
date2
!=
nil
))
{
return
date1
!.
compare
(
date2
!
)
==
.
orderedAscending
}
else
{
return
false
}
})
successCallback
(
activeCoupons
)
// successCallback(couponsArray)
}
else
{
successCallback
(
nil
)
}
}
else
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_user_coupons_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
successCallback
(
nil
)
}
}
else
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_user_coupons_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
successCallback
(
nil
)
}
}
func
getCouponsUniversalFailureCallback
(
_
error
:
Error
?)
->
Void
{
print
(
"getCouponsUniversal error: "
)
print
(
error
)
print
(
"===================="
)
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_user_coupons_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
// successCallback(nil)
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
)
}
}
}
}
...
...
Please
register
or
login
to post a comment