Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #5175: Add link vpn receipt button for Testflight builds (#6214)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub authored Oct 20, 2022
1 parent db833eb commit e926be2
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Client/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ class SettingsViewController: TableViewController {
return BraveVPN.vpnState.enableVPNDestinationVC
case .purchased:
let vc = BraveVPNSettingsViewController()
vc.faqButtonTapped = { [weak self] in
self?.settingsDelegate?.settingsOpenURLInNewTab(BraveUX.braveVPNFaqURL)
self?.dismiss(animated: true)
vc.openURL = { [unowned self] url in
self.settingsDelegate?.settingsOpenURLInNewTab(url)
self.dismiss(animated: true)
}

return vc
Expand Down
10 changes: 10 additions & 0 deletions Sources/BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,16 @@ extension Strings {
NSLocalizedString("vpn.settingsManageSubscription", tableName: "BraveShared", bundle: .strings,
value: "Manage Subscription",
comment: "Button to manage your VPN subscription")

public static let settingsLinkReceipt =
NSLocalizedString("vpn.settingsLinkReceipt", tableName: "BraveShared", bundle: .strings,
value: "Link purchase to your Brave account",
comment: "Button to link your VPN receipt to other devices.")

public static let settingsLinkReceiptFooter =
NSLocalizedString("vpn.settingsLinkReceiptFooter", tableName: "BraveShared", bundle: .strings,
value: "Link your App Store purchase to your Brave account to use Brave VPN on other devices.",
comment: "Footer text to link your VPN receipt to other devices.")

public static let settingsServerHost =
NSLocalizedString("vpn.settingsServerHost", tableName: "BraveShared", bundle: .strings,
Expand Down
6 changes: 6 additions & 0 deletions Sources/BraveShared/BraveUX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import UIKit
public struct BraveUX {
public static let braveCommunityURL = URL(string: "https://community.brave.com/")!
public static let braveVPNFaqURL = URL(string: "https://support.brave.com/hc/en-us/articles/360045045952")!
public static let braveVPNLinkReceiptProd =
URL(string: "https://account.brave.com/?intent=connect-receipt&product=vpn")!
public static let braveVPNLinkReceiptStaging =
URL(string: "https://account.bravesoftware.com/?intent=connect-receipt&product=vpn")!
public static let braveVPNLinkReceiptDev =
URL(string: "https://account.brave.software/?intent=connect-receipt&product=vpn")!
public static let bravePrivacyURL = URL(string: "https://brave.com/privacy/")!
public static let braveNewsPrivacyURL = URL(string: "https://brave.com/privacy/#brave-news")!
public static let braveOffersURL = URL(string: "https://offers.brave.com/")!
Expand Down
9 changes: 9 additions & 0 deletions Sources/BraveVPN/BraveVPN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import os.log

/// A static class to handle all things related to the Brave VPN service.
public class BraveVPN {
public static let linkReceiptEnabled = false

private static let housekeepingApi = GRDHousekeepingAPI()
private static let helper = GRDVPNHelper.sharedInstance()
Expand Down Expand Up @@ -84,6 +85,14 @@ public class BraveVPN {
return receipt
}

/// Returns true if the app store receipt is in sandbox mode.
/// This can typically let us know whether a Testflight build is used or not.
/// Keep in mind this function may not work correctly for future iOS builds.
/// Apple prefers to validate the receipt by using a server.
public static var isSandbox: Bool {
Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
}

public static func setCustomVPNCredential(_ credential: String, environment: String) {
GRDSubscriptionManager.setIsPayingUser(true)
populateRegionDataIfNecessary()
Expand Down
32 changes: 29 additions & 3 deletions Sources/BraveVPN/BraveVPNSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import os.log

public class BraveVPNSettingsViewController: TableViewController {

public var faqButtonTapped: (() -> Void)?
public var openURL: ((URL) -> Void)?

public init() {
super.init(style: .grouped)
Expand Down Expand Up @@ -65,6 +65,30 @@ public class BraveVPNSettingsViewController: TableViewController {
overlayView = overlay
}
}

private var linkReceiptRows: [Row] {
var rows = [Row]()

if BraveVPN.linkReceiptEnabled {
rows.append(Row(text: Strings.VPN.settingsLinkReceipt,
selection: { [unowned self] in
openURL?(BraveUX.braveVPNLinkReceiptProd)
}, cellClass: ButtonCell.self))
}

if BraveVPN.isSandbox {
rows += [Row(text: "[Staging] Link Receipt",
selection: { [unowned self] in
openURL?(BraveUX.braveVPNLinkReceiptStaging)
}, cellClass: ButtonCell.self),
Row(text: "[Dev] Link Receipt",
selection: { [unowned self] in
openURL?(BraveUX.braveVPNLinkReceiptDev)
}, cellClass: ButtonCell.self)]
}

return rows
}

public override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -105,7 +129,8 @@ public class BraveVPNSettingsViewController: TableViewController {
// Opens Apple's 'manage subscription' screen.
UIApplication.shared.open(url, options: [:])
}
}, cellClass: ButtonCell.self)])
}, cellClass: ButtonCell.self)] + linkReceiptRows,
footer: .title(Strings.VPN.settingsLinkReceiptFooter))

let location = BraveVPN.serverLocation ?? "-"

Expand Down Expand Up @@ -133,7 +158,8 @@ public class BraveVPNSettingsViewController: TableViewController {

let termsSection = Section(rows:
[Row(text: Strings.VPN.settingsFAQ, selection: { [unowned self] in
self.faqButtonTapped?()
self.openURL?(BraveUX.braveVPNFaqURL)

}, accessory: .disclosureIndicator, cellClass: ButtonCell.self)])

dataSource.sections = [vpnStatusSection,
Expand Down
2 changes: 1 addition & 1 deletion Sources/BraveVPN/InstallVPNView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The Brave Authors. All rights reserved.
// Copyright 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
Expand Down

0 comments on commit e926be2

Please sign in to comment.