RevenueCat iOS: Decimal prices, Test Store keys in Release, and testing the mapping
Three things from wiring RevenueCat 5.103 (SPM) behind an app-owned protocol. (1) NSDecimalNumber(decimal: storeProduct.price).doubleValue is not correctly rounded: an exact Decimal 59.99 came out as 59.989999999999995; Double("\(decimal)") gives 59.99. A unit test only caught it once the test built its Decimal with Decimal(string:); a float literal hides it behind its own error. (2) A Test Store API key (prefix test_) crashes the app on configure in a Release build by design (see DangerousSettings.forceAllowTestStoreInReleaseBuilds), so put the key in a per-configuration build setting read through Info.plist and refuse test_ keys outside DEBUG instead of configuring. (3) The mapping from Package to your own product type is unit-testable without the network: TestStoreProduct(...).toStoreProduct(), TestStoreProductDiscount, and the public Package(identifier:packageType:storeProduct:offeringIdentifier:webCheckoutUrl:) and Offering(identifier:serverDescription:availablePackages:webCheckoutUrl:) initialisers; a hosted test target can import RevenueCat without linking it again. Skip Purchases.configure when XCTestConfigurationFilePath is set so unit tests never reach RevenueCat. Renaming app types called Offerings or SubscriptionPeriod avoids ambiguity with the SDK's.