Next · Unreleased

Working-tree content. Subject to change and not yet released. Commit: e3d4530507.

RC / IAP Monetization — Integration Design

Design + plan for wiring RevenueCat into piano, re-based onto dev's catalog-from-sheet + entitlements model (post origin/dev merge). Status: DESIGN — approved, pending PO inputs. Scope: subscription (premium) + No-Ads pack (no_ads) + IAP single-song deals. Date: 2026-06-22.

Decisions taken (design session)

  • Live prices — the paywall renders localized prices from hub.subscription.getOfferings(), not static copy (App Store compliance + currency correctness).
  • Refresh-based entitlement sync — hub.subscription exposes no live customer-info listener, so RC entitlements are synced to the app on first ensureHubPurchases() configure (getCustomerInfo) and after purchase/restore (both return { customerInfo, isPremium }). A live listener can be added later for in-session renewal.
  • RC is the source of truth — entitlements-store (isPremium, adsRemoved) + owned songs are a cache/mirror of RC entitlements, not hand-set flags.
  • No-Ads pack → a real RC entitlement no_ads (RC-first, mirrors premium).
  • IAP songs → each IAP song carries an App Store productId sourced from a new productId column in the catalog Google Sheet (per isIAP row), value com.piano.songdeal1/2/3. 1 product = 1 song.
  • Variant → offering (confirmed): paywall premium / post-onboarding → default offering (weekly + yearly); oneTimeOffer → discount offering (weekly50 + yearly50).

1. Product catalog (from PO spec)

TypeProduct idPrice (USD)OfferingEntitlementBenefit
Subcom.piano.weekly7.99defaultpremium3-day free trial · unlock ALL songs · remove ALL ads
Subcom.piano.yearly39.99defaultpremiumsame as weekly
Subcom.piano.weekly503.99discountpremiumno trial · same benefit
Subcom.piano.yearly5019.99discountpremiumno trial · same benefit
IAPcom.piano.noadspack9.99—no_adsremove interstitial + banner (KEEP rewarded)
IAPcom.piano.songdeal10.99—(song unlock)buy 1 specific song
IAPcom.piano.songdeal20.99—(song unlock)buy 1 specific song
IAPcom.piano.songdeal30.99—(song unlock)buy 1 specific song

RC returns 4 offerings — verified live on-device 2026-06-22 (all products + localized prices load OK; RC side is fully ready):

  • default — $rc_annual→com.piano.yearly (1.199.000đ) · $rc_weekly→com.piano.weekly (249.000đ)
  • discount — $rc_annual→com.piano.yearly50 (599.000đ) · $rc_weekly→com.piano.weekly50 (119.000đ)
  • iap_noads — iap_noads→com.piano.noadspack (299.000đ)
  • iap_song — song_1/song_2/song_3 → com.piano.songdeal1/2/3 (29.000đ each)

