Showing
2 changed files
with
283 additions
and
19 deletions
| ... | @@ -33,6 +33,8 @@ import SwiftEventBus | ... | @@ -33,6 +33,8 @@ import SwiftEventBus |
| 33 | 33 | ||
| 34 | public var couponset: swiftApi.CouponSetItemModel? | 34 | public var couponset: swiftApi.CouponSetItemModel? |
| 35 | public var campaign: swiftApi.CampaignItemModel? | 35 | public var campaign: swiftApi.CampaignItemModel? |
| 36 | + | ||
| 37 | + let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList() | ||
| 36 | 38 | ||
| 37 | let spinner = SpinnerViewController() | 39 | let spinner = SpinnerViewController() |
| 38 | 40 | ||
| ... | @@ -214,7 +216,8 @@ import SwiftEventBus | ... | @@ -214,7 +216,8 @@ import SwiftEventBus |
| 214 | redeemButton.isEnabled = false | 216 | redeemButton.isEnabled = false |
| 215 | 217 | ||
| 216 | if (ccms == nil) { | 218 | if (ccms == nil) { |
| 217 | - swiftApi().redeemCouponSetAsync(uuid: uuid, communication_uuid: communication_uuid, redeemCouponSetCallback, failureCallback: {errorCode in | 219 | + // swiftApi().redeemCouponSetAsync(uuid: uuid, communication_uuid: communication_uuid, redeemCouponSetCallback, failureCallback: {errorCode in |
| 220 | + swiftApi().redeemCouponSetAsyncInternal(uuid: uuid, communication_uuid: communication_uuid, redeemCouponSetCallback, failureCallback: {errorCode in | ||
| 218 | self.hideSpinner() | 221 | self.hideSpinner() |
| 219 | self.redeemButton.isEnabled = true | 222 | self.redeemButton.isEnabled = true |
| 220 | 223 | ||
| ... | @@ -229,7 +232,8 @@ import SwiftEventBus | ... | @@ -229,7 +232,8 @@ import SwiftEventBus |
| 229 | }) | 232 | }) |
| 230 | } else { | 233 | } else { |
| 231 | // TODO: MAybe change user_msisdn: profile?._msisdn ?? "" | 234 | // TODO: MAybe change user_msisdn: profile?._msisdn ?? "" |
| 232 | - 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 | 235 | + // 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 |
| 236 | + 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 | ||
| 233 | self.hideSpinner() | 237 | self.hideSpinner() |
| 234 | self.redeemButton.isEnabled = true | 238 | self.redeemButton.isEnabled = true |
| 235 | 239 | ||
| ... | @@ -245,7 +249,8 @@ import SwiftEventBus | ... | @@ -245,7 +249,8 @@ import SwiftEventBus |
| 245 | } | 249 | } |
| 246 | } | 250 | } |
| 247 | 251 | ||
| 248 | - func redeemCouponSetCallback (_ response: swiftApi.GenericResponseModel?) -> Void { | 252 | + // func redeemCouponSetCallback (_ response: swiftApi.GenericResponseModel?) -> Void { |
| 253 | + func redeemCouponSetCallback (_ response: swiftApi.RedeemCouponSetResponseModel?) -> Void { | ||
| 249 | hideSpinner() | 254 | hideSpinner() |
| 250 | self.redeemButton.isEnabled = true | 255 | self.redeemButton.isEnabled = true |
| 251 | 256 | ||
| ... | @@ -267,27 +272,62 @@ import SwiftEventBus | ... | @@ -267,27 +272,62 @@ import SwiftEventBus |
| 267 | 272 | ||
| 268 | self.showSuccessDialog("Επιτυχής ενεργοποίηση","Το κουπόνι σου έχει ενεργοποιηθεί και βρίσκεται στην ενότητα My Rewards.") | 273 | self.showSuccessDialog("Επιτυχής ενεργοποίηση","Το κουπόνι σου έχει ενεργοποιηθεί και βρίσκεται στην ενότητα My Rewards.") |
| 269 | 274 | ||
| 270 | - swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in }) | 275 | + /* OLD Addition start */ |
| 271 | - swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) | 276 | +// swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in }) |
| 277 | +// swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) | ||
| 278 | +// | ||
| 279 | +// func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void { | ||
| 280 | +// if (couponsData != nil) { | ||
| 281 | +// | ||
| 282 | +// DispatchQueue.main.async { | ||
| 283 | +// SwiftEventBus.post("coupons_fetched") | ||
| 284 | +// } | ||
| 285 | +// } else { | ||
| 286 | +// } | ||
| 287 | +// } | ||
| 288 | +// | ||
| 289 | +// func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { | ||
| 290 | +// if (campaignsData != nil) { | ||
| 291 | +// DispatchQueue.main.async { | ||
| 292 | +// SwiftEventBus.post("campaigns_retrieved") | ||
| 293 | +// } | ||
| 294 | +// } else { | ||
| 295 | +// } | ||
| 296 | +// } | ||
| 297 | + /* OLD Addition end */ | ||
| 272 | 298 | ||
| 273 | - func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void { | 299 | + /* New Addition start */ |
| 274 | - if (couponsData != nil) { | 300 | + if let newCoupon = response?.getCoupon { |
| 301 | + newCoupon.status = 1 | ||
| 302 | + | ||
| 303 | + if let couponsetData = self.couponset { | ||
| 304 | + newCoupon.setCouponSetData(couponsetData) | ||
| 275 | 305 | ||
| 276 | - DispatchQueue.main.async { | 306 | + for merchant in self.merchantList { |
| 277 | - SwiftEventBus.post("coupons_fetched") | 307 | + if (merchant._uuid == couponsetData.merchant_uuid) { |
| 308 | + newCoupon.merchant_details = merchant | ||
| 309 | + break; | ||
| 310 | + } | ||
| 278 | } | 311 | } |
| 279 | - } else { | ||
| 280 | } | 312 | } |
| 281 | - } | 313 | + |
| 282 | - | 314 | + swiftApi().addCouponItem(newCoupon: newCoupon) |
| 283 | - func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { | 315 | + SwiftEventBus.post("coupons_fetched") |
| 284 | - if (campaignsData != nil) { | 316 | + |
| 285 | - DispatchQueue.main.async { | 317 | + if let tempCampaign = self.campaign { |
| 286 | - SwiftEventBus.post("campaigns_retrieved") | 318 | + swiftApi().removeCampaignItem(campaignArg: tempCampaign) |
| 319 | + swiftApi().getCampaignsAsyncNewInternal(getCampaignsCallback, failureCallback: {errorCode in}) | ||
| 320 | + } | ||
| 321 | + | ||
| 322 | + func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { | ||
| 323 | + if (campaignsData != nil) { | ||
| 324 | + DispatchQueue.main.async { | ||
| 325 | + SwiftEventBus.post("campaigns_retrieved") | ||
| 326 | + } | ||
| 287 | } | 327 | } |
| 288 | - } else { | ||
| 289 | } | 328 | } |
| 290 | } | 329 | } |
| 330 | + /* New Addition end */ | ||
| 291 | 331 | ||
| 292 | } else if (response?.getStatus == 3) { | 332 | } else if (response?.getStatus == 3) { |
| 293 | let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel() | 333 | let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel() | ... | ... |
| ... | @@ -836,7 +836,7 @@ public class swiftApi { | ... | @@ -836,7 +836,7 @@ public class swiftApi { |
| 836 | public let coupon: String? | 836 | public let coupon: String? |
| 837 | public let category: String? | 837 | public let category: String? |
| 838 | public let barcode: String? | 838 | public let barcode: String? |
| 839 | - public let status: Int? | 839 | + public var status: Int? |
| 840 | public let transaction_uuid: String? | 840 | public let transaction_uuid: String? |
| 841 | public let redeemed: String? | 841 | public let redeemed: String? |
| 842 | public let redeemed_date: Date? | 842 | public let redeemed_date: Date? |
| ... | @@ -849,7 +849,7 @@ public class swiftApi { | ... | @@ -849,7 +849,7 @@ public class swiftApi { |
| 849 | public let terms: String? | 849 | public let terms: String? |
| 850 | 850 | ||
| 851 | // Universal Coupons | 851 | // Universal Coupons |
| 852 | - public let merchant_details: MerchantModel? | 852 | + public var merchant_details: MerchantModel? |
| 853 | 853 | ||
| 854 | 854 | ||
| 855 | public init(dictionary: [String: Any]) { | 855 | public init(dictionary: [String: Any]) { |
| ... | @@ -5208,6 +5208,53 @@ public class swiftApi { | ... | @@ -5208,6 +5208,53 @@ public class swiftApi { |
| 5208 | } | 5208 | } |
| 5209 | } | 5209 | } |
| 5210 | 5210 | ||
| 5211 | + /* | ||
| 5212 | + { | ||
| 5213 | + msg = Retrieved; | ||
| 5214 | + result = { | ||
| 5215 | + coupon = WGP87TLESUNU; | ||
| 5216 | + expiration = "2024-12-31 11:59:00"; | ||
| 5217 | + }; | ||
| 5218 | + status = 1; | ||
| 5219 | + "trace_id" = "Root=1-6723705c-0eaecd6f7e9870fb0f56479b"; | ||
| 5220 | + } | ||
| 5221 | + */ | ||
| 5222 | + public class RedeemCouponSetResponseModel { | ||
| 5223 | + private var coupon: CouponItemModel? | ||
| 5224 | + private var status: Int? | ||
| 5225 | + private var msg: String? | ||
| 5226 | + | ||
| 5227 | + | ||
| 5228 | + init(dictionary: [String: Any]) { | ||
| 5229 | + self.status = dictionary["status"] as? Int? ?? -1 | ||
| 5230 | + self.msg = dictionary["msg"] as? String? ?? "" | ||
| 5231 | + if let couponDictionary = dictionary["result"] as? [String : Any] { | ||
| 5232 | + let tempCoupon = CouponItemModel(dictionary: couponDictionary) | ||
| 5233 | + self.coupon = tempCoupon | ||
| 5234 | + } else { | ||
| 5235 | + self.coupon = nil | ||
| 5236 | + } | ||
| 5237 | + } | ||
| 5238 | + | ||
| 5239 | + public var getCoupon: CouponItemModel? { | ||
| 5240 | + get { // getter | ||
| 5241 | + return self.coupon | ||
| 5242 | + } | ||
| 5243 | + } | ||
| 5244 | + | ||
| 5245 | + public var getStatus: Int { | ||
| 5246 | + get { // getter | ||
| 5247 | + return self.status ?? -1 | ||
| 5248 | + } | ||
| 5249 | + } | ||
| 5250 | + | ||
| 5251 | + public var getMsg: String { | ||
| 5252 | + get { // getter | ||
| 5253 | + return self.msg ?? "" | ||
| 5254 | + } | ||
| 5255 | + } | ||
| 5256 | + } | ||
| 5257 | + | ||
| 5211 | public func redeemCouponSetAsync(uuid: String, communication_uuid: String, _ redeemCouponSetCallback: @escaping (_ responseData: GenericResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | 5258 | public func redeemCouponSetAsync(uuid: String, communication_uuid: String, _ redeemCouponSetCallback: @escaping (_ responseData: GenericResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { |
| 5212 | 5259 | ||
| 5213 | let instanceOfMyApi = MyApi() | 5260 | let instanceOfMyApi = MyApi() |
| ... | @@ -5279,6 +5326,77 @@ public class swiftApi { | ... | @@ -5279,6 +5326,77 @@ public class swiftApi { |
| 5279 | } | 5326 | } |
| 5280 | } | 5327 | } |
| 5281 | 5328 | ||
| 5329 | + public func redeemCouponSetAsyncInternal(uuid: String, communication_uuid: String, _ redeemCouponSetCallback: @escaping (_ responseData: RedeemCouponSetResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | ||
| 5330 | + | ||
| 5331 | + let instanceOfMyApi = MyApi() | ||
| 5332 | + instanceOfMyApi.redeemCouponSetAsync(uuid, communication_uuid, requestCallback, failureBlock: requestFailureCallback) | ||
| 5333 | + | ||
| 5334 | + func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void { | ||
| 5335 | + | ||
| 5336 | + if let responseDataDictionary = responseData as? [String: Any] { | ||
| 5337 | + | ||
| 5338 | + let tempResponse = RedeemCouponSetResponseModel(dictionary: responseDataDictionary) | ||
| 5339 | + | ||
| 5340 | + if (tempResponse != nil) { | ||
| 5341 | + DispatchQueue.main.async { | ||
| 5342 | + if (tempResponse.getStatus == 1) { | ||
| 5343 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 5344 | + dynatraceEvent._eventName = "custom_success_retrieve_coupon_loyalty" | ||
| 5345 | + dynatraceEvent._parameters = nil | ||
| 5346 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 5347 | + | ||
| 5348 | + } else { | ||
| 5349 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 5350 | + dynatraceEvent._eventName = "custom_error_retrieve_coupon_loyalty" | ||
| 5351 | + dynatraceEvent._parameters = nil | ||
| 5352 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 5353 | + | ||
| 5354 | + } | ||
| 5355 | + } | ||
| 5356 | + } else { | ||
| 5357 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 5358 | + dynatraceEvent._eventName = "custom_error_retrieve_coupon_loyalty" | ||
| 5359 | + dynatraceEvent._parameters = nil | ||
| 5360 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 5361 | + } | ||
| 5362 | + | ||
| 5363 | + redeemCouponSetCallback(tempResponse); | ||
| 5364 | + | ||
| 5365 | + } else { | ||
| 5366 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 5367 | + dynatraceEvent._eventName = "custom_error_retrieve_coupon_loyalty" | ||
| 5368 | + dynatraceEvent._parameters = nil | ||
| 5369 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 5370 | + | ||
| 5371 | + redeemCouponSetCallback(nil) | ||
| 5372 | + } | ||
| 5373 | + | ||
| 5374 | + } | ||
| 5375 | + | ||
| 5376 | + func requestFailureCallback(_ error: Error?) -> Void { | ||
| 5377 | + print("redeemCouponSet error: ") | ||
| 5378 | + print(error) | ||
| 5379 | + print("====================") | ||
| 5380 | + | ||
| 5381 | + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 5382 | + dynatraceEvent._eventName = "custom_error_retrieve_coupon_loyalty" | ||
| 5383 | + dynatraceEvent._parameters = nil | ||
| 5384 | + SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 5385 | + | ||
| 5386 | + if let error = error as? NSError { | ||
| 5387 | +// if (error.code == 401) { | ||
| 5388 | +// let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel() | ||
| 5389 | +// sessionEvent._sessionExpired = true | ||
| 5390 | +// SwiftEventBus.post("sdk_session_expired", sender: sessionEvent) | ||
| 5391 | +// } | ||
| 5392 | + | ||
| 5393 | + failureCallback(error.code) | ||
| 5394 | + } else { | ||
| 5395 | + failureCallback(-1) | ||
| 5396 | + } | ||
| 5397 | + } | ||
| 5398 | + } | ||
| 5399 | + | ||
| 5282 | 5400 | ||
| 5283 | 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 { | 5401 | 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 { |
| 5284 | 5402 | ||
| ... | @@ -5318,6 +5436,44 @@ public class swiftApi { | ... | @@ -5318,6 +5436,44 @@ public class swiftApi { |
| 5318 | } | 5436 | } |
| 5319 | } | 5437 | } |
| 5320 | 5438 | ||
| 5439 | + 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 { | ||
| 5440 | + | ||
| 5441 | + let instanceOfMyApi = MyApi() | ||
| 5442 | + 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) | ||
| 5443 | + | ||
| 5444 | + func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void { | ||
| 5445 | + | ||
| 5446 | + if let responseDataDictionary = responseData as? [String: Any] { | ||
| 5447 | + | ||
| 5448 | + let tempResponse = RedeemCouponSetResponseModel(dictionary: responseDataDictionary) | ||
| 5449 | + | ||
| 5450 | + redeemCouponSetCallback(tempResponse); | ||
| 5451 | + | ||
| 5452 | + } else { | ||
| 5453 | + redeemCouponSetCallback(nil) | ||
| 5454 | + } | ||
| 5455 | + | ||
| 5456 | + } | ||
| 5457 | + | ||
| 5458 | + func requestFailureCallback(_ error: Error?) -> Void { | ||
| 5459 | + print("redeemCouponSet error: ") | ||
| 5460 | + print(error) | ||
| 5461 | + print("====================") | ||
| 5462 | + | ||
| 5463 | + if let error = error as? NSError { | ||
| 5464 | +// if (error.code == 401) { | ||
| 5465 | +// let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel() | ||
| 5466 | +// sessionEvent._sessionExpired = true | ||
| 5467 | +// SwiftEventBus.post("sdk_session_expired", sender: sessionEvent) | ||
| 5468 | +// } | ||
| 5469 | + | ||
| 5470 | + failureCallback(error.code) | ||
| 5471 | + } else { | ||
| 5472 | + failureCallback(-1) | ||
| 5473 | + } | ||
| 5474 | + } | ||
| 5475 | + } | ||
| 5476 | + | ||
| 5321 | 5477 | ||
| 5322 | public func setUniqueCampaignList(_ campaigns: Array<CampaignItemModel>) -> Void { | 5478 | public func setUniqueCampaignList(_ campaigns: Array<CampaignItemModel>) -> Void { |
| 5323 | // let userTag = self.getUserTag() | 5479 | // let userTag = self.getUserTag() |
| ... | @@ -9096,5 +9252,73 @@ public class swiftApi { | ... | @@ -9096,5 +9252,73 @@ public class swiftApi { |
| 9096 | } | 9252 | } |
| 9097 | } | 9253 | } |
| 9098 | 9254 | ||
| 9255 | + public func addCouponItem(newCoupon: CouponItemModel) { | ||
| 9256 | + var tempCouponList = getCouponList() | ||
| 9257 | + tempCouponList.append(newCoupon) | ||
| 9258 | + swiftApi().setCouponList(tempCouponList) | ||
| 9259 | + } | ||
| 9260 | + | ||
| 9261 | + public func removeCampaignItem(campaignArg: CampaignItemModel) { | ||
| 9262 | + let allCampaigns = swiftApi().getAllCampaignList().filter { $0.session_uuid != campaignArg.session_uuid } | ||
| 9263 | + swiftApi().setUniqueCampaignList(allCampaigns) | ||
| 9264 | + | ||
| 9265 | + let carouselArray = swiftApi().getCarouselList().filter { $0.session_uuid != campaignArg.session_uuid } | ||
| 9266 | + swiftApi().setCarouselList(carouselArray) | ||
| 9267 | + } | ||
| 9268 | + | ||
| 9269 | + public func getCampaignsAsyncNewInternal(_ getCampaignsCallback: @escaping (_ campaignsData: Array<CampaignItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { | ||
| 9270 | + var campaignsArray = swiftApi().getAllCampaignList() | ||
| 9271 | + swiftApi().getAvailableCouponsAsync({responseDataAvailability in | ||
| 9272 | + if let availabilityData = responseDataAvailability { | ||
| 9273 | + for tempCampaign in campaignsArray { | ||
| 9274 | + for item in availabilityData { | ||
| 9275 | + if (tempCampaign._couponset == item.key) { | ||
| 9276 | + tempCampaign._coupon_availability = item.value as? Int ?? 0 | ||
| 9277 | + } | ||
| 9278 | + } | ||
| 9279 | + } | ||
| 9280 | + } | ||
| 9281 | + | ||
| 9282 | + let parsedCampagins = parseCampaigns() | ||
| 9283 | + getCampaignsCallback(parsedCampagins); | ||
| 9284 | + | ||
| 9285 | + }, failureCallback: {errorCode in | ||
| 9286 | + let parsedCampagins = parseCampaigns() | ||
| 9287 | + getCampaignsCallback(parsedCampagins); | ||
| 9288 | + }) | ||
| 9289 | + | ||
| 9290 | + func parseCampaigns() -> Array<CampaignItemModel> { | ||
| 9291 | + campaignsArray = campaignsArray.filter { $0._coupon_availability != 0 } | ||
| 9292 | + | ||
| 9293 | + swiftApi().setUniqueCampaignList(campaignsArray) | ||
| 9294 | + | ||
| 9295 | + let carouselArray:Array<CampaignItemModel> = campaignsArray.filter { | ||
| 9296 | + let tempCampaign = $0 | ||
| 9297 | + let isCarouselItem = (tempCampaign._carousel != nil) && (tempCampaign._carousel == "true") | ||
| 9298 | + | ||
| 9299 | + return (isCarouselItem) | ||
| 9300 | + } | ||
| 9301 | + swiftApi().setCarouselList(carouselArray) | ||
| 9302 | + | ||
| 9303 | + var filteredCampaigns = campaignsArray.filter { | ||
| 9304 | + let tempCampaign = $0 | ||
| 9305 | + let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") | ||
| 9306 | + let isTelco = (tempCampaign._type != nil && tempCampaign._type == "telco") | ||
| 9307 | + | ||
| 9308 | + return (!(isCcmsOffer || isTelco)) | ||
| 9309 | + } | ||
| 9310 | + | ||
| 9311 | + // if (swiftApi().getConsumerInternal()?._answered == true) { | ||
| 9312 | + filteredCampaigns = filteredCampaigns.filter { $0.offer_category != "questionnaire" } | ||
| 9313 | + // } | ||
| 9314 | + | ||
| 9315 | + let sortedCampaigns = filteredCampaigns.sorted { | ||
| 9316 | + ($0._sorting ?? 0) < ($1._sorting ?? 0) | ||
| 9317 | + } | ||
| 9318 | + | ||
| 9319 | + return sortedCampaigns | ||
| 9320 | + } | ||
| 9321 | + } | ||
| 9322 | + | ||
| 9099 | 9323 | ||
| 9100 | } | 9324 | } | ... | ... |
-
Please register or login to post a comment