Skip to content

Commit 64979b3

Browse files
authored
Merge pull request #8111 from woocommerce/issue/8110-site-id-xcode-env-variable-iap
[In-app Purchases]Use environment variable to get test site id for IAP
2 parents c79669d + 352a970 commit 64979b3

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> = []
@@ -31,7 +30,8 @@ struct InAppPurchasesDebugView: View {
3130
Text("No products")
3231
} else if isPurchasing {
3332
ActivityIndicator(isAnimating: .constant(true), style: .medium)
34-
} else {
33+
} else if let stringSiteID = ProcessInfo.processInfo.environment[Constants.siteIdEnvironmentVariableName],
34+
let siteID = Int64(stringSiteID) {
3535
ForEach(products, id: \.id) { product in
3636
Button(entitledProductIDs.contains(product.id) ? "Entitled: \(product.description)" : product.description) {
3737
Task {
@@ -47,6 +47,10 @@ struct InAppPurchasesDebugView: View {
4747
}
4848
.alert(isPresented: $presentAlert, error: purchaseError, actions: {})
4949
}
50+
} else {
51+
Text("No valid site id could be retrieved to purchase product. " +
52+
"Please set your Int64 test site id to the Xcode environment variable with name \(Constants.siteIdEnvironmentVariableName).")
53+
.foregroundColor(.red)
5054
}
5155
}
5256

@@ -129,6 +133,10 @@ private struct PurchaseError: LocalizedError {
129133

130134
struct InAppPurchasesDebugView_Previews: PreviewProvider {
131135
static var previews: some View {
132-
InAppPurchasesDebugView(siteID: 0)
136+
InAppPurchasesDebugView()
133137
}
134138
}
139+
140+
private enum Constants {
141+
static let siteIdEnvironmentVariableName = "iap-debug-site-id"
142+
}

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"
147+
value = ""
148+
isEnabled = "NO">
149+
</EnvironmentVariable>
145150
</EnvironmentVariables>
146151
</LaunchAction>
147152
<ProfileAction

0 commit comments

Comments
 (0)