Exit offer after an abandoned checkout (iOS, RevenueCat): triggers for IAP and web, pricing it from the store, and an animated price drop
Built an 'abandoned checkout' discount offer on an iOS paywall that sells by in-app purchase and, for US users, RevenueCat web checkout. What worked and what to watch.
Triggers
- IAP: RevenueCat's purchase result has userCancelled (and ErrorCode.purchaseCancelledError). Map both to a .cancelled outcome and return it to the screen alongside any alert, e.g. buy(_:) -> (outcome: PurchaseOutcome?, feedback: PurchaseFeedback?). A helper that only returned 'what to tell the user' had collapsed cancelled and subscribed into the same nil, so the screen could not tell them apart.
- Web: there is no callback. Set a flag when calling openURL, and on scenePhase == .active with the flag set, ask the store afresh before deciding: Purchases.shared.customerInfo(fetchPolicy: .fetchCurrent). The default policy can hand back cached info, which would show a discount to someone who paid seconds ago. Give the protocol a default implementation that falls back to the cached check so test stubs still compile.
- Decide with a pure, tested function: offer follows only .cancelled, and only if an offer exists that actually saves something.
Pricing - Never put the offer price in the app. Read it from a second offering (here named in config) and compare with the regular yearly product. Support both ways a store can express it: a product with a lower base price (cheaper for good), or one with a paid introductory price (cheaper first period, then full). In the second case the UI must state the renewal price. - Web is separate: a RevenueCat Web Purchase Link sells one offering at that offering's prices, so the offer needs its own web product, its own offering and its own link. Keep two links in config and fall back to IAP for the offer when only the plans' link exists. - If the offer can recur (shown every time checkout is abandoned), remove copy like 'you will only see this once'; it is no longer true.
Animation (SwiftUI)
- Counting price: a tiny View & Animatable whose animatableData is the amount; pass terms.price(at: progress) and animate progress 0 -> 1 with one withAnimation(.easeOut(duration:)). Use .monospacedDigit() so the width does not jitter.
- Strike-through drawn like a pen: overlay a 2 pt Rectangle on the old price and animate scaleEffect(x: struck ? 1 : 0, anchor: .leading).
- Keep the 'Save $X' pill in the layout from the start with opacity 0 and scale 0.6, so nothing jumps when it springs in; then a slow continuous phaseAnimator([false, true]) scale to 1.05 keeps attention without a fake countdown timer.
- Verify by recording the simulator and laying frames side by side: the sheet showed 59.99 -> 55.34 -> 50.63 -> 49.99 and the pill landing.
Testing without store setup: a DEBUG launch flag that swaps in a mock service reading a bundled offerings fixture (with the exit offer at the planned price) let the whole path be walked before the dashboard had the product.