Showing
5 changed files
with
277 additions
and
21 deletions
| ... | @@ -84,6 +84,7 @@ | ... | @@ -84,6 +84,7 @@ |
| 84 | - (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 84 | - (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
| 85 | - (void)redeemCouponSetAsync:(NSString*)uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 85 | - (void)redeemCouponSetAsync:(NSString*)uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
| 86 | - (void)getPacingDetailsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 86 | - (void)getPacingDetailsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
| 87 | +- (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
| 87 | 88 | ||
| 88 | @end | 89 | @end |
| 89 | #endif /* MyApi_h */ | 90 | #endif /* MyApi_h */ | ... | ... |
| ... | @@ -1392,4 +1392,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; | ... | @@ -1392,4 +1392,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; |
| 1392 | }]; | 1392 | }]; |
| 1393 | } | 1393 | } |
| 1394 | 1394 | ||
| 1395 | +- (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
| 1396 | +{ | ||
| 1397 | + [[Warply sharedService] cosmoteSharingWithSuccessBlock:sharingId :^(NSDictionary *response) { | ||
| 1398 | + if (success) { | ||
| 1399 | + success(response); | ||
| 1400 | + } | ||
| 1401 | + } failureBlock:^(NSError *error) { | ||
| 1402 | + if (failure) { | ||
| 1403 | + failure(error); | ||
| 1404 | + } | ||
| 1405 | + }]; | ||
| 1406 | +} | ||
| 1407 | + | ||
| 1395 | @end | 1408 | @end | ... | ... |
| ... | @@ -374,6 +374,8 @@ WL_VERSION_INTERFACE() | ... | @@ -374,6 +374,8 @@ WL_VERSION_INTERFACE() |
| 374 | 374 | ||
| 375 | - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 375 | - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
| 376 | 376 | ||
| 377 | +- (void) cosmoteSharingWithSuccessBlock:(NSString*) sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
| 378 | + | ||
| 377 | - (void) validateCouponWithSuccessBlock:(NSString*) coupon :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 379 | - (void) validateCouponWithSuccessBlock:(NSString*) coupon :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
| 378 | 380 | ||
| 379 | - (void)loginCosmoteWithSuccessBlock:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 381 | - (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) | ... | @@ -1368,7 +1368,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 1368 | 1368 | ||
| 1369 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1369 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
| 1370 | { | 1370 | { |
| 1371 | - NSDictionary *postDictionary = @{@"coupon":@{@"action": @"get_user_coupons", @"fetch_data": @[@"transaction"]}}; | 1371 | + NSDictionary *postDictionary = @{@"coupon":@{@"action": @"get_user_coupons", @"fetch_data": @[@"transaction",@"communication"]}}; |
| 1372 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | 1372 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; |
| 1373 | [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | 1373 | [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { |
| 1374 | if (success) { | 1374 | if (success) { |
| ... | @@ -1917,6 +1917,47 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1917,6 +1917,47 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 1917 | }]; | 1917 | }]; |
| 1918 | } | 1918 | } |
| 1919 | 1919 | ||
| 1920 | +- (void) cosmoteSharingWithSuccessBlock:(NSString*) sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
| 1921 | +{ | ||
| 1922 | + NSDictionary *postDictionary = @{@"wallet": @{@"action": @"sharing_info", @"sharing_id": sharingId}}; | ||
| 1923 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
| 1924 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
| 1925 | + if (success) { | ||
| 1926 | + success(contextResponse); | ||
| 1927 | + } | ||
| 1928 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
| 1929 | + NSLog(@"%@", contextResponse ); | ||
| 1930 | + } failureBlock:^(NSError *error) { | ||
| 1931 | + if (failure) { | ||
| 1932 | + NSDictionary* dict = [NSDictionary alloc]; | ||
| 1933 | + dict = [error userInfo]; | ||
| 1934 | + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"]; | ||
| 1935 | + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) { | ||
| 1936 | + [self refreshToken:^(NSDictionary *response) { | ||
| 1937 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
| 1938 | + if (success) { | ||
| 1939 | + success(contextResponse); | ||
| 1940 | + } | ||
| 1941 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
| 1942 | + NSLog(@"%@", contextResponse ); | ||
| 1943 | + } failureBlock:^(NSError *error) { | ||
| 1944 | + if (failure) { | ||
| 1945 | + failure(error); | ||
| 1946 | + } | ||
| 1947 | + }]; | ||
| 1948 | + } failureBlock:^(NSError *error) { | ||
| 1949 | + if (failure) { | ||
| 1950 | + [_db executeUpdate:@"DROP TABLE requestVariables"]; | ||
| 1951 | + failure(error); | ||
| 1952 | + } | ||
| 1953 | + NSLog(@"Error at token %@", error ); | ||
| 1954 | + }]; | ||
| 1955 | + } | ||
| 1956 | + NSLog(@"Error at get cosmote sharing %@", error ); | ||
| 1957 | + } | ||
| 1958 | + }]; | ||
| 1959 | +} | ||
| 1960 | + | ||
| 1920 | - (void) validateCouponWithSuccessBlock:(NSString*) coupon :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1961 | - (void) validateCouponWithSuccessBlock:(NSString*) coupon :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
| 1921 | { | 1962 | { |
| 1922 | NSDictionary *postDictionary = @{@"coupon": @{@"action": @"validate", @"coupon": coupon}}; | 1963 | NSDictionary *postDictionary = @{@"coupon": @{@"action": @"validate", @"coupon": coupon}}; | ... | ... |
| ... | @@ -1601,27 +1601,159 @@ public class swiftApi { | ... | @@ -1601,27 +1601,159 @@ public class swiftApi { |
| 1601 | return finalUrl | 1601 | return finalUrl |
| 1602 | } | 1602 | } |
| 1603 | 1603 | ||
| 1604 | - public func constructCampaignUrlForShare(_ sessionUuid: String, _ sharingId: String) -> String { | 1604 | + public func handleSharing(_ controller: UIViewController, _ sharingId: String) -> Void { |
| 1605 | - for item in GlobalVariables.campaigns { | 1605 | + |
| 1606 | - if (item.session_uuid == sessionUuid) { | 1606 | + self.cosmoteSharingAsync(sharingId: sharingId, sharingCallback) |
| 1607 | - let instanceOfMyApi = MyApi() | 1607 | + |
| 1608 | - let campaignInfo = instanceOfMyApi.provideInfoForCampaign() | 1608 | + func sharingCallback (_ sharingData: SharingResponseModel?) -> Void { |
| 1609 | - let finalUrl = (item.index_url ?? "") | 1609 | + if (sharingData != nil) { |
| 1610 | - + "?web_id=" + (campaignInfo?["web_id"] as! String) | 1610 | + DispatchQueue.main.async { |
| 1611 | - + "&app_uuid=" + (campaignInfo?["app_uuid"] as! String) | 1611 | + print("========= DispatchQueue sharingCallback SUCCESSSS =========") |
| 1612 | - + "&api_key=" + (campaignInfo?["api_key"] as! String) | 1612 | + print(sharingData) |
| 1613 | - + "&session_uuid=" + (item.session_uuid ?? "") | 1613 | + print(sharingData?._modal_text) |
| 1614 | - + "&access_token=" + (campaignInfo?["access_token"] as! String) | 1614 | + print(sharingData?._status) |
| 1615 | - + "&refresh_token=" + (campaignInfo?["refresh_token"] as! String) | 1615 | + |
| 1616 | - + "&client_id=" + (campaignInfo?["client_id"] as! String) | 1616 | + if (sharingData?._status != nil && sharingData?._status != "" && sharingData?._status == "pending") { |
| 1617 | - + "&client_secret=" + (campaignInfo?["client_secret"] as! String) | 1617 | + self.initialSharingDialog(controller, sharingData?._modal_text ?? "", sharingId) |
| 1618 | - + "&sharing_id=" + sharingId; | 1618 | + |
| 1619 | - | 1619 | + } else if (sharingData?._status != nil && sharingData?._status != "" && sharingData?._status == "reject") { |
| 1620 | - return finalUrl | 1620 | + self.returnSharingDialog(controller, sharingData?._modal_text ?? "") |
| 1621 | - break; | 1621 | + } |
| 1622 | + } | ||
| 1623 | + } else { // status != 1 | ||
| 1624 | + errorSharingDialog(controller) | ||
| 1622 | } | 1625 | } |
| 1623 | } | 1626 | } |
| 1624 | - return "" | 1627 | + |
| 1628 | +// initialSharingDialog(controller, alertTitle, "") | ||
| 1629 | +// acceptSharingDialog(controller) | ||
| 1630 | +// rejectSharingDialog(controller, "") | ||
| 1631 | +// returnSharingDialog(controller, alertTitle) | ||
| 1632 | +// errorSharingDialog(controller) | ||
| 1633 | + | ||
| 1634 | + } | ||
| 1635 | + | ||
| 1636 | + func initialSharingDialog(_ controller: UIViewController, _ alertTitle: String, _ sharingId: String) -> Void { | ||
| 1637 | + | ||
| 1638 | + let alert = UIAlertController(title: "Συγχαρητήρια!", message: alertTitle, preferredStyle: .alert) | ||
| 1639 | + alert.addAction(UIAlertAction(title: "Ενεργοποίηση", style: .default, handler: { action in | ||
| 1640 | + switch action.style{ | ||
| 1641 | + case .default: | ||
| 1642 | + // TODO: add cosmoteRetrieveSharing request | ||
| 1643 | + print("default 1") | ||
| 1644 | + | ||
| 1645 | + case .cancel: | ||
| 1646 | + print("cancel 1") | ||
| 1647 | + | ||
| 1648 | + case .destructive: | ||
| 1649 | + print("destructive 1") | ||
| 1650 | + | ||
| 1651 | + } | ||
| 1652 | + })) | ||
| 1653 | + alert.addAction(UIAlertAction(title: "Απόρριψη", style: .default, handler: { action in | ||
| 1654 | + switch action.style{ | ||
| 1655 | + case .default: | ||
| 1656 | + rejectSharingDialog(controller, "") | ||
| 1657 | + print("default 2") | ||
| 1658 | + | ||
| 1659 | + case .cancel: | ||
| 1660 | + print("cancel 2") | ||
| 1661 | + | ||
| 1662 | + case .destructive: | ||
| 1663 | + print("destructive 2") | ||
| 1664 | + | ||
| 1665 | + } | ||
| 1666 | + })) | ||
| 1667 | + controller.present(alert, animated: true, completion: nil) | ||
| 1668 | + } | ||
| 1669 | + | ||
| 1670 | + func acceptSharingDialog(_ controller: UIViewController) -> Void { | ||
| 1671 | + | ||
| 1672 | + let alert = UIAlertController(title: "Συγχαρητήρια!", message: "Μόλις έλαβες το δώρο σου!", preferredStyle: .alert) | ||
| 1673 | + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in | ||
| 1674 | + switch action.style{ | ||
| 1675 | + case .default: | ||
| 1676 | + print("default 1") | ||
| 1677 | + | ||
| 1678 | + case .cancel: | ||
| 1679 | + print("cancel 1") | ||
| 1680 | + | ||
| 1681 | + case .destructive: | ||
| 1682 | + print("destructive 1") | ||
| 1683 | + | ||
| 1684 | + } | ||
| 1685 | + })) | ||
| 1686 | + controller.present(alert, animated: true, completion: nil) | ||
| 1687 | + } | ||
| 1688 | + | ||
| 1689 | + func rejectSharingDialog(_ controller: UIViewController, _ sharingId: String) -> Void { | ||
| 1690 | + | ||
| 1691 | + let alert = UIAlertController(title: "Είσαι σίγουρος;", message: "Είσαι σίγουρος ότι θέλεις να απορρίψεις το δώρο που μόλις έλαβες;", preferredStyle: .alert) | ||
| 1692 | + alert.addAction(UIAlertAction(title: "Απόρριψη", style: .default, handler: { action in | ||
| 1693 | + switch action.style{ | ||
| 1694 | + case .default: | ||
| 1695 | + print("default 1") | ||
| 1696 | + | ||
| 1697 | + case .cancel: | ||
| 1698 | + print("cancel 1") | ||
| 1699 | + | ||
| 1700 | + case .destructive: | ||
| 1701 | + print("destructive 1") | ||
| 1702 | + | ||
| 1703 | + } | ||
| 1704 | + })) | ||
| 1705 | + alert.addAction(UIAlertAction(title: "Άκυρο", style: .default, handler: { action in | ||
| 1706 | + switch action.style{ | ||
| 1707 | + case .default: | ||
| 1708 | + print("default 2") | ||
| 1709 | + | ||
| 1710 | + case .cancel: | ||
| 1711 | + print("cancel 2") | ||
| 1712 | + | ||
| 1713 | + case .destructive: | ||
| 1714 | + print("destructive 2") | ||
| 1715 | + | ||
| 1716 | + } | ||
| 1717 | + })) | ||
| 1718 | + controller.present(alert, animated: true, completion: nil) | ||
| 1719 | + } | ||
| 1720 | + | ||
| 1721 | + func returnSharingDialog(_ controller: UIViewController, _ alertTitle: String) -> Void { | ||
| 1722 | + | ||
| 1723 | + let alert = UIAlertController(title: "Επιστροφή δώρου", message: alertTitle, preferredStyle: .alert) | ||
| 1724 | + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in | ||
| 1725 | + switch action.style{ | ||
| 1726 | + case .default: | ||
| 1727 | + print("default 1") | ||
| 1728 | + | ||
| 1729 | + case .cancel: | ||
| 1730 | + print("cancel 1") | ||
| 1731 | + | ||
| 1732 | + case .destructive: | ||
| 1733 | + print("destructive 1") | ||
| 1734 | + | ||
| 1735 | + } | ||
| 1736 | + })) | ||
| 1737 | + controller.present(alert, animated: true, completion: nil) | ||
| 1738 | + } | ||
| 1739 | + | ||
| 1740 | + func errorSharingDialog(_ controller: UIViewController) -> Void { | ||
| 1741 | + | ||
| 1742 | + let alert = UIAlertController(title: "Αποτυχία", message: "Κάτι πήγε στραβά", preferredStyle: .alert) | ||
| 1743 | + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in | ||
| 1744 | + switch action.style{ | ||
| 1745 | + case .default: | ||
| 1746 | + print("default 1") | ||
| 1747 | + | ||
| 1748 | + case .cancel: | ||
| 1749 | + print("cancel 1") | ||
| 1750 | + | ||
| 1751 | + case .destructive: | ||
| 1752 | + print("destructive 1") | ||
| 1753 | + | ||
| 1754 | + } | ||
| 1755 | + })) | ||
| 1756 | + controller.present(alert, animated: true, completion: nil) | ||
| 1625 | } | 1757 | } |
| 1626 | 1758 | ||
| 1627 | 1759 | ||
| ... | @@ -1931,7 +2063,7 @@ public class swiftApi { | ... | @@ -1931,7 +2063,7 @@ public class swiftApi { |
| 1931 | } | 2063 | } |
| 1932 | 2064 | ||
| 1933 | func requestFailureCallback(_ error: Error?) -> Void { | 2065 | func requestFailureCallback(_ error: Error?) -> Void { |
| 1934 | - print("consumerIntegration error: ") | 2066 | + print("redeemCouponSet error: ") |
| 1935 | print(error) | 2067 | print(error) |
| 1936 | print("====================") | 2068 | print("====================") |
| 1937 | redeemCouponSetCallback(nil) | 2069 | redeemCouponSetCallback(nil) |
| ... | @@ -2406,4 +2538,71 @@ public class swiftApi { | ... | @@ -2406,4 +2538,71 @@ public class swiftApi { |
| 2406 | } | 2538 | } |
| 2407 | } | 2539 | } |
| 2408 | 2540 | ||
| 2541 | + | ||
| 2542 | + public class SharingResponseModel { | ||
| 2543 | + private var modal_text: String | ||
| 2544 | + private var status: String | ||
| 2545 | + | ||
| 2546 | + init() { | ||
| 2547 | + self.modal_text = "" | ||
| 2548 | + self.status = "" | ||
| 2549 | + } | ||
| 2550 | + | ||
| 2551 | + init(dictionary: [String: Any]) { | ||
| 2552 | + self.modal_text = dictionary["modal_text"] as? String ?? "" | ||
| 2553 | + self.status = dictionary["status"] as? String ?? "" | ||
| 2554 | + } | ||
| 2555 | + | ||
| 2556 | + public var _modal_text: String { | ||
| 2557 | + get { // getter | ||
| 2558 | + return self.modal_text | ||
| 2559 | + } | ||
| 2560 | + set(newValue) { //setter | ||
| 2561 | + self.modal_text = newValue | ||
| 2562 | + } | ||
| 2563 | + } | ||
| 2564 | + | ||
| 2565 | + public var _status: String { | ||
| 2566 | + get { // getter | ||
| 2567 | + return self.status | ||
| 2568 | + } | ||
| 2569 | + set(newValue) { //setter | ||
| 2570 | + self.status = newValue | ||
| 2571 | + } | ||
| 2572 | + } | ||
| 2573 | + } | ||
| 2574 | + | ||
| 2575 | + | ||
| 2576 | + public func cosmoteSharingAsync(sharingId: String, _ cosmoteSharingCallback: @escaping (_ responseData: SharingResponseModel?) -> Void) -> Void { | ||
| 2577 | + | ||
| 2578 | + let instanceOfMyApi = MyApi() | ||
| 2579 | + instanceOfMyApi.cosmoteSharingAsync(sharingId, requestCallback, failureBlock: requestFailureCallback) | ||
| 2580 | + | ||
| 2581 | + func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void { | ||
| 2582 | + | ||
| 2583 | + if let responseDataDictionary = responseData as? [String: AnyObject] { | ||
| 2584 | + if (responseDataDictionary["status"] as? Int == 1) { | ||
| 2585 | + let responseDataResult = (responseDataDictionary["result"] as? [String: Any] ?? [String: Any]()) | ||
| 2586 | + | ||
| 2587 | + let tempResponse = SharingResponseModel(dictionary: responseDataResult) | ||
| 2588 | + cosmoteSharingCallback(tempResponse); | ||
| 2589 | + } else { | ||
| 2590 | + cosmoteSharingCallback(nil) | ||
| 2591 | + } | ||
| 2592 | + | ||
| 2593 | + | ||
| 2594 | + } else { | ||
| 2595 | + cosmoteSharingCallback(nil) | ||
| 2596 | + } | ||
| 2597 | + | ||
| 2598 | + } | ||
| 2599 | + | ||
| 2600 | + func requestFailureCallback(_ error: Error?) -> Void { | ||
| 2601 | + print("cosmoteSharing error: ") | ||
| 2602 | + print(error) | ||
| 2603 | + print("====================") | ||
| 2604 | + cosmoteSharingCallback(nil) | ||
| 2605 | + } | ||
| 2606 | + } | ||
| 2607 | + | ||
| 2409 | } | 2608 | } | ... | ... |
-
Please register or login to post a comment