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
2025-03-05 13:31:40 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2091a5ce9ad9881f76a6806cb79cfb6d5e1fe76e
2091a5ce
1 parent
cee409c6
add getRedeemedSMHistoryAsync
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
127 additions
and
0 deletions
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
View file @
2091a5c
...
...
@@ -617,6 +617,35 @@ public class swiftApi {
// return dict
// }
}
public
class
RedeemedSMHistoryModel
:
Codable
{
private
var
totalRedeemedValue
:
Float
private
var
redeemedCouponList
:
Array
<
CouponItemModel
>
init
()
{
self
.
totalRedeemedValue
=
0.0
self
.
redeemedCouponList
=
[]
}
public
var
_totalRedeemedValue
:
Float
{
get
{
// getter
return
self
.
totalRedeemedValue
}
set
(
newValue
)
{
//setter
self
.
totalRedeemedValue
=
newValue
}
}
public
var
_redeemedCouponList
:
Array
<
CouponItemModel
>
{
get
{
// getter
return
self
.
redeemedCouponList
}
set
(
newValue
)
{
//setter
self
.
redeemedCouponList
=
newValue
}
}
}
public
func
getCouponsAsync
(
_
getCouponsCallback
:
@escaping
(
_
couponsData
:
Array
<
CouponItemModel
>
?)
->
Void
,
failureCallback
:
@escaping
(
_
errorCode
:
Int
)
->
Void
)
->
Void
{
...
...
@@ -4280,4 +4309,102 @@ public class swiftApi {
}
}
public
func
getRedeemedSMHistoryAsync
(
language
:
String
,
_
successCallback
:
@escaping
(
_
data
:
RedeemedSMHistoryModel
?)
->
Void
,
failureCallback
:
@escaping
(
_
errorCode
:
Int
)
->
Void
)
->
Void
{
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
getCouponsUniversalAsync
(
language
,
"supermarket"
,
getCouponsUniversalCallback
,
failureBlock
:
getCouponsUniversalFailureCallback
)
func
getCouponsUniversalCallback
(
_
responseData
:
[
AnyHashable
:
Any
]?)
->
Void
{
var
couponsArray
:
Array
<
CouponItemModel
>
=
[]
if
let
responseDataDictionary
=
responseData
as?
[
String
:
AnyObject
]
{
if
(
responseDataDictionary
[
"status"
]
as?
Int
==
1
)
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_success_user_sm_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
)
}
}
var
oldCoupons
=
couponsArray
.
filter
({
return
$0
.
status
==
0
})
// sort oldCoupons by redeemed date
oldCoupons
.
sort
(
by
:
{
let
date1
=
$0
.
redeemed_date
let
date2
=
$1
.
redeemed_date
if
((
date1
!=
nil
)
&&
(
date2
!=
nil
))
{
return
date1
!.
compare
(
date2
!
)
==
.
orderedDescending
}
else
{
return
false
}
})
let
totalCouponDiscount
=
oldCoupons
.
reduce
(
0
)
{
$0
+
(
$1
.
couponset_data
?
.
final_price
??
0.0
)
}
// RedeemedSMHistoryModel
let
redeemedSMHistory
=
RedeemedSMHistoryModel
()
redeemedSMHistory
.
_totalRedeemedValue
=
totalCouponDiscount
redeemedSMHistory
.
_redeemedCouponList
=
oldCoupons
successCallback
(
redeemedSMHistory
)
}
else
{
successCallback
(
nil
)
}
}
else
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_user_sm_coupons_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
successCallback
(
nil
)
}
}
else
{
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_user_sm_coupons_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
post
(
"dynatrace"
,
sender
:
dynatraceEvent
)
successCallback
(
nil
)
}
}
func
getCouponsUniversalFailureCallback
(
_
error
:
Error
?)
->
Void
{
print
(
"getRedeemedSMHistoryAsync error: "
)
print
(
error
)
print
(
"===================="
)
let
dynatraceEvent
=
swiftApi
.
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_user_sm_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