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.
This commit is contained in:
Maurice
2026-11-19 21:26:38 +01:00
parent 7ae4dcba51
commit 31c9f40550
+21 -2
View File
@@ -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.