Rtdn 标志

Rtdn

组织
RevenueCat
rtdn

Use this skill when setting up Real Time Developer Notifications (RTDN) for Google Play. Covers the full pipeline from Cloud Pub/Sub configuration through message parsing and processing all 18 subscription notification types (codes 1 to 13, 17 to 20, and 22).

Add to TypingMind

概览

发布者RevenueCat
代码仓库play-billing-skills
技能名称rtdn
星标数
58
复刻数
0
附带文件
仅含指令
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 RevenueCat 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Rtdn AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/RevenueCat/play-billing-skills/tree/main/google-play/rtdn
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/RevenueCat/play-billing-skills.git /tmp/play-billing-skills
mkdir -p .claude/skills
cp -r /tmp/play-billing-skills/google-play/rtdn .claude/skills/rtdn
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Rtdn,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Rtdn。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Rtdn 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Real Time Developer Notifications (RTDN)

RTDN pushes subscription and purchase state changes from Google Play to your backend within seconds. Use it as the primary signal for entitlement updates; polling the Play Developer API on a schedule is a fallback, not a substitute.

Phase 1: Understand

Pin down the following before you write code:

  • What triggers a notification. Google Play publishes a message to a Cloud Pub/Sub topic you own every time a subscription changes state, a purchase is voided, or (if enabled in the RTDN settings) a one time product is purchased or a pending one is canceled.
  • What the notification contains. A DeveloperNotification JSON object with packageName, eventTimeMillis, and exactly one of subscriptionNotification, oneTimeProductNotification, voidedPurchaseNotification, pendingRefundReviewNotification, or testNotification. Subscription, one time product, and voided purchase notifications carry a purchaseToken (a pending refund review carries orderId and pendingRefundToken instead), not the full purchase state.
  • Who owns what. You own the Pub/Sub topic and subscription in your own Google Cloud project. Google Play only has publish rights.
  • Delivery semantics. Cloud Pub/Sub guarantees at least once delivery and does not guarantee ordering. Duplicates and out of order messages are normal.
  • The golden rule. RTDNs are signals, not sources of truth. For every notification, call purchases.subscriptionsv2.get or purchases.products.get and update entitlements from the API response, not the notification type.

Decide push vs pull:

StrategyPick when
Push subscriptionYou have a public HTTPS endpoint and want a webhook style integration with retries handled by Pub/Sub
Pull subscriptionYour backend has no public URL, needs batch processing, or wants fine grained control over consumption rate

Push is the simpler default. You can swap strategies later without changing the Play Console configuration.

Phase 2: Plan

Write the plan before provisioning anything.

Infrastructure checklist

  • One Pub/Sub topic (example: play-billing-notifications). One topic handles subscriptions, one time products, and voided purchases.
  • One subscription attached to the topic with an appropriate ack-deadline (60s is a reasonable starting point).
  • IAM binding granting roles/pubsub.publisher to google-play-developer-notifications@system.gserviceaccount.com on the topic.
  • Play Console Monetization setup pointing at projects/YOUR_PROJECT_ID/topics/play-billing-notifications.
  • A test notification fired from the Play Console to confirm end to end wiring.

Ack semantics

Your webhook must return 2xx within the ack deadline to acknowledge the message. Any other response or a timeout causes Pub/Sub to retry with exponential backoff. Plan accordingly:

  • Ack as soon as you have durably captured the message (message ID plus payload). Do the API call and database updates inside the same request only if they fit well inside the ack deadline. Otherwise ack fast and process asynchronously from a queue you own.
  • Never ack before you have persisted enough to replay the work. A lost message after ack means a missed state change.
  • Any status other than 102, 200, 201, 202, or 204 (4xx included) is a negative acknowledgement, and Pub/Sub redelivers the message. Return 5xx for transient failures. For a message you can never process, save it to your own error store and return 200, or configure a dead letter topic with a maximum delivery attempts limit.

Idempotency plan

Because duplicates and out of order deliveries are guaranteed, every handler must be idempotent.

  • Deduplicate on Pub/Sub messageId. Persist processed message IDs with a TTL of 24 to 48 hours. Skip any replay you have already seen, then ack.
  • Do not mutate state from the notification type alone. Always call the Developer API for the current state. Two out of order notifications produce two API calls that both return the same current state, so your database converges to the correct value.
  • Track eventTimeMillis per purchaseToken. Record the highest event time you have seen so you can detect stale events if you need to branch logic, but still call the API on every notification.
  • Make database writes idempotent. Use upserts keyed on purchaseToken rather than inserts. Revoking access must be safe to run twice; so must extending expiry.

