@@ -11,34 +11,36 @@ struct InAppPurchasesDebugView: View {
1111 @State var isPurchasing = false
1212 @State private var purchaseError : PurchaseError ? {
1313 didSet {
14- presentErrorAlert = purchaseError != nil
14+ presentAlert = purchaseError != nil
1515 }
1616 }
17- @State var presentErrorAlert = false
18- @State var presentPurchaseProductAlert = false
17+ @State var presentAlert = false
1918
2019 var body : some View {
21- List {
22- Section {
23- Button ( " Reload products " ) {
24- Task {
25- await loadProducts ( )
20+ if ProcessInfo . processInfo. environment [ " wpcom-api-base-url " ] == nil {
21+ Text ( " ⚠️ Your WPCOM Sandbox URL is not setup " )
22+ . headlineStyle ( )
23+ Text ( " To test In-App Purchases please make sure that the WPCOM requests are pointing " +
24+ " to your sandbox environment and you have the billing system sandbox-mode enabled there. " )
25+ . padding ( )
26+ } else {
27+ List {
28+ Section {
29+ Button ( " Reload products " ) {
30+ Task {
31+ await loadProducts ( )
32+ }
2633 }
2734 }
28- }
29- Section ( " Products " ) {
30- if products. isEmpty {
31- Text ( " No products " )
32- } else if isPurchasing {
33- ActivityIndicator ( isAnimating: . constant( true ) , style: . medium)
34- } else if let stringSiteID = ProcessInfo . processInfo. environment [ Constants . siteIdEnvironmentVariableName] ,
35- let siteID = Int64 ( stringSiteID) {
36- ForEach ( products, id: \. id) { product in
37- Button ( entitledProductIDs. contains ( product. id) ? " Entitled: \( product. description) " : product. description) {
38- presentPurchaseProductAlert = true
39- }
40- . alert ( " Did you setup your sandbox environment? " , isPresented: $presentPurchaseProductAlert) {
41- Button ( " Yes " ) {
35+ Section ( " Products " ) {
36+ if products. isEmpty {
37+ Text ( " No products " )
38+ } else if isPurchasing {
39+ ActivityIndicator ( isAnimating: . constant( true ) , style: . medium)
40+ } else if let stringSiteID = ProcessInfo . processInfo. environment [ Constants . siteIdEnvironmentVariableName] ,
41+ let siteID = Int64 ( stringSiteID) {
42+ ForEach ( products, id: \. id) { product in
43+ Button ( entitledProductIDs. contains ( product. id) ? " Entitled: \( product. description) " : product. description) {
4244 Task {
4345 isPurchasing = true
4446 do {
@@ -50,43 +52,36 @@ struct InAppPurchasesDebugView: View {
5052 isPurchasing = false
5153 }
5254 }
53- Button ( " No " ) { }
55+ . alert ( isPresented : $presentAlert , error : purchaseError , actions : { } )
5456 }
55- . alert ( isPresented: $presentErrorAlert, error: purchaseError, actions: { } )
57+ } else {
58+ Text ( " No valid site id could be retrieved to purchase product. " +
59+ " Please set your Int64 test site id to the Xcode environment variable with name \( Constants . siteIdEnvironmentVariableName) . " )
60+ . foregroundColor ( . red)
5661 }
57- } else {
58- Text ( " No valid site id could be retrieved to purchase product. " +
59- " Please set your Int64 test site id to the Xcode environment variable with name \( Constants . siteIdEnvironmentVariableName) . " )
60- . foregroundColor ( . red)
6162 }
62- }
63-
64- Section {
65- Button ( " Retry WPCom Synchronization for entitled products " ) {
66- retryWPComSynchronizationForPurchasedProducts ( )
67- } . disabled ( !inAppPurchasesAreSupported || entitledProductIDs. isEmpty)
68- }
6963
70- if !inAppPurchasesAreSupported {
7164 Section {
72- Text ( " In-App Purchases are not supported for this user " )
73- . foregroundColor ( . red)
65+ Button ( " Retry WPCom Synchronization for entitled products " ) {
66+ retryWPComSynchronizationForPurchasedProducts ( )
67+ } . disabled ( !inAppPurchasesAreSupported || entitledProductIDs. isEmpty)
7468 }
75- }
7669
77- Section ( " Warning " ) {
78- Text ( " ⚠️ Please make sure before testing a purchase that the IAP requests are pointing " +
79- " to your WPCOM sandbox environment and you have the billing system sandbox-mode enabled. " )
80- . foregroundColor ( Color ( . accent) )
70+ if !inAppPurchasesAreSupported {
71+ Section {
72+ Text ( " In-App Purchases are not supported for this user " )
73+ . foregroundColor ( . red)
74+ }
75+ }
8176 }
82- }
83- . navigationTitle ( " IAP Debug " )
84- . task {
85- await loadProducts ( )
86- }
87- . onReceive ( NotificationCenter . default . publisher ( for : UIApplication . willEnterForegroundNotification ) ) { _ in
88- Task {
89- await loadUserEntitlements ( )
77+ . navigationTitle ( " IAP Debug " )
78+ . task {
79+ await loadProducts ( )
80+ }
81+ . onReceive ( NotificationCenter . default . publisher ( for : UIApplication . willEnterForegroundNotification ) ) { _ in
82+ Task {
83+ await loadUserEntitlements ( )
84+ }
9085 }
9186 }
9287 }
0 commit comments