Skip to content

Commit 1979d79

Browse files
committed
Use environment variable to get test site id for IAP
1 parent d3a39df commit 1979d79

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct HubMenu: View {
113113
NavigationLink(destination: CouponListView(siteID: viewModel.siteID), isActive: $showingCoupons) {
114114
EmptyView()
115115
}.hidden()
116-
NavigationLink(destination: InAppPurchasesDebugView(siteID: viewModel.siteID), isActive: $showingIAPDebug) {
116+
NavigationLink(destination: InAppPurchasesDebugView(), isActive: $showingIAPDebug) {
117117
EmptyView()
118118
}.hidden()
119119
LazyNavigationLink(destination: viewModel.getReviewDetailDestination(), isActive: $viewModel.showingReviewDetail) {

WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesDebugView.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Yosemite
44

55
@MainActor
66
struct InAppPurchasesDebugView: View {
7-
let siteID: Int64
87
private let inAppPurchasesForWPComPlansManager = InAppPurchasesForWPComPlansManager()
98
@State var products: [WPComPlanProduct] = []
109
@State var entitledProductIDs: Set<String> = []
@@ -25,7 +24,8 @@ struct InAppPurchasesDebugView: View {
2524
Text("No products")
2625
} else if isPurchasing {
2726
ActivityIndicator(isAnimating: .constant(true), style: .medium)
28-
} else {
27+
} else if let stringSiteID = ProcessInfo.processInfo.environment[Constants.siteIdEnvironmentVariableName],
28+
let siteID = Int64(stringSiteID) {
2929
ForEach(products, id: \.id) { product in
3030
Button(entitledProductIDs.contains(product.id) ? "Entitled: \(product.description)" : product.description) {
3131
Task {
@@ -36,6 +36,10 @@ struct InAppPurchasesDebugView: View {
3636
}
3737
}
3838
}
39+
} else {
40+
Text("Couldn't retrieve site id to purchase product. " +
41+
"Please set your Int64 test site id to the Xcode environment variable with name \(Constants.siteIdEnvironmentVariableName).")
42+
.foregroundColor(.red)
3943
}
4044
}
4145

@@ -104,6 +108,10 @@ struct InAppPurchasesDebugView: View {
104108

105109
struct InAppPurchasesDebugView_Previews: PreviewProvider {
106110
static var previews: some View {
107-
InAppPurchasesDebugView(siteID: 0)
111+
InAppPurchasesDebugView()
108112
}
109113
}
114+
115+
private enum Constants {
116+
static let siteIdEnvironmentVariableName = "iap-debug-site-id-purchase-param"
117+
}

WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerce.xcscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
value = ""
143143
isEnabled = "NO">
144144
</EnvironmentVariable>
145+
<EnvironmentVariable
146+
key = "iap-debug-site-id-purchase-param"
147+
value = ""
148+
isEnabled = "NO">
149+
</EnvironmentVariable>
145150
</EnvironmentVariables>
146151
</LaunchAction>
147152
<ProfileAction

0 commit comments

Comments
 (0)