Skip to content

Fix sandbox detection#442

Merged
yusuftor merged 2 commits intodevelopfrom
fix/improve-sandbox-detection
Feb 26, 2026
Merged

Fix sandbox detection#442
yusuftor merged 2 commits intodevelopfrom
fix/improve-sandbox-detection

Conversation

@yusuftor
Copy link
Copy Markdown
Collaborator

@yusuftor yusuftor commented Feb 26, 2026

Summary

  • Uses AppTransaction.environment (iOS 16+) as the primary sandbox detection method in DeviceHelper.detectSandbox(), with the existing receipt URL path check as a fallback for older iOS versions.
  • The previous approach only checked Bundle.main.appStoreReceiptURL for "sandboxReceipt", which could incorrectly return false for apps using Stripe or other non-StoreKit payment methods — including during App Review.
  • Leverages the AppTransaction.shared call already made in ReceiptManager.setAppTransactionId() to also capture the environment, avoiding any additional async work.

Checklist

  • I added/updated tests or detailed why my change isn't tested.
  • I added an entry to the CHANGELOG.md for any breaking changes, enhancements, or bug fixes.
  • All unit tests pass.
  • All UI tests pass.
  • Demo project builds and runs on iOS.
  • Demo project builds and runs on Mac Catalyst.
  • Demo project builds and runs on visionOS.
  • I have run swiftlint in the main directory and fixed any issues.
  • I have updated the SDK documentation as well as the online docs.
  • I have reviewed the contributing guide

🤖 Generated with Claude Code

Greptile Summary

This PR fixes incorrect sandbox detection for apps using Stripe or other non-StoreKit payment methods. The previous approach only checked the receipt URL path for "sandboxReceipt", which would return false for apps without StoreKit receipts - even during App Review or TestFlight.

The fix leverages AppTransaction.environment (available on iOS 16+) as the primary detection method, with the receipt URL check as a fallback for older iOS versions or when AppTransaction data isn't available yet. This is captured in a new static property ReceiptManager.isSandboxEnvironment that's set during initialization.

Key changes:

  • Added ReceiptManager.isSandboxEnvironment static property set from AppTransaction.shared
  • Updated DeviceHelper.detectSandbox() to check this property before falling back to receipt URL
  • Proper fallback ensures backward compatibility and handles initialization timing
  • Added basic tests and CHANGELOG entry

The implementation is clean and follows the existing pattern used by appTransactionId and appId static properties.

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it's a well-designed fix with proper fallback behavior
  • The implementation correctly uses AppTransaction.environment (iOS 16+) as the primary sandbox detection method while maintaining backward compatibility with the receipt URL fallback. The logic is sound, follows existing patterns in the codebase, and includes appropriate tests and documentation.
  • No files require special attention

Important Files Changed

Filename Overview
CHANGELOG.md Added version 4.14.1 entry documenting the sandbox detection fix - clear and accurate description of the change
Sources/SuperwallKit/Network/Device Helper/DeviceHelper.swift Added check for AppTransaction-based sandbox detection before falling back to receipt URL method - logic is sound with appropriate fallback behavior
Sources/SuperwallKit/StoreKit/Products/Receipt Manager/Receipt Manager/ReceiptManager.swift Added static property to capture sandbox environment from AppTransaction - follows existing pattern for appTransactionId and appId
Tests/SuperwallKitTests/StoreKit/Products/Receipt Manager/ReceiptManagerTests.swift Added basic tests for the new isSandboxEnvironment property - verifies property can be set and read correctly

Last reviewed commit: 77138ea

Lever and others added 2 commits February 26, 2026 13:49
Use AppTransaction.environment (iOS 16+) as the primary sandbox
detection method, falling back to the receipt URL path check for
older iOS versions. The previous approach only checked
Bundle.main.appStoreReceiptURL for "sandboxReceipt", which could
return false for apps using Stripe or other non-StoreKit payment
methods, including during App Review.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@yusuftor yusuftor changed the title Fix sandbox detection for Stripe and non-StoreKit flows Fix sandbox detection Feb 26, 2026
@yusuftor yusuftor merged commit 6b68830 into develop Feb 26, 2026
3 checks passed
@yusuftor yusuftor deleted the fix/improve-sandbox-detection branch February 26, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant