From 31c9f40550a3ada931c0e96c1814587efbb0b8aa Mon Sep 17 00:00:00 2001 From: Maurice Date: Thu, 19 Nov 2026 21:26:38 +0100 Subject: [PATCH] fix(native): App Review builds can buy TREK Cloud while orders are closed While TREK Cloud's orders are closed, the plan picker on iOS offers the subscriptions only to builds that buy in the App Store sandbox (TestFlight, App Review, Xcode). That was read from the receipt's file name alone, which App Review's build did not carry: the reviewer saw "TREK Cloud opens soon" and no way to buy, and the app was rejected under 2.1(b) because its in-app purchases could not be found. The environment now comes from the signed app transaction (StoreKit 2, iOS 16 and later), with the receipt's file name as the fallback on iOS 15 or when the app transaction cannot be read. A production build still sees the plans without a buy button until orders open, and the cloud refuses a production purchase before the opening as before. --- client/ios/App/App/TrekShellPlugin.swift | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/client/ios/App/App/TrekShellPlugin.swift b/client/ios/App/App/TrekShellPlugin.swift index ee63e01ff..d98d35b07 100644 --- a/client/ios/App/App/TrekShellPlugin.swift +++ b/client/ios/App/App/TrekShellPlugin.swift @@ -686,9 +686,8 @@ extension TrekShellPlugin { /// know are left out, so the shell offers only what can really be bought. @objc func storeProducts(_ call: CAPPluginCall) { let ids = call.getArray("ids", String.self) ?? [] - // TestFlight, App Review and Xcode builds buy in the sandbox; their receipt says so. - let sandbox = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" Task { + let sandbox = await Self.buysInSandbox() guard AppStore.canMakePayments, let products = try? await Product.products(for: ids) else { call.resolve(["products": [], "sandbox": sandbox]) return @@ -697,6 +696,26 @@ extension TrekShellPlugin { } } + /// Whether this build buys in the App Store sandbox: TestFlight, App Review and + /// Xcode builds do, and while TREK Cloud's orders are closed only they may buy. + /// The signed app transaction names its environment; the receipt's file name, + /// which App Review builds do not always carry, is only the fallback where the + /// app transaction is missing (iOS 15) or cannot be read. + static func buysInSandbox() async -> Bool { + let receiptSaysSandbox = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" + guard #available(iOS 16.0, *), let result = try? await AppTransaction.shared else { + return receiptSaysSandbox + } + // An unverified transaction still names the environment it was signed in; + // it only decides whether the button shows, the cloud checks every purchase itself. + let transaction: AppTransaction + switch result { + case .verified(let signed), .unverified(let signed, _): + transaction = signed + } + return transaction.environment != .production || receiptSaysSandbox + } + /// Feature storeKit: runs the App Store purchase sheet. Resolves with `kind` /// bought (with the signed transaction the control plane verifies), cancelled, /// pending (Ask to Buy, a payment the bank still has to approve) or failed.