Manos Chorianopoulos

add handleSharing, cosmoteSharingAsync

......@@ -84,6 +84,7 @@
- (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)redeemCouponSetAsync:(NSString*)uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getPacingDetailsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
@end
#endif /* MyApi_h */
......
......@@ -1392,4 +1392,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
- (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] cosmoteSharingWithSuccessBlock:sharingId :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
@end
......
......@@ -374,6 +374,8 @@ WL_VERSION_INTERFACE()
- (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) cosmoteSharingWithSuccessBlock:(NSString*) sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) validateCouponWithSuccessBlock:(NSString*) coupon :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)loginCosmoteWithSuccessBlock:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -1368,7 +1368,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSDictionary *postDictionary = @{@"coupon":@{@"action": @"get_user_coupons", @"fetch_data": @[@"transaction"]}};
NSDictionary *postDictionary = @{@"coupon":@{@"action": @"get_user_coupons", @"fetch_data": @[@"transaction",@"communication"]}};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
[self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
......@@ -1917,6 +1917,47 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
- (void) cosmoteSharingWithSuccessBlock:(NSString*) sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSDictionary *postDictionary = @{@"wallet": @{@"action": @"sharing_info", @"sharing_id": sharingId}};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary 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)"]) {
[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 );
}];
}
NSLog(@"Error at get cosmote sharing %@", error );
}
}];
}
- (void) validateCouponWithSuccessBlock:(NSString*) coupon :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSDictionary *postDictionary = @{@"coupon": @{@"action": @"validate", @"coupon": coupon}};
......
......@@ -1601,27 +1601,159 @@ public class swiftApi {
return finalUrl
}
public func constructCampaignUrlForShare(_ sessionUuid: String, _ sharingId: String) -> String {
for item in GlobalVariables.campaigns {
if (item.session_uuid == sessionUuid) {
let instanceOfMyApi = MyApi()
let campaignInfo = instanceOfMyApi.provideInfoForCampaign()
let finalUrl = (item.index_url ?? "")
+ "?web_id=" + (campaignInfo?["web_id"] as! String)
+ "&app_uuid=" + (campaignInfo?["app_uuid"] as! String)
+ "&api_key=" + (campaignInfo?["api_key"] as! String)
+ "&session_uuid=" + (item.session_uuid ?? "")
+ "&access_token=" + (campaignInfo?["access_token"] as! String)
+ "&refresh_token=" + (campaignInfo?["refresh_token"] as! String)
+ "&client_id=" + (campaignInfo?["client_id"] as! String)
+ "&client_secret=" + (campaignInfo?["client_secret"] as! String)
+ "&sharing_id=" + sharingId;
return finalUrl
break;
public func handleSharing(_ controller: UIViewController, _ sharingId: String) -> Void {
self.cosmoteSharingAsync(sharingId: sharingId, sharingCallback)
func sharingCallback (_ sharingData: SharingResponseModel?) -> Void {
if (sharingData != nil) {
DispatchQueue.main.async {
print("========= DispatchQueue sharingCallback SUCCESSSS =========")
print(sharingData)
print(sharingData?._modal_text)
print(sharingData?._status)
if (sharingData?._status != nil && sharingData?._status != "" && sharingData?._status == "pending") {
self.initialSharingDialog(controller, sharingData?._modal_text ?? "", sharingId)
} else if (sharingData?._status != nil && sharingData?._status != "" && sharingData?._status == "reject") {
self.returnSharingDialog(controller, sharingData?._modal_text ?? "")
}
}
} else { // status != 1
errorSharingDialog(controller)
}
}
return ""
// initialSharingDialog(controller, alertTitle, "")
// acceptSharingDialog(controller)
// rejectSharingDialog(controller, "")
// returnSharingDialog(controller, alertTitle)
// errorSharingDialog(controller)
}
func initialSharingDialog(_ controller: UIViewController, _ alertTitle: String, _ sharingId: String) -> Void {
let alert = UIAlertController(title: "Συγχαρητήρια!", message: alertTitle, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ενεργοποίηση", style: .default, handler: { action in
switch action.style{
case .default:
// TODO: add cosmoteRetrieveSharing request
print("default 1")
case .cancel:
print("cancel 1")
case .destructive:
print("destructive 1")
}
}))
alert.addAction(UIAlertAction(title: "Απόρριψη", style: .default, handler: { action in
switch action.style{
case .default:
rejectSharingDialog(controller, "")
print("default 2")
case .cancel:
print("cancel 2")
case .destructive:
print("destructive 2")
}
}))
controller.present(alert, animated: true, completion: nil)
}
func acceptSharingDialog(_ controller: UIViewController) -> Void {
let alert = UIAlertController(title: "Συγχαρητήρια!", message: "Μόλις έλαβες το δώρο σου!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default 1")
case .cancel:
print("cancel 1")
case .destructive:
print("destructive 1")
}
}))
controller.present(alert, animated: true, completion: nil)
}
func rejectSharingDialog(_ controller: UIViewController, _ sharingId: String) -> Void {
let alert = UIAlertController(title: "Είσαι σίγουρος;", message: "Είσαι σίγουρος ότι θέλεις να απορρίψεις το δώρο που μόλις έλαβες;", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Απόρριψη", style: .default, handler: { action in
switch action.style{
case .default:
print("default 1")
case .cancel:
print("cancel 1")
case .destructive:
print("destructive 1")
}
}))
alert.addAction(UIAlertAction(title: "Άκυρο", style: .default, handler: { action in
switch action.style{
case .default:
print("default 2")
case .cancel:
print("cancel 2")
case .destructive:
print("destructive 2")
}
}))
controller.present(alert, animated: true, completion: nil)
}
func returnSharingDialog(_ controller: UIViewController, _ alertTitle: String) -> Void {
let alert = UIAlertController(title: "Επιστροφή δώρου", message: alertTitle, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default 1")
case .cancel:
print("cancel 1")
case .destructive:
print("destructive 1")
}
}))
controller.present(alert, animated: true, completion: nil)
}
func errorSharingDialog(_ controller: UIViewController) -> Void {
let alert = UIAlertController(title: "Αποτυχία", message: "Κάτι πήγε στραβά", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default 1")
case .cancel:
print("cancel 1")
case .destructive:
print("destructive 1")
}
}))
controller.present(alert, animated: true, completion: nil)
}
......@@ -1931,7 +2063,7 @@ public class swiftApi {
}
func requestFailureCallback(_ error: Error?) -> Void {
print("consumerIntegration error: ")
print("redeemCouponSet error: ")
print(error)
print("====================")
redeemCouponSetCallback(nil)
......@@ -2406,4 +2538,71 @@ public class swiftApi {
}
}
public class SharingResponseModel {
private var modal_text: String
private var status: String
init() {
self.modal_text = ""
self.status = ""
}
init(dictionary: [String: Any]) {
self.modal_text = dictionary["modal_text"] as? String ?? ""
self.status = dictionary["status"] as? String ?? ""
}
public var _modal_text: String {
get { // getter
return self.modal_text
}
set(newValue) { //setter
self.modal_text = newValue
}
}
public var _status: String {
get { // getter
return self.status
}
set(newValue) { //setter
self.status = newValue
}
}
}
public func cosmoteSharingAsync(sharingId: String, _ cosmoteSharingCallback: @escaping (_ responseData: SharingResponseModel?) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.cosmoteSharingAsync(sharingId, requestCallback, failureBlock: requestFailureCallback)
func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
if let responseDataDictionary = responseData as? [String: AnyObject] {
if (responseDataDictionary["status"] as? Int == 1) {
let responseDataResult = (responseDataDictionary["result"] as? [String: Any] ?? [String: Any]())
let tempResponse = SharingResponseModel(dictionary: responseDataResult)
cosmoteSharingCallback(tempResponse);
} else {
cosmoteSharingCallback(nil)
}
} else {
cosmoteSharingCallback(nil)
}
}
func requestFailureCallback(_ error: Error?) -> Void {
print("cosmoteSharing error: ")
print(error)
print("====================")
cosmoteSharingCallback(nil)
}
}
}
......