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

Support expired subscription state and subscription repurchase #2707

Merged
merged 15 commits into from
May 3, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
Expand All @@ -138,7 +138,7 @@
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
static let subscriptionsUnknownPriceClicked = "subscriptionsUnknownPriceClicked"
static let subscriptionsAddEmailSuccess = "subscriptionsAddEmailSuccess"
static let subscriptionsWelcomeFaqClicked = "subscriptionsWelcomeFaqClicked"
static let getAccessToken = "getAccessToken"
}

// swiftlint:disable:next cyclomatic_complexity
Expand All @@ -124,6 +125,7 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
case Handlers.subscriptionsUnknownPriceClicked: return subscriptionsUnknownPriceClicked
case Handlers.subscriptionsAddEmailSuccess: return subscriptionsAddEmailSuccess
case Handlers.subscriptionsWelcomeFaqClicked: return subscriptionsWelcomeFaqClicked
case Handlers.getAccessToken: return getAccessToken
default:
return nil
}
Expand All @@ -142,11 +144,8 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
}

func getSubscription(params: Any, original: WKScriptMessage) async throws -> Encodable? {
if let authToken = accountManager.authToken, accountManager.accessToken != nil {
return Subscription(token: authToken)
} else {
return Subscription(token: "")
}
let authToken = accountManager.authToken ?? ""
return Subscription(token: authToken)
}

func setSubscription(params: Any, original: WKScriptMessage) async throws -> Encodable? {
Expand Down Expand Up @@ -451,6 +450,14 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
return nil
}

func getAccessToken(params: Any, original: WKScriptMessage) async throws -> Encodable? {
if let accessToken = AccountManager(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs)).accessToken {
return ["token": accessToken]
} else {
return [String: String]()
}
}

// MARK: Push actions

enum SubscribeActionName: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,13 @@ public struct PreferencesSubscriptionView: View {
TextMenuItemCaption(UserText.preferencesSubscriptionExpiredCaption)
} buttons: {
// We need to improve re-purchase flow
/* Button(UserText.viewPlansButtonTitle) { model.purchaseAction() }
.buttonStyle(DefaultActionButtonStyle(enabled: true)) */
Button(UserText.viewPlansExpiredButtonTitle) { model.purchaseAction() }
.buttonStyle(DefaultActionButtonStyle(enabled: true))
Menu {
Button(UserText.addToAnotherDeviceButton) {
model.userEventHandler(.addToAnotherDeviceClick)
showingSheet.toggle()
}
Button(UserText.removeFromThisDeviceButton, action: {
showingRemoveConfirmationDialog.toggle()
})
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum UserText {
}

static func preferencesSubscriptionExpiredCaption(formattedDate: String) -> String {
let localized = NSLocalizedString("subscription.preferences.subscription.expired.caption", value: "Your Privacy Pro subscription expired on %@.", comment: "Caption for the subscription preferences pane when the subscription has expired. The parameter is date of expiry.")
let localized = NSLocalizedString("subscription.preferences.subscription.expired.caption", value: "Your Privacy Pro subscription expired on %@", comment: "Caption for the subscription preferences pane when the subscription has expired. The parameter is date of expiry.")
return String(format: localized, formattedDate)
}

Expand All @@ -64,8 +64,8 @@ enum UserText {

static let addToAnotherDeviceButton = NSLocalizedString("subscription.preferences.add.to.another.device.button", value: "Add to Another Device…", comment: "Button to add subscription to another device")
static let manageSubscriptionButton = NSLocalizedString("subscription.preferences.manage.subscription.button", value: "Manage Subscription", comment: "Button to manage subscription")
static let changePlanOrBillingButton = NSLocalizedString("subscription.preferences.change.plan.or.billing.button", value: "Change Plan or Billing...", comment: "Button to add subscription to another device")
static let removeFromThisDeviceButton = NSLocalizedString("subscription.preferences.remove.from.this.device.button", value: "Remove From This Device...", comment: "Button to remove subscription from this device")
static let changePlanOrBillingButton = NSLocalizedString("subscription.preferences.change.plan.or.billing.button", value: "Change Plan or Billing", comment: "Button to add subscription to another device")
static let removeFromThisDeviceButton = NSLocalizedString("subscription.preferences.remove.from.this.device.button", value: "Remove From This Device", comment: "Button to remove subscription from this device")

// MARK: Preferences when subscription is inactive
static let preferencesSubscriptionInactiveHeader = NSLocalizedString("subscription.preferences.subscription.inactive.header", value: "Subscribe to Privacy Pro", comment: "Header for the subscription preferences pane when the subscription is inactive")
Expand All @@ -81,6 +81,7 @@ enum UserText {
// MARK: Preferences when subscription is expired
static let preferencesSubscriptionExpiredCaption = NSLocalizedString("subscription.preferences.subscription.expired.caption", value: "Subscribe again to continue using Privacy Pro.", comment: "Caption for the subscription preferences pane when the subscription activation is pending")

static let viewPlansExpiredButtonTitle = NSLocalizedString("subscription.preferences.button.view.plans", value: "View Plans…", comment: "Button for viewing subscription plans on expired subscription")
static let manageDevicesButton = NSLocalizedString("subscription.preferences.manage.devices.button", value: "Manage Devices", comment: "Button to manage devices")

// MARK: - Change plan or billing dialogs
Expand Down
Loading