diff --git a/WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift b/WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift index 947bf635881..e958ac7a121 100644 --- a/WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift +++ b/WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift @@ -113,7 +113,7 @@ struct HubMenu: View { NavigationLink(destination: CouponListView(siteID: viewModel.siteID), isActive: $showingCoupons) { EmptyView() }.hidden() - NavigationLink(destination: InAppPurchasesDebugView(siteID: viewModel.siteID), isActive: $showingIAPDebug) { + NavigationLink(destination: InAppPurchasesDebugView(), isActive: $showingIAPDebug) { EmptyView() }.hidden() LazyNavigationLink(destination: viewModel.getReviewDetailDestination(), isActive: $viewModel.showingReviewDetail) { diff --git a/WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesDebugView.swift b/WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesDebugView.swift index ce9e20f0cb7..1d7218fb809 100644 --- a/WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesDebugView.swift +++ b/WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesDebugView.swift @@ -4,7 +4,6 @@ import Yosemite @MainActor struct InAppPurchasesDebugView: View { - let siteID: Int64 private let inAppPurchasesForWPComPlansManager = InAppPurchasesForWPComPlansManager() @State var products: [WPComPlanProduct] = [] @State var entitledProductIDs: Set = [] @@ -25,7 +24,8 @@ struct InAppPurchasesDebugView: View { Text("No products") } else if isPurchasing { ActivityIndicator(isAnimating: .constant(true), style: .medium) - } else { + } else if let stringSiteID = ProcessInfo.processInfo.environment[Constants.siteIdEnvironmentVariableName], + let siteID = Int64(stringSiteID) { ForEach(products, id: \.id) { product in Button(entitledProductIDs.contains(product.id) ? "Entitled: \(product.description)" : product.description) { Task { @@ -36,6 +36,10 @@ struct InAppPurchasesDebugView: View { } } } + } else { + Text("No valid site id could be retrieved to purchase product. " + + "Please set your Int64 test site id to the Xcode environment variable with name \(Constants.siteIdEnvironmentVariableName).") + .foregroundColor(.red) } } @@ -104,6 +108,10 @@ struct InAppPurchasesDebugView: View { struct InAppPurchasesDebugView_Previews: PreviewProvider { static var previews: some View { - InAppPurchasesDebugView(siteID: 0) + InAppPurchasesDebugView() } } + +private enum Constants { + static let siteIdEnvironmentVariableName = "iap-debug-site-id" +} diff --git a/WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerce.xcscheme b/WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerce.xcscheme index 093f5c0cae4..f2bc9d4e286 100644 --- a/WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerce.xcscheme +++ b/WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerce.xcscheme @@ -142,6 +142,11 @@ value = "" isEnabled = "NO"> + +