Commit 156ea852 authored by Jose Blaya's avatar Jose Blaya
Browse files

Refactor purchase flow

parent ac6c8546
......@@ -31,3 +31,8 @@
"unreachable.title" = "Whoops!";
"unreachable.message" = "No internet connection found. Please confirm that you have an internet connection and hit retry below.\n\nYou can come back to the app later to finish the process.";
"unreachable.submit" = "TRY AGAIN";
"purchase.uncredited.alert.message" = "You have uncredited transactions. Do you want to recover your account details?";
"purchase.uncredited.alert.button.cancel" = "Cancel";
"purchase.uncredited.alert.button.recover" = "Recover account";
......@@ -20,5 +20,8 @@ public extension Notification.Name {
/// Reload the tiles.
public static let PIATilesDidChange = Notification.Name("PIATilesDidChange")
/// Present Recover Signup page
public static let PIARecoverAccount = Notification.Name("PIARecoverAccount")
}
......@@ -46,6 +46,20 @@ internal enum L10n {
internal static let message = L10n.tr("Signup", "in_progress.redeem.message")
}
}
internal enum Purchase {
internal enum Uncredited {
internal enum Alert {
/// You have uncredited transactions. Do you want to recover your account details?
internal static let message = L10n.tr("Signup", "purchase.uncredited.alert.message")
internal enum Button {
/// Cancel
internal static let cancel = L10n.tr("Signup", "purchase.uncredited.alert.button.cancel")
/// Recover account
internal static let recover = L10n.tr("Signup", "purchase.uncredited.alert.button.recover")
}
}
}
}
internal enum Success {
/// Thank you for signing up with us. We have sent your account username and password at your email address at %@
internal static func messageFormat(_ p1: String) -> String {
......
......@@ -128,6 +128,21 @@ public class ConfirmVPNPlanViewController: AutolayoutViewController, BrandableNa
private func startPurchaseProcessWithEmail(_ email: String,
andPlan plan: PurchasePlan) {
guard !Client.store.hasUncreditedTransactions else {
let alert = Macros.alert(
nil,
L10n.Signup.Purchase.Uncredited.Alert.message
)
alert.addCancelAction(L10n.Signup.Purchase.Uncredited.Alert.Button.cancel)
alert.addActionWithTitle(L10n.Signup.Purchase.Uncredited.Alert.Button.recover) {
self.navigationController?.popToRootViewController(animated: true)
Macros.postNotification(.PIARecoverAccount)
}
present(alert, animated: true, completion: nil)
return
}
//textEmail.text = email
log.debug("Will purchase plan: \(plan.product)")
......
......@@ -36,6 +36,9 @@ public class GetStartedViewController: AutolayoutViewController, ConfigurationAc
labelVersion.text = Macros.localizedVersionFullString()
view.backgroundColor = UIColor.piaGrey1
let nc = NotificationCenter.default
nc.addObserver(self, selector: #selector(recoverAccount), name: .PIARecoverAccount, object: nil)
self.styleButtons()
super.viewDidLoad()
......@@ -132,4 +135,9 @@ public class GetStartedViewController: AutolayoutViewController, ConfigurationAc
Theme.current.applyButtonLabelStyle(couldNotGetPlanButton)
}
// MARK: Notification event
@objc private func recoverAccount() {
self.performSegue(withIdentifier: StoryboardSegue.Welcome.restorePurchaseSegue.rawValue,
sender: nil)
}
}
......@@ -90,6 +90,7 @@ class PurchaseViewController: AutolayoutViewController, WelcomeChild {
if let vc = segue.destination as? ConfirmVPNPlanViewController,
let selectedIndex = selectedPlanIndex {
vc.preset = preset
vc.completionDelegate = completionDelegate
vc.populateViewWith(plans: allPlans,
andSelectedPlanIndex: selectedIndex)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment