Skip to content

Commit

Permalink
Support expired subscription state and subscription repurchase (#2707)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/72649045549333/1206382263248900/f

**Description**:
Support expired subscription state and subscription repurchase.
Repurchase is done on a platform that is matching the app distribution
(independent to where it was originally bought). Changes for supporting
repurchase flows are/were implemented in BSK in the following PRs:
- App Store repurchase:
duckduckgo/BrowserServicesKit#788
- Stripe repurchase:
duckduckgo/BrowserServicesKit#800

**Steps to test this PR**:
1. Activate expired subscription via email
2. Repurchase expired App Store subscription on Stripe
3. Repurchase expired Stripe subscription on App Store
4. Repurchase expired Stripe subscription on Stripe


---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)

---------

Co-authored-by: Daniel Bernal <[email protected]>
  • Loading branch information
miasma13 and afterxleep authored May 3, 2024
1 parent ea3f48f commit 780958d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
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

0 comments on commit 780958d

Please sign in to comment.