Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action sheet with payment options for 30 and 90 days #7468

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
58677710290975E9006F721F /* SettingsInteractorFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5867770F290975E8006F721F /* SettingsInteractorFactory.swift */; };
58677712290976FB006F721F /* SettingsInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58677711290976FB006F721F /* SettingsInteractor.swift */; };
5867771429097BCD006F721F /* PaymentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5867771329097BCD006F721F /* PaymentState.swift */; };
5867771629097C5B006F721F /* ProductState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5867771529097C5B006F721F /* ProductState.swift */; };
5868585524054096000B8131 /* CustomButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5868585424054096000B8131 /* CustomButton.swift */; };
586A0DCB2A20E359006C731C /* MullvadTypes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 58D223D5294C8E5E0029F5F8 /* MullvadTypes.framework */; };
586A0DD12A20E371006C731C /* WireGuardKitTypes in Frameworks */ = {isa = PBXBuildFile; productRef = 586A0DD02A20E371006C731C /* WireGuardKitTypes */; };
Expand Down Expand Up @@ -1055,6 +1054,9 @@
F0F56B092C0E058A009D676B /* ObserverList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58CC40EE24A601900019D96E /* ObserverList.swift */; };
F0FADDEA2BE90AAA000D0B02 /* LaunchArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0F1EF8C2BE8FF0A00CED01D /* LaunchArguments.swift */; };
F0FADDEC2BE90AB0000D0B02 /* LaunchArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0F1EF8C2BE8FF0A00CED01D /* LaunchArguments.swift */; };
F95C1C252D3E5E8E00EBE769 /* UIAlertController+InAppPurchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95C1C242D3E5E7A00EBE769 /* UIAlertController+InAppPurchase.swift */; };
F998EFF82D359C4600D88D01 /* SKProduct+Formatting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD5BEF24238EB300112C88 /* SKProduct+Formatting.swift */; };
F998EFFA2D3656BA00D88D01 /* SKProduct+Sorting.swift in Sources */ = {isa = PBXBuildFile; fileRef = F998EFF92D3656B100D88D01 /* SKProduct+Sorting.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -1613,7 +1615,6 @@
5867770F290975E8006F721F /* SettingsInteractorFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsInteractorFactory.swift; sourceTree = "<group>"; };
58677711290976FB006F721F /* SettingsInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsInteractor.swift; sourceTree = "<group>"; };
5867771329097BCD006F721F /* PaymentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentState.swift; sourceTree = "<group>"; };
5867771529097C5B006F721F /* ProductState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductState.swift; sourceTree = "<group>"; };
5868585424054096000B8131 /* CustomButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomButton.swift; sourceTree = "<group>"; };
58695A9F2A4ADA9200328DB3 /* TunnelObfuscationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelObfuscationTests.swift; sourceTree = "<group>"; };
586A95112901321B007BAF2B /* IPv6Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPv6Endpoint.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2311,6 +2312,8 @@
F0F316182BF3572B0078DBCF /* RelaySelectorResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaySelectorResult.swift; sourceTree = "<group>"; };
F0F3161A2BF358590078DBCF /* NoRelaysSatisfyingConstraintsError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoRelaysSatisfyingConstraintsError.swift; sourceTree = "<group>"; };
F0FBD98E2C4A60CC00EE5323 /* KeyExchangingResultStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyExchangingResultStub.swift; sourceTree = "<group>"; };
F95C1C242D3E5E7A00EBE769 /* UIAlertController+InAppPurchase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertController+InAppPurchase.swift"; sourceTree = "<group>"; };
F998EFF92D3656B100D88D01 /* SKProduct+Sorting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SKProduct+Sorting.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -3106,7 +3109,6 @@
58CCA01722426713004F3011 /* AccountViewController.swift */,
7A1A26422A2612AE00B978AA /* PaymentAlertPresenter.swift */,
5867771329097BCD006F721F /* PaymentState.swift */,
5867771529097C5B006F721F /* ProductState.swift */,
7A7B3AB52C6DE4DA00D4BCCE /* RestorePurchasesView.swift */,
);
path = Account;
Expand Down Expand Up @@ -3152,10 +3154,12 @@
58B9EB142489139B00095626 /* RESTError+Display.swift */,
58A8EE592976BFBB009C0F8D /* SKError+Localized.swift */,
58FD5BEF24238EB300112C88 /* SKProduct+Formatting.swift */,
F998EFF92D3656B100D88D01 /* SKProduct+Sorting.swift */,
58A8EE5D2976DB00009C0F8D /* StorePaymentManagerError+Display.swift */,
E158B35F285381C60002F069 /* String+AccountFormatting.swift */,
7A09C98029D99215000C2CAC /* String+FuzzyMatch.swift */,
5807E2BF2432038B00F5FF30 /* String+Helpers.swift */,
F95C1C242D3E5E7A00EBE769 /* UIAlertController+InAppPurchase.swift */,
58CEB2F82AFD136E00E6E088 /* UIBackgroundConfiguration+Extensions.swift */,
5891BF5025E66B1E006D6FB0 /* UIBarButtonItem+KeyboardNavigation.swift */,
587CBFE222807F530028DED3 /* UIColor+Helpers.swift */,
Expand Down Expand Up @@ -5658,6 +5662,7 @@
7AD63A3F2CDA53F600445268 /* ObfuscationMethodSelectorTests.swift in Sources */,
44DD7D292B7113CA0005F67F /* MockTunnel.swift in Sources */,
A9A5FA142ACB05160083449F /* MapConnectionStatusOperation.swift in Sources */,
F998EFF82D359C4600D88D01 /* SKProduct+Formatting.swift in Sources */,
A9A5FA152ACB05160083449F /* RedeemVoucherOperation.swift in Sources */,
A9A5FA162ACB05160083449F /* RotateKeyOperation.swift in Sources */,
7AD63A3D2CD9065D00445268 /* ObfuscatorPortSelectorTests.swift in Sources */,
Expand Down Expand Up @@ -5995,6 +6000,7 @@
58968FAE28743E2000B799DC /* TunnelInteractor.swift in Sources */,
7A1A26472A29CF0800B978AA /* RelayFilterDataSource.swift in Sources */,
5864AF0929C78850005B0CD9 /* VPNSettingsCellFactory.swift in Sources */,
F998EFFA2D3656BA00D88D01 /* SKProduct+Sorting.swift in Sources */,
F050AE4E2B70D7F8003F4EDB /* LocationCellViewModel.swift in Sources */,
58CEB30C2AFD586600E6E088 /* DynamicBackgroundConfiguration.swift in Sources */,
587B7536266528A200DEF7E9 /* NotificationManager.swift in Sources */,
Expand Down Expand Up @@ -6082,7 +6088,6 @@
5868585524054096000B8131 /* CustomButton.swift in Sources */,
58E25F812837BBBB002CFB2C /* SceneDelegate.swift in Sources */,
7A1A26492A29D48A00B978AA /* RelayFilterCellFactory.swift in Sources */,
5867771629097C5B006F721F /* ProductState.swift in Sources */,
7A28826A2BA8336600FD9F20 /* VPNSettingsCoordinator.swift in Sources */,
7A6389DE2B7E3BD6008E77E1 /* CustomListItemIdentifier.swift in Sources */,
58C76A082A33850E00100D75 /* ApplicationTarget.swift in Sources */,
Expand Down Expand Up @@ -6177,6 +6182,7 @@
A9E034642ABB302000E59A5A /* UIEdgeInsets+Extensions.swift in Sources */,
58CEB2E92AFBBA4A00E6E088 /* AddAccessMethodCoordinator.swift in Sources */,
58DFF7D02B02560400F864E0 /* NSAttributedString+Extensions.swift in Sources */,
F95C1C252D3E5E8E00EBE769 /* UIAlertController+InAppPurchase.swift in Sources */,
58E0A98827C8F46300FE6BDD /* Tunnel.swift in Sources */,
7A12D0762B062D5C00E9602D /* URLSessionProtocol.swift in Sources */,
58ACF64F26567A7100ACE4B7 /* CustomSwitchContainer.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPN/Classes/AccessbilityIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public enum AccessibilityIdentifier: Equatable {
case selectLocationFilterButton
case relayFilterChipCloseButton
case openPortSelectorMenuButton

case cancelPurchaseListButton
// Cells
case deviceCell
case accessMethodProtocolSelectionCell
Expand Down
50 changes: 50 additions & 0 deletions ios/MullvadVPN/Coordinators/AccountCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Routing
import StoreKit
import UIKit

enum AccountDismissReason: Equatable, Sendable {
Expand Down Expand Up @@ -67,9 +68,26 @@ final class AccountCoordinator: Coordinator, Presentable, Presenting, @unchecked
navigateToDeleteAccount()
case .restorePurchasesInfo:
showRestorePurchasesInfo()
case let .showPurchaseOptions(details):
showPurchaseOptions(
products: details.products,
accountNumber: details.accountNumber,
didRequestPurchase: details.didRequestPurchase
)
case .showFailedToLoadProducts:
showFailToFetchProducts()
}
}

func showPurchaseOptions(
products: [SKProduct],
accountNumber: String,
didRequestPurchase: @escaping (_ product: SKProduct) -> Void
) {
let alert = UIAlertController.showInAppPurchaseAlert(products: products, didRequestPurchase: didRequestPurchase)
presentationContext.present(alert, animated: true)
}

private func navigateToRedeemVoucher() {
let coordinator = ProfileVoucherCoordinator(
navigationController: CustomNavigationController(),
Expand Down Expand Up @@ -230,4 +248,36 @@ final class AccountCoordinator: Coordinator, Presentable, Presenting, @unchecked
let presenter = AlertPresenter(context: self)
presenter.showAlert(presentation: presentation, animated: true)
}

func showFailToFetchProducts() {
let message = NSLocalizedString(
"WELCOME_FAILED_TO_FETCH_PRODUCTS_DIALOG",
tableName: "Welcome",
value:
"""
Failed to connect to App store, please try again later.
""",
comment: ""
)

let presentation = AlertPresentation(
id: "welcome-failed-to-fetch-products-alert",
icon: .info,
message: message,
buttons: [
AlertAction(
title: NSLocalizedString(
"WELCOME_FAILED_TO_FETCH_PRODUCTS_OK_ACTION",
tableName: "Welcome",
value: "Got it!",
comment: ""
),
style: .default
),
]
)

let presenter = AlertPresenter(context: self)
presenter.showAlert(presentation: presentation, animated: true)
}
}
42 changes: 42 additions & 0 deletions ios/MullvadVPN/Coordinators/OutOfTimeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Routing
import StoreKit
import UIKit

class OutOfTimeCoordinator: Coordinator, Presenting, @preconcurrency OutOfTimeViewControllerDelegate, Poppable {
Expand Down Expand Up @@ -82,4 +83,45 @@ class OutOfTimeCoordinator: Coordinator, Presenting, @preconcurrency OutOfTimeVi

didFinishPayment?(self)
}

func outOfTimeViewControllerDidRequestShowPurchaseOptions(
_ controller: OutOfTimeViewController,
products: [SKProduct],
didRequestPurchase: @escaping (SKProduct) -> Void
) {
let alert = UIAlertController.showInAppPurchaseAlert(products: products, didRequestPurchase: didRequestPurchase)
presentationContext.present(alert, animated: true)
}

func outOfTimeViewControllerDidFailToFetchProducts(_ controller: OutOfTimeViewController) {
let message = NSLocalizedString(
"WELCOME_FAILED_TO_FETCH_PRODUCTS_DIALOG",
tableName: "Welcome",
value:
"""
Failed to connect to App store, please try again later.
""",
comment: ""
)

let presentation = AlertPresentation(
id: "welcome-failed-to-fetch-products-alert",
icon: .info,
message: message,
buttons: [
AlertAction(
title: NSLocalizedString(
"WELCOME_FAILED_TO_FETCH_PRODUCTS_OK_ACTION",
tableName: "Welcome",
value: "Got it!",
comment: ""
),
style: .default
),
]
)

let presenter = AlertPresenter(context: self)
presenter.showAlert(presentation: presentation, animated: true)
}
}
48 changes: 48 additions & 0 deletions ios/MullvadVPN/Coordinators/WelcomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ final class WelcomeCoordinator: Coordinator, Poppable, Presenting {
}

extension WelcomeCoordinator: @preconcurrency WelcomeViewControllerDelegate {
func didRequestToShowFailToFetchProducts(controller: WelcomeViewController) {
let message = NSLocalizedString(
"WELCOME_FAILED_TO_FETCH_PRODUCTS_DIALOG",
tableName: "Welcome",
value:
"""
Failed to connect to App store, please try again later.
""",
comment: ""
)

let presentation = AlertPresentation(
id: "welcome-failed-to-fetch-products-alert",
icon: .info,
message: message,
buttons: [
AlertAction(
title: NSLocalizedString(
"WELCOME_FAILED_TO_FETCH_PRODUCTS_OK_ACTION",
tableName: "Welcome",
value: "Got it!",
comment: ""
),
style: .default
),
]
)

let presenter = AlertPresenter(context: self)
presenter.showAlert(presentation: presentation, animated: true)
}

func didRequestToShowInfo(controller: WelcomeViewController) {
let message = NSLocalizedString(
"WELCOME_DEVICE_CONCEPT_TEXT_DIALOG",
Expand Down Expand Up @@ -118,6 +150,22 @@ extension WelcomeCoordinator: @preconcurrency WelcomeViewControllerDelegate {
presenter.showAlert(presentation: presentation, animated: true)
}

func didRequestToViewPurchaseOptions(
controller: WelcomeViewController,
products: [SKProduct],
accountNumber: String
) {
let alert = UIAlertController.showInAppPurchaseAlert(products: products, didRequestPurchase: { product in
self.didRequestToPurchaseCredit(
controller: controller,
accountNumber: accountNumber,
product: product
)
})

presentationContext.present(alert, animated: true)
}

func didRequestToPurchaseCredit(controller: WelcomeViewController, accountNumber: String, product: SKProduct) {
navigationController.enableHeaderBarButtons(false)

Expand Down
15 changes: 15 additions & 0 deletions ios/MullvadVPN/Extensions/SKProduct+Sorting.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// SKProduct+Sorting.swift
// MullvadVPN
//
// Created by Steffen Ernst on 2025-01-14.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import StoreKit

extension Array where Element == SKProduct {
func sortedByPrice() -> [SKProduct] {
sorted { ($0.price as Decimal) < ($1.price as Decimal) }
}
}
48 changes: 48 additions & 0 deletions ios/MullvadVPN/Extensions/UIAlertController+InAppPurchase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// UIAlertController+InAppPurchase.swift
// MullvadVPN
//
// Created by Steffen Ernst on 2025-01-20.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import StoreKit
import UIKit

extension UIAlertController {
public static func showInAppPurchaseAlert(
products: [SKProduct],
didRequestPurchase: @escaping (SKProduct) -> Void
) -> UIAlertController {
let localizedString = NSLocalizedString(
"ADD_TIME_BUTTON",
tableName: "Welcome",
value: "Add Time",
comment: ""
)
let alert = UIAlertController(title: localizedString, message: nil, preferredStyle: .actionSheet)
products.sortedByPrice().forEach { product in
guard let localizedTitle = product.customLocalizedTitle else {
return
}
let action = UIAlertAction(title: localizedTitle, style: .default, handler: { _ in
alert.dismiss(animated: true, completion: {
didRequestPurchase(product)
})
})
action
.accessibilityIdentifier =
"\(AccessibilityIdentifier.purchaseButton.asString)_\(product.productIdentifier)"
alert.addAction(action)
}
let cancelAction = UIAlertAction(title: NSLocalizedString(
"PRODUCT_LIST_CANCEL_BUTTON",
tableName: "Welcome",
value: "Cancel",
comment: ""
), style: .cancel)
cancelAction.accessibilityIdentifier = AccessibilityIdentifier.cancelPurchaseListButton.asString
alert.addAction(cancelAction)
return alert
}
}
18 changes: 15 additions & 3 deletions ios/MullvadVPN/StorePaymentManager/StoreSubscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@
import Foundation
import StoreKit

enum StoreSubscription: String {
enum StoreSubscription: String, CaseIterable {
/// Thirty days non-renewable subscription
case thirtyDays = "net.mullvad.MullvadVPN.subscription.30days"
case ninetyDays = "net.mullvad.MullvadVPN.subscription.90days"

var localizedTitle: String {
switch self {
case .thirtyDays:
return NSLocalizedString(
"STORE_SUBSCRIPTION_TITLE_ADD_30_DAYS",
tableName: "StoreSubscriptions",
value: "Add 30 days time",
value: "Add 30 days",
comment: ""
)
case .ninetyDays:
return NSLocalizedString(
"STORE_SUBSCRIPTION_TITLE_ADD_90_DAYS",
tableName: "StoreSubscriptions",
value: "Add 90 days",
comment: ""
)
}
Expand All @@ -28,7 +36,11 @@ enum StoreSubscription: String {

extension SKProduct {
var customLocalizedTitle: String? {
StoreSubscription(rawValue: productIdentifier)?.localizedTitle
guard let localizedTitle = StoreSubscription(rawValue: productIdentifier)?.localizedTitle,
let localizedPrice else {
return nil
}
return "\(localizedTitle) (\(localizedPrice))"
}
}

Expand Down
Loading
Loading