购买测试

测试购买、恢复购买和权益更新。

购买需要原生 development、preview 或 store build。Expo Go 和 Web 可以渲染 starter 的其他部分,但不能跑 react-native-purchases

iOS 购买在随附 webhook 中是端到端的。Android 配置后可以加载 RevenueCat SDK,但当前 Supabase mapper 会忽略 Google Play webhook events。请先扩展 webhook,再把 Android 购买测试视为 entitlement 测试。

Build 要求

使用 EAS development build 或 store-distribution build:

eas build --profile development --platform ios
eas build --profile development --platform android

设置要测试平台的 RevenueCat key:

EXPO_PUBLIC_REVENUECAT_IOS_KEY=appl_xxxxxxxxxxxxxxxxx
EXPO_PUBLIC_REVENUECAT_ANDROID_KEY=goog_xxxxxxxxxxxxxxxxx

env 变更后重启 Metro。bundle/package ID、签名或商店配置变更后重新构建。

商店测试账号

尽量使用真实设备。

创建 sandbox tester

在 App Store Connect 的 Users and Access → Sandbox Testers 中创建 sandbox tester。使用尚未成为 Apple ID 的邮箱。

安装原生 build

安装 development build、internal distribution build 或 TestFlight build。它的 bundle identifier 必须匹配你配置 products 的 ID。

登录 sandbox 账号

在设备上从 App Store 或 Developer 设置登录 Sandbox Account,具体路径取决于 iOS 版本。

测试 Google Play Billing 时,请使用 Play 分发的测试 build。

配置 license testers

在 Play Console 中添加 license testers,并确保 tester 能访问包含该 build 的 internal、closed 或 open testing track。

匹配 package 和 signing

package name 和 signing certificate 必须匹配 Play Console 中的 app 和 products。 如果测试 expo.soarstarter.com.dev 这样的变体 ID,需要为它单独配置 product。

先扩展 webhook 再测试 entitlement

当前 RevenueCat Edge mapper 会忽略 PLAY_STORE。可以测试 Android 购买 UI,但 Supabase entitlement row 不会更新,直到你实现该后端路径。

跑通 iOS 购买测试

登录应用

启动原生 build,并登录 Supabase 账号。购买前 RevenueCat identity sync 必须使用该 Supabase user UUID。

打开 paywall

打开 Home license card、Me → Upgrade to Pro,或 /paywall。确认 packages 从 current offering 加载,且 Annual 存在时被默认选择。

购买 package

点击 Continue,并在 sandbox purchase sheet 中确认。成功后 paywall 会关闭, entitlement.pollAfterPurchase() 开始轮询 Supabase authoritative row。

验证 RevenueCat

在 RevenueCat 切换到 sandbox data,找到 App User ID 等于 Supabase user UUID 的 customer。pro entitlement 应为 active。

验证 Supabase

在 Supabase 中运行 SQL:

select user_id, provider, product_id, product_type, status, period_end
from public.subscriptions
where user_id = 'your-supabase-user-uuid';

App Store 购买应看到 provider = 'app_store'statusactivetrialing,且 period_end 在未来。Lifetime 购买使用 product_type = 'one_time'

恢复购买测试

  1. 重新安装原生 build,或登出后再登录。
  2. 使用同一个 store sandbox account 和同一个 Supabase account。
  3. 打开 paywall 或 Manage subscription。
  4. 点击 Restore purchases
  5. 确认 RevenueCat 返回 active pro entitlement,并且应用轮询 Supabase row。

Restore 检查的是 RevenueCat 的购买缓存;真正的门禁仍取决于 subscriptions row。

常见失败

现象可能原因处理方式
Paywall 提示 purchases are not configured缺少平台 RevenueCat key、Web runtime 或 Expo Go设置 EXPO_PUBLIC_REVENUECAT_IOS_KEY / EXPO_PUBLIC_REVENUECAT_ANDROID_KEY,并使用原生 build
Packages 一直不加载没有 current offering、packages 缺失、product metadata 未完成或商店同步延迟激活 offering、挂载 packages、完成商店 metadata,等待同步
购买前要求登录没有 Supabase session先登录,让购买绑定到账号 UUID
Bundle/package mismatchexpo.soarstarter.com.dev 测试,但 products 为生产 ID 创建为当前变体配置 products,或构建匹配的变体
RevenueCat entitlement active 但 Supabase row 缺失Webhook URL/Authorization 错误、function 未部署,或 app_user_id 不是 UUID检查 REVENUECAT_WEBHOOK_AUTH、function logs 和 RevenueCat customer ID
Android 购买没有解锁 Supabase entitlement当前 webhook 忽略 PLAY_STORE events在 Android entitlement 测试前扩展 webhook mapper 和数据库 enum
Restore 找不到购买使用了不同 store sandbox account、不同 Supabase account,或没有 active purchase使用相同账号,或用新的 sandbox purchase 测试

相关页面

On this page