Skip to content

Commit 1e83da4

Browse files
committed
Correctly handle initial post-subscription behavior
1 parent 32e2ceb commit 1e83da4

8 files changed

+99
-6
lines changed

Client.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ let kApiCodeEmailAlreadyUsed = 40
2222
let kApiCodeReceiptAlreadyUsed = 48
2323
let kApiCodeInvalidAuth = 401
2424
let kApiCodeTooManyRequests = 999
25+
let kApiCodeSandboxReceiptNotAllowed = 9925
2526
let kApiCodeUnknownError = 99999
2627
let kApiCodeNegativeError = -1
2728

@@ -99,9 +100,9 @@ class Client {
99100
}
100101
}
101102

102-
static func subscriptionEvent() throws -> Promise<SubscriptionEvent> {
103+
static func subscriptionEvent(forceRefresh: Bool = false) throws -> Promise<SubscriptionEvent> {
103104
DDLogInfo("API CALL: subscription-event")
104-
return getReceipt(forceRefresh: false)
105+
return getReceipt(forceRefresh: forceRefresh)
105106
.then { receipt -> Promise<(data: Data, response: URLResponse)> in
106107
let parameters:[String : Any] = [
107108
"authtype": "ios",

Lockdown Tunnel/PacketTunnelProvider.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LDObserverFactory: ObserverFactory {
3030
for whitelistedDomain in whitelistedDomains {
3131
if (session.host.hasSuffix("." + whitelistedDomain) || session.host == whitelistedDomain) {
3232
#if DEBUG
33-
PacketTunnelProviderLogs.log("whitelisted \(session.host), not blocking")
33+
//PacketTunnelProviderLogs.log("whitelisted \(session.host), not blocking")
3434
#endif
3535
return
3636
}
@@ -39,7 +39,7 @@ class LDObserverFactory: ObserverFactory {
3939
if (getUserWantsFirewallEnabled()) {
4040
updateMetrics(.incrementAndLog(host: session.host), rescheduleNotifications: .withEnergySaving)
4141
#if DEBUG
42-
PacketTunnelProviderLogs.log("session host: \(session.host)")
42+
//PacketTunnelProviderLogs.log("session host: \(session.host)")
4343
#endif
4444
socket.forceDisconnect()
4545
return

LockdowniOS/AccountVC.swift

+12
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ final class AccountViewController: BaseViewController, Loadable {
252252
upgradeButton.backgroundView?.backgroundColor = UIColor.tunnelsDarkBlue
253253
upgradeButton.button.setTitleColor(UIColor.white, for: UIControl.State())
254254
upgradeButton.button.setTitle(NSLocalizedString("View Upgrade Options", comment:""), for: UIControl.State())
255+
case kApiCodeSandboxReceiptNotAllowed:
256+
upgradeButton.button.isEnabled = true
257+
upgradeButton.selectionStyle = .default
258+
upgradeButton.backgroundView?.backgroundColor = UIColor.tunnelsDarkBlue
259+
upgradeButton.button.setTitleColor(UIColor.white, for: UIControl.State())
260+
upgradeButton.button.setTitle(NSLocalizedString("View Upgrade Options", comment:""), for: UIControl.State())
255261
default:
256262
DDLogError("Error loading plan: API error code - \(apiError.code)")
257263
upgradeButton.button.isEnabled = true
@@ -313,6 +319,12 @@ final class AccountViewController: BaseViewController, Loadable {
313319
upgradeButton.backgroundView?.backgroundColor = UIColor.tunnelsDarkBlue
314320
upgradeButton.button.setTitleColor(UIColor.white, for: UIControl.State())
315321
upgradeButton.button.setTitle(NSLocalizedString("View Upgrade Options", comment:""), for: UIControl.State())
322+
case kApiCodeSandboxReceiptNotAllowed:
323+
upgradeButton.button.isEnabled = true
324+
upgradeButton.selectionStyle = .default
325+
upgradeButton.backgroundView?.backgroundColor = UIColor.tunnelsDarkBlue
326+
upgradeButton.button.setTitleColor(UIColor.white, for: UIControl.State())
327+
upgradeButton.button.setTitle(NSLocalizedString("View Upgrade Options", comment:""), for: UIControl.State())
316328
default:
317329
DDLogError("Error loading plan: API error code - \(apiError.code)")
318330
upgradeButton.button.isEnabled = true

LockdowniOS/SignupViewController.swift

+58-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,63 @@ class SignupViewController: BaseViewController {
176176
presentingViewController.reloadTable()
177177
}
178178
if self.enableVPNAfterSubscribe {
179-
VPNController.shared.setEnabled(true)
179+
// force refresh receipt, and sync with email if it exists, activate VPNte
180+
if let apiCredentials = getAPICredentials(), getAPICredentialsConfirmed() == true {
181+
DDLogInfo("purchase complete: syncing with confirmed email")
182+
firstly {
183+
try Client.signInWithEmail(email: apiCredentials.email, password: apiCredentials.password)
184+
}
185+
.then { (signin: SignIn) -> Promise<SubscriptionEvent> in
186+
DDLogInfo("purchase complete: signin result: \(signin)")
187+
return try Client.subscriptionEvent(forceRefresh: true)
188+
}
189+
.then { (result: SubscriptionEvent) -> Promise<GetKey> in
190+
DDLogInfo("purchase complete: subscriptionevent result: \(result)")
191+
return try Client.getKey()
192+
}
193+
.done { (getKey: GetKey) in
194+
try setVPNCredentials(id: getKey.id, keyBase64: getKey.b64)
195+
DDLogInfo("purchase complete: setting VPN creds with ID: \(getKey.id)")
196+
VPNController.shared.setEnabled(true)
197+
}
198+
.catch { error in
199+
DDLogError("purchase complete: Error: \(error)")
200+
if (self.popupErrorAsNSURLError("Error activating Secure Tunnel: \(error)")) {
201+
return
202+
}
203+
else if let apiError = error as? ApiError {
204+
switch apiError.code {
205+
default:
206+
_ = self.popupErrorAsApiError("API Error activating Secure Tunnel: \(error)")
207+
}
208+
}
209+
}
210+
}
211+
else {
212+
firstly {
213+
try Client.signIn(forceRefresh: true) // this will fetch and set latest receipt, then submit to API to get cookie
214+
}
215+
.then { (signin: SignIn) -> Promise<GetKey> in
216+
// TODO: don't always do this -- if we already have a key, then only do it once per day max
217+
try Client.getKey()
218+
}
219+
.done { (getKey: GetKey) in
220+
try setVPNCredentials(id: getKey.id, keyBase64: getKey.b64)
221+
VPNController.shared.setEnabled(true)
222+
}
223+
.catch { error in
224+
DDLogError("purchase complete - no email: Error: \(error)")
225+
if (self.popupErrorAsNSURLError("Error activating Secure Tunnel: \(error)")) {
226+
return
227+
}
228+
else if let apiError = error as? ApiError {
229+
switch apiError.code {
230+
default:
231+
_ = self.popupErrorAsApiError("API Error activating Secure Tunnel: \(error)")
232+
}
233+
}
234+
}
235+
}
180236
}
181237
})
182238
},
@@ -191,7 +247,7 @@ class SignupViewController: BaseViewController {
191247
case .clientInvalid: errorText = NSLocalizedString("Not allowed to make the payment", comment: "")
192248
case .paymentCancelled: errorText = NSLocalizedString("Payment was cancelled", comment: "")
193249
case .paymentInvalid: errorText = NSLocalizedString("The purchase identifier was invalid", comment: "")
194-
case .paymentNotAllowed: errorText = NSLocalizedString("The device is not allowed to make the payment", comment: "")
250+
case .paymentNotAllowed: errorText = NSLocalizedString("Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.", comment: "")
195251
case .storeProductNotAvailable: errorText = NSLocalizedString("The product is not available in the current storefront", comment: "")
196252
case .cloudServicePermissionDenied: errorText = NSLocalizedString("Access to cloud service information is not allowed", comment: "")
197253
case .cloudServiceNetworkConnectionFailed: errorText = NSLocalizedString("Could not connect to the network", comment: "")

en.lproj/Localizable.strings

+6
Original file line numberDiff line numberDiff line change
@@ -682,3 +682,9 @@
682682

683683
/* No comment provided by engineer. */
684684
"Please that you have an active subscription. If you're attempting to share a subscription from the same account, you'll need to sign in with the same email address. Otherwise, please start your free trial or e-mail team@lockdownprivacy.com" = "Please that you have an active subscription. If you're attempting to share a subscription from the same account, you'll need to sign in with the same email address. Otherwise, please start your free trial or e-mail team@lockdownprivacy.com";
685+
686+
/* No comment provided by engineer. */
687+
"In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again." = "In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.";
688+
689+
/* No comment provided by engineer. */
690+
"Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again." = "Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.";

es.lproj/Localizable.strings

+6
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,9 @@
688688

689689
/* No comment provided by engineer. */
690690
"Please that you have an active subscription. If you're attempting to share a subscription from the same account, you'll need to sign in with the same email address. Otherwise, please start your free trial or e-mail team@lockdownprivacy.com" = "Please that you have an active subscription. If you're attempting to share a subscription from the same account, you'll need to sign in with the same email address. Otherwise, please start your free trial or e-mail team@lockdownprivacy.com";
691+
692+
/* No comment provided by engineer. */
693+
"In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again." = "In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.";
694+
695+
/* No comment provided by engineer. */
696+
"Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again." = "Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.";

fr.lproj/Localizable.strings

+6
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,9 @@
688688

689689
/* No comment provided by engineer. */
690690
"Please that you have an active subscription. If you're attempting to share a subscription from the same account, you'll need to sign in with the same email address. Otherwise, please start your free trial or e-mail team@lockdownprivacy.com" = "Please that you have an active subscription. If you're attempting to share a subscription from the same account, you'll need to sign in with the same email address. Otherwise, please start your free trial or e-mail team@lockdownprivacy.com";
691+
692+
/* No comment provided by engineer. */
693+
"In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again." = "In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.";
694+
695+
/* No comment provided by engineer. */
696+
"Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again." = "Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.";

ja.lproj/Localizable.strings

+6
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,9 @@
688688

689689
/* No comment provided by engineer. */
690690
"Please that you have an active subscription. If you're attempting to share a subscription from the same account, you'll need to sign in with the same email address. Otherwise, please start your free trial or e-mail team@lockdownprivacy.com" = "Please that you have an active subscription. If you're attempting to share a subscription from the same account, you'll need to sign in with the same email address. Otherwise, please start your free trial or e-mail team@lockdownprivacy.com";
691+
692+
/* No comment provided by engineer. */
693+
"In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again." = "In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.";
694+
695+
/* No comment provided by engineer. */
696+
"Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again." = "Payment not allowed.\nEither this device is not allowed to make purchases, or In-App Purchases have been disabled. Please allow them in Settings App -> Screen Time -> Restrictions -> App Store -> In-app Purchases. Then try again.";

0 commit comments

Comments
 (0)