Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ struct InAppPurchasesDebugView: View {
@State var isPurchasing = false
@State private var purchaseError: PurchaseError? {
didSet {
presentAlert = purchaseError != nil
presentErrorAlert = purchaseError != nil
}
}
@State var presentAlert = false
@State var presentErrorAlert = false
@State var presentPurchaseProductAlert = false

var body: some View {
List {
Expand All @@ -34,18 +35,24 @@ struct InAppPurchasesDebugView: View {
let siteID = Int64(stringSiteID) {
ForEach(products, id: \.id) { product in
Button(entitledProductIDs.contains(product.id) ? "Entitled: \(product.description)" : product.description) {
Task {
isPurchasing = true
do {
try await inAppPurchasesForWPComPlansManager.purchaseProduct(with: product.id, for: siteID)
} catch {
purchaseError = PurchaseError(error: error)
presentPurchaseProductAlert = true
}
.alert("Did you setup your sandbox environment?", isPresented: $presentPurchaseProductAlert) {
Button("Yes") {
Task {
isPurchasing = true
do {
try await inAppPurchasesForWPComPlansManager.purchaseProduct(with: product.id, for: siteID)
} catch {
purchaseError = PurchaseError(error: error)
}
await loadUserEntitlements()
isPurchasing = false
}
await loadUserEntitlements()
isPurchasing = false
}
Button("No") {}
}
.alert(isPresented: $presentAlert, error: purchaseError, actions: {})
.alert(isPresented: $presentErrorAlert, error: purchaseError, actions: {})
}
} else {
Text("No valid site id could be retrieved to purchase product. " +
Expand All @@ -66,6 +73,12 @@ struct InAppPurchasesDebugView: View {
.foregroundColor(.red)
}
}

Section ("Warning") {
Text("⚠️ Please make sure before testing a purchase that the IAP requests are pointing " +
"to your WPCOM sandbox environment and you have the billing system sandbox-mode enabled.")
.foregroundColor(Color(.accent))
}
}
.navigationTitle("IAP Debug")
.task {
Expand Down