Monitoring

  • Dashboard the count of unacked messages and the oldest unacked age on the subscription.
  • Alert on sustained non 2xx responses from the webhook.
  • Count notifications by type as a metric so you can spot anomalies (for example, a spike in SUBSCRIPTION_ON_HOLD).

Phase 3: Execute

Step 1: Create the topic

bash
gcloud pubsub topics create play-billing-notifications

Step 2: Grant publish rights to Google Play

bash
gcloud pubsub topics add-iam-policy-binding \
  play-billing-notifications \
  --member=serviceAccount:google-play-developer-notifications@system.gserviceaccount.com \
  --role=roles/pubsub.publisher

Missing this binding is the most common reason a freshly configured RTDN pipeline delivers no messages.

Step 3: Create a push subscription

bash
gcloud pubsub subscriptions create play-billing-sub \
  --topic=play-billing-notifications \
  --push-endpoint=https://api.yourapp.com/billing/rtdn \
  --ack-deadline=60

For pull, omit --push-endpoint and run a subscriber loop in your backend.

Step 4: Enable RTDN in Play Console

In the Play Console, open Monetization setup, find Real time developer notifications, check Enable real-time notifications, enter projects/YOUR_PROJECT_ID/topics/play-billing-notifications, click Send Test Message, choose Get all notifications for subscriptions and one-time products under notification types (the other option omits one time product events), and click Save changes. A push subscriber should receive the test within seconds.

Step 5: Write the webhook endpoint

The push body wraps the notification in a Pub/Sub envelope. The data field is a base64 encoded JSON string.

json
{
  "message": {
    "data": "eyJ2ZXJzaW9uIjoiMS4wIiwi...",
    "messageId": "136969346945",
    "attributes": {}
  },
  "subscription": "projects/myproject/subscriptions/play-billing-sub"
}

Decode the payload:

kotlin
import java.util.Base64

fun decodePubSubData(base64: String): String {
    val bytes = Base64.getDecoder().decode(base64)
    return String(bytes, Charsets.UTF_8)
}

Parse into a DeveloperNotification:

kotlin
data class DeveloperNotification(
    val version: String,
    val packageName: String,
    val eventTimeMillis: Long,
    val subscriptionNotification: SubscriptionNotification? = null,
    val oneTimeProductNotification: OneTimeProductNotification? = null,
    val voidedPurchaseNotification: VoidedPurchaseNotification? = null,
    val pendingRefundReviewNotification: PendingRefundReviewNotification? = null,
    val testNotification: TestNotification? = null
)

Step 6: Dispatch by notification shape

Route by which sub object is present, then by type code.

kotlin
fun route(n: DeveloperNotification) {
    when {
        n.subscriptionNotification != null ->
            handleSubscription(n.subscriptionNotification)
        n.oneTimeProductNotification != null ->
            handleOneTime(n.oneTimeProductNotification)
        n.voidedPurchaseNotification != null ->
            handleVoided(n.voidedPurchaseNotification)
        n.pendingRefundReviewNotification != null ->
            handleRefundReview(n.pendingRefundReviewNotification)
        n.testNotification != null ->
            log("RTDN test received")
        else ->
            log("Unknown RTDN shape: $n")
    }
}

Call orders.reviewrefund (POST applications/{packageName}/orders/{orderId}:reviewrefund) with pendingRefundToken, refundPreference, and sampleContentProvided within 24 hours of a pendingRefundReviewNotification.

Step 7: Deduplicate before processing

kotlin
suspend fun onPubSubMessage(
    messageId: String,
    n: DeveloperNotification
) {
    if (store.hasProcessed(messageId)) return
    route(n)
    store.markProcessed(messageId)
}

Step 8: Always call the API

kotlin
suspend fun handleSubscription(s: SubscriptionNotification) {
    metrics.increment("rtdn.sub.${s.notificationType}")
    val sub = playApi.getSubscriptionV2(
        packageName, s.purchaseToken
    )
    updateEntitlementFromApiState(s.purchaseToken, sub)
}

