@@ -16,64 +16,72 @@ struct InAppPurchasesDebugView: View {
1616 @State var presentAlert = false
1717
1818 var body : some View {
19- List {
20- Section {
21- Button ( " Reload products " ) {
22- Task {
23- await loadProducts ( )
19+ if ProcessInfo . processInfo. environment [ " wpcom-api-base-url " ] == nil {
20+ Text ( " ⚠️ Your WPCOM Sandbox URL is not setup " )
21+ . headlineStyle ( )
22+ Text ( " To test In-App Purchases please make sure that the WPCOM requests are pointing " +
23+ " to your sandbox environment and you have the billing system sandbox-mode enabled there. " )
24+ . padding ( )
25+ } else {
26+ List {
27+ Section {
28+ Button ( " Reload products " ) {
29+ Task {
30+ await loadProducts ( )
31+ }
2432 }
2533 }
26- }
27- Section ( " Products " ) {
28- if products. isEmpty {
29- Text ( " No products " )
30- } else if isPurchasing {
31- ActivityIndicator ( isAnimating: . constant( true ) , style: . medium)
32- } else if let stringSiteID = ProcessInfo . processInfo. environment [ Constants . siteIdEnvironmentVariableName] ,
33- let siteID = Int64 ( stringSiteID) {
34- ForEach ( products, id: \. id) { product in
35- Button ( entitledProductIDs. contains ( product. id) ? " Entitled: \( product. description) " : product. description) {
36- Task {
37- isPurchasing = true
38- do {
39- let result = try await inAppPurchasesForWPComPlansManager. purchaseProduct ( with: product. id, for: siteID)
40- print ( " [IAP Debug] Purchase result: \( result) " )
41- } catch {
42- purchaseError = PurchaseError ( error: error)
34+ Section ( " Products " ) {
35+ if products. isEmpty {
36+ Text ( " No products " )
37+ } else if isPurchasing {
38+ ActivityIndicator ( isAnimating: . constant( true ) , style: . medium)
39+ } else if let stringSiteID = ProcessInfo . processInfo. environment [ Constants . siteIdEnvironmentVariableName] ,
40+ let siteID = Int64 ( stringSiteID) {
41+ ForEach ( products, id: \. id) { product in
42+ Button ( entitledProductIDs. contains ( product. id) ? " Entitled: \( product. description) " : product. description) {
43+ Task {
44+ isPurchasing = true
45+ do {
46+ let result = try await inAppPurchasesForWPComPlansManager. purchaseProduct ( with: product. id, for: siteID)
47+ print ( " [IAP Debug] Purchase result: \( result) " )
48+ } catch {
49+ purchaseError = PurchaseError ( error: error)
50+ }
51+ await loadUserEntitlements ( )
52+ isPurchasing = false
4353 }
44- await loadUserEntitlements ( )
45- isPurchasing = false
4654 }
55+ . alert ( isPresented: $presentAlert, error: purchaseError, actions: { } )
4756 }
48- . alert ( isPresented: $presentAlert, error: purchaseError, actions: { } )
49- }
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) . " )
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) . " )
5360 . foregroundColor ( . red)
61+ }
5462 }
55- }
56-
57- Section {
58- Button ( " Retry WPCom Synchronization for entitled products " ) {
59- retryWPComSynchronizationForPurchasedProducts ( )
60- } . disabled ( !inAppPurchasesAreSupported || entitledProductIDs. isEmpty)
61- }
6263
63- if !inAppPurchasesAreSupported {
6464 Section {
65- Text ( " In-App Purchases are not supported for this user " )
66- . foregroundColor ( . red)
65+ Button ( " Retry WPCom Synchronization for entitled products " ) {
66+ retryWPComSynchronizationForPurchasedProducts ( )
67+ } . disabled ( !inAppPurchasesAreSupported || entitledProductIDs. isEmpty)
68+ }
69+
70+ if !inAppPurchasesAreSupported {
71+ Section {
72+ Text ( " In-App Purchases are not supported for this user " )
73+ . foregroundColor ( . red)
74+ }
6775 }
6876 }
69- }
70- . navigationTitle ( " IAP Debug " )
71- . task {
72- await loadProducts ( )
73- }
74- . onReceive ( NotificationCenter . default . publisher ( for : UIApplication . willEnterForegroundNotification ) ) { _ in
75- Task {
76- 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+ }
7785 }
7886 }
7987 }
0 commit comments