Fix SK2 computed period prices showing incorrectly rounded values in production#460
Open
Fix SK2 computed period prices showing incorrectly rounded values in production#460
Conversation
Product.priceFormatStyle carries storefront-specific rounding rules in production that differ from StoreKit config file testing. This caused computed period prices (weeklyPrice, dailyPrice, monthlyPrice, yearlyPrice) to display incorrectly — e.g. a £4.99/week product showing as £5.00/week on the UK App Store. Switch from priceFormatStyle to NumberFormatter (via the existing PriceFormatterProvider) for formatting computed prices, matching how the SK1 path works. localizedPrice still uses priceFormatStyle since it formats the product's own original price. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sources/SuperwallKit/StoreKit/Products/StoreProduct/SK2StoreProduct.swift
Outdated
Show resolved
Hide resolved
Sources/SuperwallKit/StoreKit/Products/StoreProduct/SK2StoreProduct.swift
Show resolved
Hide resolved
This property reads the intro offer price directly from StoreKit (not a computed value), so it should use priceFormatStyle like localizedPrice. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…Unit Avoids leaking a USD currency symbol in non-USD locales when NumberFormatter.string(from:) returns nil. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
weeklyPrice,dailyPrice,monthlyPrice,yearlyPrice) display incorrectly rounded values. For example, a £4.99/week product shows as £5.00/week on the UK App Store.Product.priceFormatStylecarries storefront-specific rounding rules in production that don't exist in StoreKit config file testing. When we feed a computedDecimalback throughpriceFormatStyle, it re-applies rounding that corrupts the value.priceFormatStyletoNumberFormattervia the existingPriceFormatterProvider.priceFormatterForSK2(), matching the SK1 code path.localizedPricestill usespriceFormatStylesince it formats the product's own original price (not a computed value).Evidence from production (app 31689, UK App Store, GBP)
$product_price$product_weekly_price$product_monthly_price$product_yearly_priceThis bug is not reproducible with StoreKit config files in Xcode because local test products create a simpler
priceFormatStylewithout storefront rounding rules.Test plan
SubscriptionPeriodPriceTestsstill pass (math layer unchanged)CHANGELOG.mdfor any breaking changes, enhancements, or bug fixes.swiftlintin the main directory and fixed any issues.🤖 Generated with Claude Code
Greptile Summary
This PR fixes incorrectly rounded SK2 computed period prices (
weeklyPrice,dailyPrice,monthlyPrice,yearlyPrice) in production by replacingProduct.priceFormatStyle— which carries storefront-specific rounding rules — with aNumberFormattervia the existingPriceFormatterProvider.priceFormatterForSK2(), matching the SK1 code path. All four computed price properties and the trial price helpers are updated;localizedPriceintentionally retainspriceFormatStylesince it formats the product's raw price directly.Confidence Score: 5/5
Safe to merge — the core fix is correct and well-targeted; remaining findings are P2 style issues only.
The fix correctly addresses the root cause (storefront-specific rounding from
priceFormatStyle) by routing computed prices throughNumberFormatter, matching the SK1 precedent. The two P2 comments cover a hardcoded"$0.00"fallback (practically unreachable) and a minor design inconsistency withlocalizedTrialPeriodPrice. Neither affects correctness in normal operation.No files require special attention.
Vulnerabilities
No security concerns identified. The change only affects how computed prices are formatted for display; no new data sources, network calls, or sensitive inputs are introduced.
Important Files Changed
priceFormatStylewithNumberFormatterviaPriceFormatterProviderfor computed period prices to avoid storefront-specific rounding; two minor P2 issues: hardcoded"$0.00"fallback and inconsistency betweenlocalizedTrialPeriodPriceandlocalizedPriceformatting paths.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[SK2StoreProduct computed price properties] --> B[Compute Decimal via division + roundedPrice] B --> C{Before fix} B --> D{After fix} C --> E["Decimal.formatted(priceFormatStyle)\n⚠ applies storefront rounding\ne.g. £4.99 → £5.00"] D --> F["priceFormatterProvider.priceFormatterForSK2()\n✅ standard NumberFormatter\ne.g. £4.99 → £4.99"] G[SK2StoreProduct.localizedPrice] --> H["Decimal.formatted(priceFormatStyle)\n✅ unchanged – raw SK2 price, no computed division"] style E fill:#ffcccc style F fill:#ccffcc style H fill:#ccffccPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "Fix SK2 computed prices showing incorrec..." | Re-trigger Greptile