Manos Chorianopoulos

add cancelUnifiedCoupon functionality

......@@ -7,7 +7,7 @@
<key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
......
......@@ -7,7 +7,7 @@
<key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
......
......@@ -3479,14 +3479,14 @@
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="UnifiedCouponBCFooterTableViewCell" id="LD5-ES-J67" customClass="UnifiedCouponBCFooterTableViewCell" customModule="SwiftWarplyFramework">
<rect key="frame" x="0.0" y="935.5" width="414" height="160"/>
<rect key="frame" x="0.0" y="935.5" width="414" height="220"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="LD5-ES-J67" id="DmN-AA-8n5">
<rect key="frame" x="0.0" y="0.0" width="414" height="160"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="220"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="L4W-1e-9fQ">
<rect key="frame" x="0.0" y="0.0" width="414" height="160"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="220"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Kdi-w7-eKZ">
<rect key="frame" x="123.5" y="20" width="167" height="50"/>
......@@ -3502,8 +3502,22 @@
<action selector="mapButtonAction:" destination="kZo-uj-MVp" eventType="touchUpInside" id="jm9-HG-8Sd"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="BrE-JO-TPr">
<rect key="frame" x="91" y="80" width="232" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="NrC-VW-t5Y"/>
</constraints>
<fontDescription key="fontDescription" name="PeridotPE-Bold" family="Peridot PE" pointSize="17"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" title="Ακύρωση ενιαίου κουπονιού">
<color key="titleColor" red="0.054901960780000002" green="0.65098039220000004" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="cancelButtonAction:" destination="kZo-uj-MVp" eventType="touchUpInside" id="4mm-Dp-2gO"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Sq7-ea-Nx2">
<rect key="frame" x="103.5" y="90" width="207" height="40"/>
<rect key="frame" x="103.5" y="150" width="207" height="40"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="UgG-aB-OOw"/>
</constraints>
......@@ -3518,7 +3532,7 @@
</connections>
</button>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="center" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kkr-9H-ZSx" customClass="UnselectableTappableTextView" customModule="SwiftWarplyFramework">
<rect key="frame" x="20" y="130" width="374" height="0.0"/>
<rect key="frame" x="20" y="190" width="374" height="0.0"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" id="oLt-F6-WA7"/>
......@@ -3531,9 +3545,11 @@
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="Kdi-w7-eKZ" firstAttribute="top" secondItem="L4W-1e-9fQ" secondAttribute="top" constant="20" id="1IM-rZ-u2k"/>
<constraint firstItem="Sq7-ea-Nx2" firstAttribute="top" secondItem="Kdi-w7-eKZ" secondAttribute="bottom" constant="20" id="1Qv-cX-6D8"/>
<constraint firstItem="Sq7-ea-Nx2" firstAttribute="top" secondItem="BrE-JO-TPr" secondAttribute="bottom" constant="20" id="1Qv-cX-6D8"/>
<constraint firstItem="Kkr-9H-ZSx" firstAttribute="leading" secondItem="L4W-1e-9fQ" secondAttribute="leading" constant="20" id="7pl-xk-jHX"/>
<constraint firstAttribute="trailing" secondItem="Kkr-9H-ZSx" secondAttribute="trailing" constant="20" id="VBo-Kj-h0s"/>
<constraint firstItem="BrE-JO-TPr" firstAttribute="centerX" secondItem="L4W-1e-9fQ" secondAttribute="centerX" id="bW8-3Y-oqb"/>
<constraint firstItem="BrE-JO-TPr" firstAttribute="top" secondItem="Kdi-w7-eKZ" secondAttribute="bottom" constant="10" id="dEo-5F-kZg"/>
<constraint firstItem="Kkr-9H-ZSx" firstAttribute="top" secondItem="Sq7-ea-Nx2" secondAttribute="bottom" id="jsT-BU-52c"/>
<constraint firstItem="Sq7-ea-Nx2" firstAttribute="width" secondItem="L4W-1e-9fQ" secondAttribute="width" multiplier="0.5" id="ljh-1k-pkA"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="Sq7-ea-Nx2" secondAttribute="bottom" constant="30" id="nmp-6u-Pr6"/>
......@@ -3553,6 +3569,7 @@
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<outlet property="cancelButton" destination="BrE-JO-TPr" id="fJv-84-jmi"/>
<outlet property="mapButton" destination="Kdi-w7-eKZ" id="DIH-nr-baa"/>
<outlet property="mapButtonHeight" destination="SUG-HC-XQH" id="GRr-Cz-ZUP"/>
<outlet property="mapButtonTopSpace" destination="1IM-rZ-u2k" id="Maj-hs-eqg"/>
......
......@@ -83,6 +83,7 @@
- (void)getUnifiedCouponsAsync:(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;
- (void)getCouponsetsDealsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) cancelUnifiedCouponAsync:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
- (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -1490,6 +1490,19 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
- (void) cancelUnifiedCouponAsync:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] cancelUnifiedCouponWithSuccessBlock:transactionId :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
- (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure
{
[[Warply sharedService] getInbox2WithSuccessBlock :^(NSArray *inbox) {
......
......@@ -17,6 +17,7 @@ import AVFoundation
@IBOutlet weak var mapButton: UIButton!
@IBOutlet weak var mapButtonHeight: NSLayoutConstraint!
@IBOutlet weak var mapButtonTopSpace: NSLayoutConstraint!
@IBOutlet weak var cancelButton: UIButton!
public override func awakeFromNib() {
super.awakeFromNib()
......@@ -32,6 +33,16 @@ import AVFoundation
mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 50)
mapButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 25)
cancelButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 17)
cancelButton.setTitle("Ακύρωση ενιαίου κουπονιού", for: .normal)
cancelButton.setTitleColor(UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00), for: .normal)
cancelButton.layer.cornerRadius = 15.0
cancelButton.frame = CGRect(x: 0.0, y: 0.0, width: cancelButton.intrinsicContentSize.width, height: 50)
cancelButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 25)
cancelButton.backgroundColor = .clear
cancelButton.layer.borderWidth = 2
cancelButton.layer.borderColor = UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00).cgColor
// mapButton.isHidden = true
// mapButtonHeight.constant = 0
// mapButtonTopSpace.constant = 0
......
......@@ -8,7 +8,7 @@
import UIKit
import RSBarcodes_Swift
import AVFoundation
// import SwiftEventBus
import SwiftEventBus
@objc public class UnifiedCouponBarcodeViewController: UIViewController {
@IBOutlet weak var mainView: UIView!
......@@ -57,6 +57,88 @@ import AVFoundation
// MARK: - Functions
func showConfirmDialog() -> Void {
let alert = UIAlertController(title: "Ακύρωση Κουπονιού", message: "Είσαι σίγουρος ότι θέλεις να ακυρώσεις το κουπόνι σου;", preferredStyle: .alert)
let cancelButton = UIAlertAction(title: "Όχι", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
})
// cancelButton.setValue(UIColor(rgb: 0xFC5757), forKey: "titleTextColor")
alert.addAction(cancelButton)
alert.addAction(UIAlertAction(title: "Ναι", style: .default, handler: { action in
switch action.style{
case .default:
self.cancelUnifiedCouponRequest()
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
func showSuccessDialog() -> Void {
let alert = UIAlertController(title: "Ακύρωση Κουπονιού", message: "Το ενιαίο κουπόνι σου ακυρώθηκε επιτυχώς. Βρες τα μεμονωμένα κουπόνια στο καλάθι SM deals.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
SwiftEventBus.post("refresh_unified_coupons")
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: {})
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
func cancelUnifiedCouponRequest () -> Void {
var tranIdFound = "";
for coupon in self.coupon?._coupons ?? [] {
if ((coupon.transaction_uuid != nil) && coupon.transaction_uuid != "") {
tranIdFound = coupon.transaction_uuid ?? "";
break;
}
}
if (tranIdFound != "") {
swiftApi().cancelUnifiedCouponAsync(transactionId: tranIdFound, self.cancelUnifiedCouponCallback, failureCallback: { errorCode in })
}
}
func cancelUnifiedCouponCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void {
if (responseData != nil) {
DispatchQueue.main.async {
if (responseData?.getStatus == 1) {
self.showSuccessDialog()
}
}
}
}
// MARK: - Actions
@IBAction func showCouponsButtonAction(_ sender: Any) {
......@@ -109,6 +191,10 @@ import AVFoundation
// }
// }
}
@IBAction func cancelButtonAction(_ sender: Any) {
self.showConfirmDialog()
}
}
// MARK: - TableView
......
......@@ -405,6 +405,8 @@ WL_VERSION_INTERFACE()
- (void) getCouponSetsDealsWithSuccessBlock:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) cancelUnifiedCouponWithSuccessBlock:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(NSString*)user_msisdn :(NSString*)businessService :(NSString*)offerName :(NSString*)productType :(NSString*)provDuration :(NSString*)noOfRecurrance :(NSString*)price :(NSString*)discount :(NSString*)voiceCategory :(NSString*)dataCategory :(NSString*)minsValue :(NSString*)dataValue :(NSString*)provStepValueMins :(NSString*)OfferAudienceLevel :(NSString*)UACIOfferTrackingCode :(NSString*)OFFERCODE1 :(NSString*)SCORE :(NSString*)ZONE :(NSString*)WAVE :(NSString*)VALIDITY :(NSString*)TREATMENT_CODE :(NSString*)ccms_session_id :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -3388,6 +3388,63 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
- (void) cancelUnifiedCouponWithSuccessBlock:(NSString*) transactionId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
[data setValue:@"cancel_unified_coupon" forKey:@"action"];
[data setValue:transactionId forKey:@"transaction_id"];
NSMutableDictionary* dataCoupons = [[NSMutableDictionary alloc] init];
[dataCoupons setValue:data forKey:@"coupon"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataCoupons 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 Cancel Unified Coupon %@", error );
failure(error);
}
}
}];
}
- (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSDictionary *postDictionary = @{@"coupon": @{@"action": @"retrieve_coupon", @"coupon_set": uuid, @"communication_uuid": communication_uuid}};
......
......@@ -691,6 +691,7 @@ public class swiftApi {
public let category: String?
public let barcode: String?
public let status: Int?
public let transaction_uuid: String?
public let redeemed: String?
public let redeemed_date: Date?
public var couponset_data: CouponSetItemModel?
......@@ -713,6 +714,14 @@ public class swiftApi {
self.barcode = dictionary["barcode"] as? String? ?? ""
self.status = dictionary["status"] as? Int? ?? nil
if let tranIdString = dictionary["transaction_uuid"] as? String? ?? "", tranIdString != "" {
self.transaction_uuid = tranIdString
} else if let tranIdInt = dictionary["transaction_uuid"] as? Int? ?? 0, tranIdInt != 0 {
self.transaction_uuid = String(tranIdInt)
} else {
self.transaction_uuid = ""
}
if let tempDiscount = dictionary["discount"] as? String? ?? "" {
if tempDiscount.contains(",") {
let formattedDiscount = tempDiscount.replacingOccurrences(of: ",", with: ".")
......@@ -7382,4 +7391,76 @@ public class swiftApi {
}
public func cancelUnifiedCouponAsync(transactionId: String, _ cancelUnifiedCouponCallback: @escaping (_ responseData: GenericResponseModel?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.cancelUnifiedCouponAsync(transactionId, 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_cancel_unified_coupon"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_cancel_unified_coupon"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_cancel_unified_coupon"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
}
cancelUnifiedCouponCallback(tempResponse);
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_cancel_unified_coupon"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
cancelUnifiedCouponCallback(nil)
}
}
func requestFailureCallback(_ error: Error?) -> Void {
print("cancelUnifiedCoupon error: ")
print(error)
print("====================")
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_cancel_unified_coupon"
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)
}
}
}
}
......