Apply the same pattern to one time products (purchases.products.get) and voided purchases (revoke the entitlement keyed on the purchase token; for refundType 2 claw back only the refunded quantity, see below).

Notification type reference

Chapter 10 of the handbook documents the 14 subscription types, 2 one time product types, voided purchase, and test notification. The 18 subscription notification types (codes 1 to 13, 17 to 20, and 22; the newer ones are SUBSCRIPTION_ITEMS_CHANGED, SUBSCRIPTION_CANCELLATION_SCHEDULED, SUBSCRIPTION_PRICE_CHANGE_UPDATED, SUBSCRIPTION_PENDING_PURCHASE_CANCELED, and SUBSCRIPTION_PRICE_STEP_UP_CONSENT_UPDATED) are listed in Appendix A of the handbook. See the RTDN chapter on revenuecat.com for in depth coverage of each type; see the rtdn-reference skill or the appendix linked from it for the complete list.

Key subscription types you must handle correctly:

TypeCodeAction
SUBSCRIPTION_RECOVERED1Restore access; payment recovered from hold
SUBSCRIPTION_RENEWED2Extend expiry to new lineItems[].expiryTime
SUBSCRIPTION_CANCELED3Keep access until lineItems[].expiryTime; do not revoke now
SUBSCRIPTION_PURCHASED4Server side safety net; verify the purchase
SUBSCRIPTION_ON_HOLD5Revoke access; keep the subscription record
SUBSCRIPTION_IN_GRACE_PERIOD6Keep access; surface a payment update prompt
SUBSCRIPTION_RESTARTED7User resubscribed before expiry; confirm auto renewing
SUBSCRIPTION_PRICE_CHANGE_CONFIRMED8Deprecated; handle code 19 instead
SUBSCRIPTION_DEFERRED9Fetch new expiry time and extend access
SUBSCRIPTION_PAUSED10Revoke access until resume
SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED11Sync pause schedule with API state
SUBSCRIPTION_REVOKED12Revoke access immediately
SUBSCRIPTION_EXPIRED13Terminal; revoke if not already
SUBSCRIPTION_PRICE_CHANGE_UPDATED19Re-read lineItems[].autoRenewingPlan.priceChangeDetails
SUBSCRIPTION_PENDING_PURCHASE_CANCELED20Clean up the pending record. If it was a pending upgrade, downgrade, or top up, the old subscription stays active

One time products: ONE_TIME_PRODUCT_PURCHASED (1) and ONE_TIME_PRODUCT_CANCELED (2). Voided purchases: revoke and record for reconciliation; productType marks subscription (1) vs one time (2). For refundType 2 (quantity based partial refund) claw back only the refunded quantity (refundableQuantity from purchases.productsv2 holds what remains).

Phase 4: Verify

  • Fire a test notification from Play Console and confirm the webhook logs a testNotification payload.
  • Run an end to end sandbox purchase, cancel it, and verify you receive SUBSCRIPTION_PURCHASED then SUBSCRIPTION_CANCELED with matching purchase tokens.
  • Replay the same Pub/Sub messageId twice and confirm your handler runs the business logic exactly once.
  • Shuffle two notifications for the same token and confirm the final database state matches the API response rather than the order of delivery.
  • Temporarily return 500 from the webhook and confirm Pub/Sub retries and eventually delivers after you return to 200.
  • Check the Pub/Sub subscription metrics for oldest unacked age; it should stay close to zero in steady state.
  • Run a periodic reconciliation job that polls a sample of subscriptions against the API. If it finds drift, your RTDN pipeline has gaps to investigate.

References

常见问题

Rtdn AI 技能有什么作用?

Use this skill when setting up Real Time Developer Notifications (RTDN) for Google Play. Covers the full pipeline from Cloud Pub/Sub configuration through message parsing and processing all 18 subscription notification types (codes 1 to 13, 17 to 20, and 22).

为什么在 TypingMind 中使用 Rtdn?

因为您只需安装一次,就能搭配任何模型使用。Rtdn 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Rtdn?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/RevenueCat/play-billing-skills/tree/main/google-play/rtdn。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Rtdn?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Rtdn 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Rtdn 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Rtdn AI 技能免费吗?

是的。RevenueCat 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