@@ -78,7 +78,7 @@ final class StoreCreationCoordinator: Coordinator {
7878 do {
7979 let inProgressView = createIAPEligibilityInProgressView ( )
8080 let storeCreationNavigationController = WooNavigationController ( rootViewController: inProgressView)
81- presentStoreCreation ( viewController: storeCreationNavigationController)
81+ await presentStoreCreation ( viewController: storeCreationNavigationController)
8282
8383 guard await purchasesManager. inAppPurchasesAreSupported ( ) else {
8484 throw PlanPurchaseError . iapNotSupported
@@ -96,8 +96,14 @@ final class StoreCreationCoordinator: Coordinator {
9696
9797 startStoreCreationM2 ( from: storeCreationNavigationController, planToPurchase: product)
9898 } catch {
99+ let isWebviewFallbackAllowed = featureFlagService. isFeatureFlagEnabled ( . storeCreationM2WithInAppPurchasesEnabled) == false
99100 navigationController. dismiss ( animated: true ) { [ weak self] in
100- self ? . startStoreCreationM1 ( )
101+ guard let self else { return }
102+ if isWebviewFallbackAllowed {
103+ self . startStoreCreationM1 ( )
104+ } else {
105+ self . showIneligibleUI ( from: self . navigationController, error: error)
106+ }
101107 }
102108 }
103109 }
@@ -118,7 +124,9 @@ private extension StoreCreationCoordinator {
118124 // Disables interactive dismissal of the store creation modal.
119125 webNavigationController. isModalInPresentation = true
120126
121- presentStoreCreation ( viewController: webNavigationController)
127+ Task { @MainActor in
128+ await presentStoreCreation ( viewController: webNavigationController)
129+ }
122130 }
123131
124132 func startStoreCreationM2( from navigationController: UINavigationController , planToPurchase: WPComPlanProduct ) {
@@ -135,15 +143,25 @@ private extension StoreCreationCoordinator {
135143 analytics. track ( event: . StoreCreation. siteCreationStep ( step: . storeName) )
136144 }
137145
138- func presentStoreCreation( viewController: UIViewController ) {
139- // If the navigation controller is already presenting another view, the view needs to be dismissed before store
140- // creation view can be presented.
141- if navigationController. presentedViewController != nil {
142- navigationController. dismiss ( animated: true ) { [ weak self] in
143- self ? . navigationController. present ( viewController, animated: true )
146+ @MainActor
147+ func presentStoreCreation( viewController: UIViewController ) async {
148+ await withCheckedContinuation { continuation in
149+ // If the navigation controller is already presenting another view, the view needs to be dismissed before store
150+ // creation view can be presented.
151+ if navigationController. presentedViewController != nil {
152+ navigationController. dismiss ( animated: true ) { [ weak self] in
153+ guard let self else {
154+ return continuation. resume ( )
155+ }
156+ self . navigationController. present ( viewController, animated: true ) {
157+ continuation. resume ( )
158+ }
159+ }
160+ } else {
161+ navigationController. present ( viewController, animated: true ) {
162+ continuation. resume ( )
163+ }
144164 }
145- } else {
146- navigationController. present ( viewController, animated: true )
147165 }
148166 }
149167
@@ -154,6 +172,28 @@ private extension StoreCreationCoordinator {
154172 message: Localization . WaitingForIAPEligibility. message) ,
155173 hidesNavigationBar: true )
156174 }
175+
176+ /// Shows UI when the user is not eligible for store creation.
177+ func showIneligibleUI( from navigationController: UINavigationController , error: Error ) {
178+ let message : String
179+ switch error {
180+ case PlanPurchaseError . iapNotSupported:
181+ message = Localization . IAPIneligibleAlert. notSupportedMessage
182+ case PlanPurchaseError . productNotEligible:
183+ message = Localization . IAPIneligibleAlert. productNotEligibleMessage
184+ default :
185+ message = Localization . IAPIneligibleAlert. defaultMessage
186+ }
187+
188+ let alert = UIAlertController ( title: nil ,
189+ message: message,
190+ preferredStyle: . alert)
191+ alert. view. tintColor = . text
192+
193+ alert. addCancelActionWithTitle ( Localization . IAPIneligibleAlert. dismissActionTitle) { _ in }
194+
195+ navigationController. present ( alert, animated: true )
196+ }
157197}
158198
159199// MARK: - Store creation M1
@@ -486,6 +526,23 @@ private extension StoreCreationCoordinator {
486526 )
487527 }
488528
529+ enum IAPIneligibleAlert {
530+ static let notSupportedMessage = NSLocalizedString (
531+ " We're sorry, but store creation is not currently available in your country in the app. " ,
532+ comment: " Message of the alert when the user cannot create a store because their App Store country is not supported. "
533+ )
534+ static let productNotEligibleMessage = NSLocalizedString (
535+ " Sorry, but you can only create one store. Your account is already associated with an active store. " ,
536+ comment: " Message of the alert when the user cannot create a store because they already created one before. "
537+ )
538+ static let defaultMessage = NSLocalizedString (
539+ " We're sorry, but store creation is not currently available in the app. " ,
540+ comment: " Message of the alert when the user cannot create a store for some reason. "
541+ )
542+ static let dismissActionTitle = NSLocalizedString ( " OK " ,
543+ comment: " Button title to cancel the alert when the user cannot create a store. " )
544+ }
545+
489546 enum DiscardChangesAlert {
490547 static let title = NSLocalizedString ( " Do you want to leave? " ,
491548 comment: " Title of the alert when the user dismisses the store creation flow. " )
0 commit comments