Repository navigation
feat: subscription billing — family plan, monthly analysis quota, report lock, RevenueCat (off by default) - #29
Merged
Merged
Conversation
Subscriptions are judged per family and free analysis is capped per Korean calendar month, so the server needs its own records: a usage ledger keyed by call (no foreign keys, so deleting a call or account never shrinks the month's total), the RevenueCat entitlement per user, and processed webhook event ids for deduplication. Every billing setting defaults to empty or the contract value and none is a production requirement: with BILLING_LAUNCH_AT empty the server behaves as today. The migration is 0024 because 0023 is reserved by another branch.
…evenueCat sync First billing pass from the billing contract (section 2): - A family is premium while anyone in it has a valid subscription or the earliest member's trial (max(signup, launch) + TRIAL_DAYS) has not ended, so a new member never extends the trial. - The pipeline checks the family's usage for the Korean month after the consent check and before claiming the call. A family at or over its limit gets ANALYSIS_EXCLUDED with ANALYSIS_QUOTA_EXCEEDED and the audio deleted, without calling STT or Gemini. The check stays out of processing_allowed, which runs again mid-analysis and would cut a call that already started. A call is written to the ledger once when STT starts, even with billing off, and a retried call already in the ledger is never cut. - Reports and signals answer 402 PREMIUM_REQUIRED, kept apart from the 403 for disabled sharing. Baseline and call APIs stay open for free screens. - GET /v1/account/entitlement and POST /v1/account/entitlement/refresh report the family plan; refresh re-reads RevenueCat by our user id only. - POST /v1/webhooks/revenuecat checks the static Authorization value, ignores repeated event ids, refreshes every related user (including TRANSFER targets) and only drops access when the stored expiry passes. It finishes inside the request and answers 503 on failure so RevenueCat retries instead of losing an update. - Account deletion removes the entitlement and webhook rows and blanks the person's id in the usage ledger.
The production env file lives on the server and is filled by the team, so compose falls back to empty values and contract defaults. Until BILLING_LAUNCH_AT is set billing stays off and production is unaffected.
The paywall shows the next charge date only while the subscription renews and offers subscription management once it is cancelled. willRenew comes from the subscription that gives paidUntil (the latest one in the family): true while auto-renewing, false after cancellation, null when nobody pays. It is updated from unsubscribe_detected_at in the REST response and from CANCELLATION and UNCANCELLATION webhooks.
…usage from launch Review fixes before billing is turned on: - A missed renewal webhook could lock a paying family. Before locking reports, excluding a call for quota or answering the entitlement, a subscription that expired within 7 days and was not cancelled is read again from RevenueCat, at most every 10 minutes per person. Failures fall back to stored values and never fail the request. - Entitlements are written with INSERT ... ON CONFLICT DO UPDATE so a refresh racing the first purchase webhook cannot hit the primary key. - Refresh calls RevenueCat only while billing is on and at most every 30 seconds per user; otherwise it answers from stored values. - Webhook authorization ignores surrounding whitespace on both sides. - Without a secret key, events other than EXPIRATION only move the expiry forward and include the billing grace period, so a late retry of an old event cannot cut access. - Usage recorded before BILLING_LAUNCH_AT does not count toward the month. - A call whose STT never finished and that ends ANALYSIS_FAILED gives its usage back; a call that fails after the transcript was saved keeps it. - When I pay, paidUntil and willRenew describe my own subscription.
…is deleted
Account deletion already removes our billing rows; RevenueCat still kept the
customer under the deleted user id. With billing on and a secret key, the
server now calls DELETE /v1/subscribers/{id} after the deletion commits.
RevenueCat queues the deletion and answers 404 for a customer that no
longer exists, which counts as done. Any failure is only logged so the
account deletion still completes; the store subscription itself is
untouched and must be cancelled in the store.
App Store review and the team need to walk through the paywall and a real purchase before billing is turned on for everyone. An operator can now mark an account with "billing preview" in the /ops accounts tab (same pattern as the internal and cohort controls, operator code required, metrics untouched). If anyone in a family is marked, that family is treated as billing on even with BILLING_LAUNCH_AT empty: entitlement says billingEnabled, reports answer 402, the analysis quota applies and refresh calls RevenueCat. Its billing start is the earliest member's signup, so the trial ends 14 days after that and an old review account sees the free plan at once. The same start is kept when billing is later on for everyone. The column is added in 0024, which has not reached production yet.
Decision 2026-11-28: emergency guidance is shown whatever the plan.
GET /parents/{id}/signals?filter=ACUTE no longer answers 402 for a free
family; ALL and PROMOTED stay locked, and the sharing check (403) still
runs first.
Decision 2026-11-28: emergency guidance is shown whatever the plan, but the
report's safetyNotices come from call extractions, not from acute signals,
and the report itself is locked on the free plan.
GET /parents/{id}/safety-notices?days=14 (1-90) returns the same items as
the report ({callId, observedAt, text}, newest call first, short excluded
calls included) for calls that ended in the last N days. It checks sharing
(403) but never the plan. The report and this API now share one function so
the two cannot drift apart.
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.
구독 결제(무료 / 프리미엄 월 13,000원, 가입 뒤 2주 체험)의 서버 쪽입니다. 연동은 RevenueCat 이고, 두 앱의
feat/billing-20261127과 짝을 이룹니다.결제는 꺼진 채로 들어갑니다. 설정
BILLING_LAUNCH_AT이 비어 있으면 모든 사람이 프리미엄이고 잠금·분석 분량 제한이 없어 지금과 똑같이 동작합니다. 새 설정 값이 하나도 없어도 안전하게 동작합니다.요금제 판정
분석 분량
analysis_usage에 셉니다.ANALYSIS_QUOTA_EXCEEDED). 결제를 켜기 전 사용량과 음성 인식이 끝내 실패한 통화는 세지 않습니다.잠금
PREMIUM_REQUIRED를 줍니다(403 공유 꺼짐과 구분).GET /v1/parents/{id}/safety-notices,signals?filter=ACUTE는 402 없음.API
GET /v1/account/entitlement,POST /v1/account/entitlement/refresh(구매 직후 RevenueCat 재확인, 실패하면 502).POST /v1/webhooks/revenuecat:Authorization헤더 비교, 이벤트 ID 중복 거름, 요청 안에서 REST 로 다시 확인.운영 지표 화면
billing_preview): 전체에 켜기 전에 고른 계정(심사·팀)만 결제를 켜고 끝까지 시험합니다.DB
0024_billing(down0022_call_ai_usage, 0023 은 다른 브랜치가 예약): 표analysis_usage·user_entitlements·revenuecat_events, 계정 표시에billing_preview.설정(compose·env 예시에 이름만 더함, 운영 값은 결제를 켤 때 넣음)
BILLING_LAUNCH_AT·REVENUECAT_SECRET_KEY·REVENUECAT_WEBHOOK_AUTH·REVENUECAT_ENTITLEMENT_ID=premium·REVENUECAT_ALLOW_SANDBOX=true·TRIAL_DAYS=14·FREE_ANALYSIS_SECONDS=2400·PREMIUM_ANALYSIS_SECONDS=15000시험
uv run pytest619개 통과,ruff check통과.