Manos Chorianopoulos

redeemCouponSet optimizations

......@@ -33,6 +33,8 @@ import SwiftEventBus
public var couponset: swiftApi.CouponSetItemModel?
public var campaign: swiftApi.CampaignItemModel?
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
let spinner = SpinnerViewController()
......@@ -214,7 +216,8 @@ import SwiftEventBus
redeemButton.isEnabled = false
if (ccms == nil) {
swiftApi().redeemCouponSetAsync(uuid: uuid, communication_uuid: communication_uuid, redeemCouponSetCallback, failureCallback: {errorCode in
// swiftApi().redeemCouponSetAsync(uuid: uuid, communication_uuid: communication_uuid, redeemCouponSetCallback, failureCallback: {errorCode in
swiftApi().redeemCouponSetAsyncInternal(uuid: uuid, communication_uuid: communication_uuid, redeemCouponSetCallback, failureCallback: {errorCode in
self.hideSpinner()
self.redeemButton.isEnabled = true
......@@ -229,7 +232,8 @@ import SwiftEventBus
})
} else {
// TODO: MAybe change user_msisdn: profile?._msisdn ?? ""
swiftApi().redeemCouponSetAsync(uuid: uuid, communication_uuid: communication_uuid, user_msisdn: profile?._msisdn ?? "", businessService: (ccms?._businessService ?? ""), offerName: (ccms?._offerName ?? ""), productType: (ccms?._productType ?? ""), provDuration: (ccms?._provDuration ?? ""), noOfRecurrance: (ccms?._noOfRecurrance ?? ""), price: (ccms?._price ?? ""), discount: (ccms?._discount ?? ""), voiceCategory: (ccms?._voiceCategory ?? ""), dataCategory: (ccms?._dataCategory ?? ""), minsValue: (ccms?._minsValue ?? ""), dataValue: (ccms?._dataValue ?? ""), provStepValueMins: (ccms?._provStepValueMins ?? ""), OfferAudienceLevel: (ccms?._offerAudienceLevel ?? ""), UACIOfferTrackingCode: (ccms?._uaciOfferTrackingCode ?? ""), OFFERCODE1: (ccms?._offerCode1 ?? ""), SCORE: (ccms?._score ?? ""), ZONE: (ccms?._zone ?? ""), WAVE: (ccms?._wave ?? ""), VALIDITY: (ccms?._validity ?? ""), TREATMENT_CODE: (ccms?._treatmentCode ?? ""), ccms_session_id: (ccms?._sessionId ?? ""), redeemCouponSetCallback, failureCallback: {errorCode in
// swiftApi().redeemCouponSetAsync(uuid: uuid, communication_uuid: communication_uuid, user_msisdn: profile?._msisdn ?? "", businessService: (ccms?._businessService ?? ""), offerName: (ccms?._offerName ?? ""), productType: (ccms?._productType ?? ""), provDuration: (ccms?._provDuration ?? ""), noOfRecurrance: (ccms?._noOfRecurrance ?? ""), price: (ccms?._price ?? ""), discount: (ccms?._discount ?? ""), voiceCategory: (ccms?._voiceCategory ?? ""), dataCategory: (ccms?._dataCategory ?? ""), minsValue: (ccms?._minsValue ?? ""), dataValue: (ccms?._dataValue ?? ""), provStepValueMins: (ccms?._provStepValueMins ?? ""), OfferAudienceLevel: (ccms?._offerAudienceLevel ?? ""), UACIOfferTrackingCode: (ccms?._uaciOfferTrackingCode ?? ""), OFFERCODE1: (ccms?._offerCode1 ?? ""), SCORE: (ccms?._score ?? ""), ZONE: (ccms?._zone ?? ""), WAVE: (ccms?._wave ?? ""), VALIDITY: (ccms?._validity ?? ""), TREATMENT_CODE: (ccms?._treatmentCode ?? ""), ccms_session_id: (ccms?._sessionId ?? ""), redeemCouponSetCallback, failureCallback: {errorCode in
swiftApi().redeemCouponSetAsyncInternal(uuid: uuid, communication_uuid: communication_uuid, user_msisdn: profile?._msisdn ?? "", businessService: (ccms?._businessService ?? ""), offerName: (ccms?._offerName ?? ""), productType: (ccms?._productType ?? ""), provDuration: (ccms?._provDuration ?? ""), noOfRecurrance: (ccms?._noOfRecurrance ?? ""), price: (ccms?._price ?? ""), discount: (ccms?._discount ?? ""), voiceCategory: (ccms?._voiceCategory ?? ""), dataCategory: (ccms?._dataCategory ?? ""), minsValue: (ccms?._minsValue ?? ""), dataValue: (ccms?._dataValue ?? ""), provStepValueMins: (ccms?._provStepValueMins ?? ""), OfferAudienceLevel: (ccms?._offerAudienceLevel ?? ""), UACIOfferTrackingCode: (ccms?._uaciOfferTrackingCode ?? ""), OFFERCODE1: (ccms?._offerCode1 ?? ""), SCORE: (ccms?._score ?? ""), ZONE: (ccms?._zone ?? ""), WAVE: (ccms?._wave ?? ""), VALIDITY: (ccms?._validity ?? ""), TREATMENT_CODE: (ccms?._treatmentCode ?? ""), ccms_session_id: (ccms?._sessionId ?? ""), redeemCouponSetCallback, failureCallback: {errorCode in
self.hideSpinner()
self.redeemButton.isEnabled = true
......@@ -245,7 +249,8 @@ import SwiftEventBus
}
}
func redeemCouponSetCallback (_ response: swiftApi.GenericResponseModel?) -> Void {
// func redeemCouponSetCallback (_ response: swiftApi.GenericResponseModel?) -> Void {
func redeemCouponSetCallback (_ response: swiftApi.RedeemCouponSetResponseModel?) -> Void {
hideSpinner()
self.redeemButton.isEnabled = true
......@@ -267,27 +272,62 @@ import SwiftEventBus
self.showSuccessDialog("Επιτυχής ενεργοποίηση","Το κουπόνι σου έχει ενεργοποιηθεί και βρίσκεται στην ενότητα My Rewards.")
swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in })
swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
/* OLD Addition start */
// swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in })
// swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
//
// func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
// if (couponsData != nil) {
//
// DispatchQueue.main.async {
// SwiftEventBus.post("coupons_fetched")
// }
// } else {
// }
// }
//
// func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
// if (campaignsData != nil) {
// DispatchQueue.main.async {
// SwiftEventBus.post("campaigns_retrieved")
// }
// } else {
// }
// }
/* OLD Addition end */
func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
if (couponsData != nil) {
/* New Addition start */
if let newCoupon = response?.getCoupon {
newCoupon.status = 1
if let couponsetData = self.couponset {
newCoupon.setCouponSetData(couponsetData)
DispatchQueue.main.async {
SwiftEventBus.post("coupons_fetched")
for merchant in self.merchantList {
if (merchant._uuid == couponsetData.merchant_uuid) {
newCoupon.merchant_details = merchant
break;
}
}
} else {
}
}
func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
if (campaignsData != nil) {
DispatchQueue.main.async {
SwiftEventBus.post("campaigns_retrieved")
swiftApi().addCouponItem(newCoupon: newCoupon)
SwiftEventBus.post("coupons_fetched")
if let tempCampaign = self.campaign {
swiftApi().removeCampaignItem(campaignArg: tempCampaign)
swiftApi().getCampaignsAsyncNewInternal(getCampaignsCallback, failureCallback: {errorCode in})
}
func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
if (campaignsData != nil) {
DispatchQueue.main.async {
SwiftEventBus.post("campaigns_retrieved")
}
}
} else {
}
}
/* New Addition end */
} else if (response?.getStatus == 3) {
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
......
......@@ -836,7 +836,7 @@ public class swiftApi {
public let coupon: String?
public let category: String?
public let barcode: String?
public let status: Int?
public var status: Int?
public let transaction_uuid: String?
public let redeemed: String?
public let redeemed_date: Date?
......@@ -849,7 +849,7 @@ public class swiftApi {
public let terms: String?
// Universal Coupons
public let merchant_details: MerchantModel?
public var merchant_details: MerchantModel?
public init(dictionary: [String: Any]) {
......@@ -5208,6 +5208,53 @@ public class swiftApi {
}
}
/*
{
msg = Retrieved;
result = {
coupon = WGP87TLESUNU;
expiration = "2024-12-31 11:59:00";
};
status = 1;
"trace_id" = "Root=1-6723705c-0eaecd6f7e9870fb0f56479b";
}
*/
public class RedeemCouponSetResponseModel {
private var coupon: CouponItemModel?
private var status: Int?
private var msg: String?
init(dictionary: [String: Any]) {
self.status = dictionary["status"] as? Int? ?? -1
self.msg = dictionary["msg"] as? String? ?? ""
if let couponDictionary = dictionary["result"] as? [String : Any] {
let tempCoupon = CouponItemModel(dictionary: couponDictionary)
self.coupon = tempCoupon
} else {
self.coupon = nil
}
}
public var getCoupon: CouponItemModel? {
get { // getter
return self.coupon
}
}
public var getStatus: Int {
get { // getter
return self.status ?? -1
}
}
public var getMsg: String {
get { // getter
return self.msg ?? ""
}
}
}
public func redeemCouponSetAsync(uuid: String, communication_uuid: String, _ redeemCouponSetCallback: @escaping (_ responseData: GenericResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
......@@ -5279,6 +5326,77 @@ public class swiftApi {
}
}
public func redeemCouponSetAsyncInternal(uuid: String, communication_uuid: String, _ redeemCouponSetCallback: @escaping (_ responseData: RedeemCouponSetResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.redeemCouponSetAsync(uuid, communication_uuid, requestCallback, failureBlock: requestFailureCallback)
func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
if let responseDataDictionary = responseData as? [String: Any] {
let tempResponse = RedeemCouponSetResponseModel(dictionary: responseDataDictionary)
if (tempResponse != nil) {
DispatchQueue.main.async {
if (tempResponse.getStatus == 1) {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_success_retrieve_coupon_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_retrieve_coupon_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_retrieve_coupon_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
redeemCouponSetCallback(tempResponse);
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_retrieve_coupon_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
redeemCouponSetCallback(nil)
}
}
func requestFailureCallback(_ error: Error?) -> Void {
print("redeemCouponSet error: ")
print(error)
print("====================")
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_retrieve_coupon_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 func redeemCouponSetAsync(uuid: String, communication_uuid: String, user_msisdn: String, businessService: String, offerName: String, productType: String, provDuration: String, noOfRecurrance: String, price: String, discount: String, voiceCategory: String, dataCategory: String, minsValue: String, dataValue: String, provStepValueMins: String, OfferAudienceLevel: String, UACIOfferTrackingCode: String, OFFERCODE1: String, SCORE: String, ZONE: String, WAVE: String, VALIDITY: String, TREATMENT_CODE: String, ccms_session_id: String, _ redeemCouponSetCallback: @escaping (_ responseData: GenericResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
......@@ -5318,6 +5436,44 @@ public class swiftApi {
}
}
public func redeemCouponSetAsyncInternal(uuid: String, communication_uuid: String, user_msisdn: String, businessService: String, offerName: String, productType: String, provDuration: String, noOfRecurrance: String, price: String, discount: String, voiceCategory: String, dataCategory: String, minsValue: String, dataValue: String, provStepValueMins: String, OfferAudienceLevel: String, UACIOfferTrackingCode: String, OFFERCODE1: String, SCORE: String, ZONE: String, WAVE: String, VALIDITY: String, TREATMENT_CODE: String, ccms_session_id: String, _ redeemCouponSetCallback: @escaping (_ responseData: RedeemCouponSetResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.redeemCouponSetAsync(uuid, communication_uuid, user_msisdn, businessService, offerName, productType, provDuration, noOfRecurrance, price, discount, voiceCategory, dataCategory, minsValue, dataValue, provStepValueMins, OfferAudienceLevel, UACIOfferTrackingCode, OFFERCODE1, SCORE, ZONE, WAVE, VALIDITY, TREATMENT_CODE, ccms_session_id, requestCallback, failureBlock: requestFailureCallback)
func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
if let responseDataDictionary = responseData as? [String: Any] {
let tempResponse = RedeemCouponSetResponseModel(dictionary: responseDataDictionary)
redeemCouponSetCallback(tempResponse);
} else {
redeemCouponSetCallback(nil)
}
}
func requestFailureCallback(_ error: Error?) -> Void {
print("redeemCouponSet error: ")
print(error)
print("====================")
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 func setUniqueCampaignList(_ campaigns: Array<CampaignItemModel>) -> Void {
// let userTag = self.getUserTag()
......@@ -9096,5 +9252,73 @@ public class swiftApi {
}
}
public func addCouponItem(newCoupon: CouponItemModel) {
var tempCouponList = getCouponList()
tempCouponList.append(newCoupon)
swiftApi().setCouponList(tempCouponList)
}
public func removeCampaignItem(campaignArg: CampaignItemModel) {
let allCampaigns = swiftApi().getAllCampaignList().filter { $0.session_uuid != campaignArg.session_uuid }
swiftApi().setUniqueCampaignList(allCampaigns)
let carouselArray = swiftApi().getCarouselList().filter { $0.session_uuid != campaignArg.session_uuid }
swiftApi().setCarouselList(carouselArray)
}
public func getCampaignsAsyncNewInternal(_ getCampaignsCallback: @escaping (_ campaignsData: Array<CampaignItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
var campaignsArray = swiftApi().getAllCampaignList()
swiftApi().getAvailableCouponsAsync({responseDataAvailability in
if let availabilityData = responseDataAvailability {
for tempCampaign in campaignsArray {
for item in availabilityData {
if (tempCampaign._couponset == item.key) {
tempCampaign._coupon_availability = item.value as? Int ?? 0
}
}
}
}
let parsedCampagins = parseCampaigns()
getCampaignsCallback(parsedCampagins);
}, failureCallback: {errorCode in
let parsedCampagins = parseCampaigns()
getCampaignsCallback(parsedCampagins);
})
func parseCampaigns() -> Array<CampaignItemModel> {
campaignsArray = campaignsArray.filter { $0._coupon_availability != 0 }
swiftApi().setUniqueCampaignList(campaignsArray)
let carouselArray:Array<CampaignItemModel> = campaignsArray.filter {
let tempCampaign = $0
let isCarouselItem = (tempCampaign._carousel != nil) && (tempCampaign._carousel == "true")
return (isCarouselItem)
}
swiftApi().setCarouselList(carouselArray)
var filteredCampaigns = campaignsArray.filter {
let tempCampaign = $0
let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true")
let isTelco = (tempCampaign._type != nil && tempCampaign._type == "telco")
return (!(isCcmsOffer || isTelco))
}
// if (swiftApi().getConsumerInternal()?._answered == true) {
filteredCampaigns = filteredCampaigns.filter { $0.offer_category != "questionnaire" }
// }
let sortedCampaigns = filteredCampaigns.sorted {
($0._sorting ?? 0) < ($1._sorting ?? 0)
}
return sortedCampaigns
}
}
}
......