2. Entitlement model — 3 buckets (mapped to dev's model)

BucketRC sourceSynced toApp effect
premiumentitlement premium (any active sub)entitlements-store.isPremium + grantPremiumEntitlement() (library setSubscription + sdk.player.setVip)unlock ALL songs + remove ALL ads
no_adsLifetime: allPurchasedProductIdentifiers ∋ com.piano.noads.lifetime (t1) or com.piano.noadspack (t2, legacy). Timed 1d / 7d: nonSubscriptionTransactions dates, each pass its own length from its purchase (no stacking: the cover ends with the pass that ends last), checked against the later of the device clock and requestDate — product-ownership, no RC entitlement needed. Table: noads-products.ts, rule: noads-expiry.tsentitlements-store.adsRemoved (a timer + foreground re-check turn it off when a timed pack ends)remove interstitial, FSN, App Open + banner; KEEP rewarded (the ads engine gate is per format: rewarded closes for VIP only, entitlement-gate.ts)
song unlock…allPurchasedProductIdentifiers ∋ com.piano.songdeal{1,2,3} (offering iap_song)unlockSongEntitlement(songId) (library acquireSong + sdk.player.addUserSong)unlock 1 specific song

Lock model already exists (packages/catalog/src/lock-rules.ts getSongLockState): VIP/owned → PLAYABLE; else isPremium→LOCKED_PREMIUM, isIAP→LOCKED_IAP, isAdsUnlock→LOCKED_ADS. Premium entitlement makes ctx.isVip true → every song resolves PLAYABLE. No lock-rule change needed.

Ad-gating rules

Ad typeSkip when
Interstitialpremium OR no_ads
Bannerpremium OR no_ads
Rewardedpremium only (no_ads does not remove rewarded — ad-unlock songs still work)

3. Architecture — entitlement sync

RC (source of truth) — configured lazily via ensureHubPurchases(reason)
  ├─ first configure: getCustomerInfo() ──► syncEntitlementsFromRC(customerInfo)
  ├─ purchase():       { customerInfo } ────► syncEntitlementsFromRC(customerInfo)
  └─ restore():        { customerInfo } ────► syncEntitlementsFromRC(customerInfo)
                                              + reconcileOwnedIapSongsFromRC() (IAP song re-unlock)

syncEntitlementsFromRC(info):
  premium = info.entitlements.active["premium"]?.isActive   → store.setPremium(premium) + grant/clear VIP (library + sdk.player.setVip)
  noAds   = info.entitlements.active["no_ads"]?.isActive     → store.setAdsRemoved(noAds)
  ownedSongs (non-sub purchases) ─ reconcile on restore / IAP purchase attempt (not on catalog load)

RevenueCat lifetime (heap / memory)

react-native-purchases and the native RevenueCat SDK are process-lifetime singletons, not screen-scoped. Once ensureHubPurchases() runs, the JS module, hub.subscription, and native configure stay reachable until the app process ends.

Deferred init (so a browsing-only song list can avoid RC until paywall/IAP):

TriggerensureHubPurchases reason tag
Subscription paywall opens / purchase / restorepaywall:packages, paywall:purchase, paywall:restore
IAP song offerings (IAP deal row scrolls into view or IAP tap)iap-offerings:fetch
IAP row / modal purchaseiap:row-purchase, iap:modal-purchase
Remove-ads / sale-off50 flowsremove-ads:purchase, sale-off50:*

Guest session creation does not call RC — lock UI reads MMKV-hydrated entitlements-store until one of the paths above runs. The first configure logs [rc] init | reason = … and stores the tag in the IAP init reason for heap profiling.

entitlements-store needs setPremium(bool) / setAdsRemoved(bool) setters — subscriptions lapse, so the sync must be able to clear, which dev's grant-only grantPremium()/removeAds() can't. grantPremiumEntitlement() stays for the VIP library/SDK side-effects (called when premium flips true).

hub.ts already caches isPremiumCached for ad-gating; extend the launch refresh to also (a) cache isNoAdsCached and (b) push both into entitlements-store. A single syncEntitlementsFromRC() is the one place that reads customerInfo and writes the store/library.

4. Files to create

  • src/features/monetization/catalog.ts — typed product catalog (id, kind, offering, entitlement). Pure data + types; single source of truth for product ids. No RN/RC imports.
  • src/features/monetization/entitlements.ts — pure gating helpers from { isPremium, isNoAds }: shouldShowInterstitial, shouldShowBanner, shouldShowRewarded. Unit-tested next to the file.
  • src/features/monetization/syncEntitlementsFromRC.ts — reads a CustomerInfo, writes entitlements-store + grantPremiumEntitlement/clear. The launch + purchase/restore sync seam.

5. Integration points (dev's actual files → change)

WhereChange
revenuecat-iap-service.tson launch, sync entitlements from getCustomerInfo(); the ad gate reads isNoAds from the entitlements store
ads.tsinterstitial/banner gate on premium ‖ no_ads; rewarded stays premium-only — via entitlements.ts
PaywallModal + PaywallPlanBody/OfferBodyfetch offerings, render live localized prices; variant→offering map; loading/error
PaywallHosthandlePurchase(trialOn) → pick package (plan + trial intro) → hub.subscription.purchase(pkg) → sync → close; replace the grantPremiumEntitlement() stub
PaywallFooter restoreonRestore → hub.subscription.restore() → sync (currently onClose stub)
RemoveAdsPromoCard → flow store buyRemoveAds → iap.buyNoAdspurchase(noadspack) straight from the song-list promo (no modal since 2026-11-05) → syncEntitlements → no_ads entitlement drives adsRemoved
SaleOff50Modalyearly 50%-off sale card (Figma 7688:117350); wire onClaim → hub.subscription.purchase(yearly50) with live originalPriceLabel / salePriceLabel from RC
PremiumUnlockModal + SongsScreenfor LOCKED_IAP songs add a "Buy ($0.99)" CTA → hub.subscription.purchase(song.productId) → unlockSongEntitlement(songId) (rewarded "Play for free" path already wired for LOCKED_ADS)
catalog schema + sheetadd optional productId column/field for isIAP rows

6. Hub change (required for no_ads)

The IAP adapter maps a single premium entitlement. no_ads needs a second entitlement check:

  • The app checks info.entitlements.active["no_ads"] directly in the IAP adapter (the former hub is gone).

→ Checking no_ads via getCustomerInfo() in syncEntitlementsFromRC needs no hub release.

7. Plan (phases)

PhaseWorkDepends on
P1catalog.ts + entitlements.ts + syncEntitlementsFromRC.ts (+ unit tests)—
P2hub.ts launch sync + isNoAds seam; ads.ts gate on premium ‖ no_adsP1 (+ PO no_ads entitlement for real data)
P3Subscription paywall: live prices + variant→offering + purchase(trialOn)/restore end-to-endRC subs (done)
P4no_ads: song-list promo buyRemoveAds → purchase(noadspack) + restorePO creates RC no_ads entitlement
P5IAP songs: productId sheet column → PremiumUnlockModal Buy CTA → purchase(songdeal) → unlockSongEntitlementPO: 3 songs + productId mapping

P1 + P3 start immediately. P2/P4 (no_ads) wait on PO's RC no_ads entitlement. P5 waits on PO's IAP mapping.

Open items / PO

  • create RC entitlement no_ads — NOT needed: non-consumable IAPs (noadspack, songdeal*) are read from customerInfo.allPurchasedProductIdentifiers (product-ownership). Only premium subscriptions need an entitlement (already configured — verify after a test purchase).
  • IAP songs (P5) — chosen: Rush E + Passo Bem Solto (Slowed) (2 songs → 2 of the 3 songdeal products; songdeal3 reserved). The iap_song offering exists (song_1/2/3 → songdeal1/2/3). Still needed for P5: the 2 songs' catalog ids, which songdeal{1,2} each maps to, and a productId column in the Sheet (or a hardcoded 2-entry map). These 2 rows must have isIAP=true in the Sheet.
  • Confirm the App Store subs carry the 3-day free-trial intro offer on weekly/yearly (none on *50) — RC surfaces it via the package intro price.