Skip to content

Commit

Permalink
Merge branch 'feat/CP-7415' into 'develop'
Browse files Browse the repository at this point in the history
Merge-Request: apple/vpn/protonvpn!1592
Approved-by: Pawel Jurczyk <[email protected]>
Approved-by: John Biggs <[email protected]>
  • Loading branch information
pawel-jurczyk committed Feb 12, 2024
2 parents a2e0a55 + 55002d9 commit 540af5a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "external/protoncore"]
path = external/protoncore
url = ../../shared/protoncore
tag = 19.0.0
tag = 19.0.1
[submodule "tunnelkit"]
path = external/tunnelkit
url = ../tunnelkit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@ extension OnboardingModuleService: OnboardingService {
let countriesCount = self.planService.countriesCount
let allCountriesUpsell: ModalType = .allCountries(numberOfServers: serversCount, numberOfCountries: countriesCount)
return ModalsFactory().modalViewController(modalType: allCountriesUpsell) {
self.userDidRequestPlanPurchase { action in
switch action {
case .planPurchased:
self.onboardingCoordinatorDidFinish()
case .planPurchaseViewControllerReady(let viewController):
self.windowService.present(modal: viewController)
}
self.planService.createPlusPlanUI {
self.onboardingCoordinatorDidFinish()
}
} dismissAction: {
self.onboardingCoordinatorDidFinish()
Expand All @@ -87,24 +82,8 @@ extension OnboardingModuleService: OnboardingService {
}

extension OnboardingModuleService {
func userDidRequestPlanPurchase(completion: @escaping (PlanPurchaseAction) -> Void) {
planService.createPlusPlanUI { result in
switch result {
case let .planPurchaseViewControllerCreated(viewController):
completion(.planPurchaseViewControllerReady(viewController))
case .planPurchased:
completion(.planPurchased)
}
}
}

func onboardingCoordinatorDidFinish() {
private func onboardingCoordinatorDidFinish() {
log.debug("Onboarding finished", category: .app)
delegate?.onboardingServiceDidFinish()
}
}

enum PlanPurchaseAction {
case planPurchaseViewControllerReady(UIViewController)
case planPurchased
}
27 changes: 10 additions & 17 deletions apps/ios/ProtonVPN/Scenes/Payments/PlanService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ protocol PlanServiceDelegate: AnyObject {
func paymentTransactionDidFinish(modalSource: UpsellEvent.ModalSource?, newPlanName: String?) async
}

enum PlusPlanUIResult {
case planPurchaseViewControllerCreated(UIViewController)
case planPurchased
}

protocol PlanService {
var allowUpgrade: Bool { get }
var countriesCount: Int { get }
Expand All @@ -50,7 +45,7 @@ protocol PlanService {
func presentPlanSelection(modalSource: UpsellEvent.ModalSource?)
func presentSubscriptionManagement()
func updateServicePlans() async throws
func createPlusPlanUI(completion: @escaping (PlusPlanUIResult) -> Void)
func createPlusPlanUI(completion: @escaping () -> Void)

func clear()
}
Expand Down Expand Up @@ -160,30 +155,28 @@ final class CorePlanService: PlanService {
}
}

func createPlusPlanUI(completion: @escaping (PlusPlanUIResult) -> Void) {
func createPlusPlanUI(completion: @escaping () -> Void) {
paymentsUI = createPaymentsUI(onlyPlusPlan: true)
paymentsUI?.showUpgradePlan(presentationType: PaymentsUIPresentationType.none, backendFetch: true) { [weak self] response in
paymentsUI?.showUpgradePlan(presentationType: PaymentsUIPresentationType.modal, backendFetch: true) { [weak self] response in
switch response {
case let .open(vc: viewController, opened: false):
completion(.planPurchaseViewControllerCreated(viewController))
case .open(vc: _, opened: true):
assertionFailure("Invalid usage")
case let .purchaseError(error: error):
log.error("Purchase failed", category: .iap, metadata: ["error": "\(error)"])
case .close:
log.debug("Payments closed", category: .iap)
case let .purchasedPlan(accountPlan: plan):
log.debug("Purchased plan: \(plan.protonName)", category: .iap)
completion(.planPurchased)
completion()
Task { [weak self] in
await self?.delegate?.paymentTransactionDidFinish(modalSource: nil, newPlanName: plan.protonName)
}
case let .purchaseError(error: error):
log.error("Purchase failed", category: .iap, metadata: ["error": "\(error)"])
case .close:
log.debug("Payments closed", category: .iap)
case let .planPurchaseProcessingInProgress(accountPlan: plan):
log.debug("Purchasing \(plan.protonName)", category: .iap)
case .toppedUpCredits:
log.debug("Credits topped up", category: .iap)
case let .apiMightBeBlocked(message, error):
log.error("\(message)", category: .connection, metadata: ["error": "\(error)"])
case .open:
log.debug("Purchase screen opened", category: .iap)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/ios/ProtonVPNTests/Mocks/PlanServiceMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PlanServiceMock: PlanService {

}

func createPlusPlanUI(completion: @escaping (PlusPlanUIResult) -> Void) {
func createPlusPlanUI(completion: @escaping () -> Void) {

}
}
2 changes: 1 addition & 1 deletion external/protoncore

0 comments on commit 540af5a

Please sign in to comment.