Skip to content

feat: サインインした後に購入をいまのユーザーへ移す syncPurchases を足す - #9

Merged
taniguchi-kyoichi merged 1 commit into
mainfrom
feat/sync-purchases
Nov 1, 2026
Merged

taniguchi-kyoichi merged 1 commit into
mainfrom
feat/sync-purchases

Conversation

@taniguchi-kyoichi

Copy link
Copy Markdown
Contributor

何のため

2026-11-01、ごほうび習慣でトライアルを始めた人が2台目の端末でサインインしたところ、syncUser(userId:) が logIn しかしないため Premium が前の身元に残り、「購入を復元」を押すまで付かなかった。

変えたこと

  • SubscriptionUseCase.syncPurchases() を足した。Purchases.shared.syncPurchases() を包み、UIを出さずに購入をいまの身元へ移し、キャッシュを更新して SubscriptionStatus を返す。失敗は SubscriptionError.userSyncFailed
  • プロトコルの既定実装は checkSubscriptionStatus() で答える(既存の準拠はそのままコンパイルが通る)。PreviewSubscriptionUseCase も実装
  • 起動時の syncUser には組み込まない。 RevenueCat の transfer behavior は既定で「新しい App User ID へ移す」なので、起動ごとに同期すると入れ直しで作られた使い捨てのアカウントが購入を奪う。呼ぶのは本人が明示的にサインインして uid が変わった時だけ(ドキュメントに明記)

確かめたこと

  • swift build / swift test が通る
  • 新しいテスト SyncPurchasesTests:結果のキャッシュ反映・サインイン後に前の身元の購入が付く・syncUser は同期を呼ばない・失敗してもキャッシュは変わらない・既定実装
  • scripts/release.sh --dry-run:bump=minor(3.5.0 → 3.6.0、削除0・追加4)

🤖 Generated with Claude Code

syncUser は身元を入れ替えるだけなので、前の身元で始めたトライアルは
「購入を復元」を押すまで新しいアカウントに付かなかった。
syncPurchases は Purchases.syncPurchases を包み、何も出さずに購入を移して
SubscriptionStatus を返す。起動時の syncUser には組み込まない
(既定の transfer behavior で使い捨てのアカウントが購入を奪うため)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@taniguchi-kyoichi
taniguchi-kyoichi merged commit 201a180 into main Nov 1, 2026
1 check failed
@taniguchi-kyoichi
taniguchi-kyoichi deleted the feat/sync-purchases branch November 1, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant