Logo Integrating Pbl

Integrating Pbl

Tổ chức
RevenueCat
integrating-pbl

Use this skill when integrating the Google Play Billing Library client side (adding the dependency, wiring BillingClient, managing its connection lifecycle, and querying product details). Grounded in PBL 9.x.

Tổng quan

Nhà phát hànhRevenueCat
Kho mãplay-billing-skills
Tên kỹ năngintegrating-pbl
Sao
58
Bản fork
0
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépApache-2.0
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được RevenueCat công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Integrating Pbl trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/RevenueCat/play-billing-skills/tree/main/google-play/integrating-pbl
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

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/integrating-pbl .claude/skills/integrating-pbl
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Integrating Pbl trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Integrating Pbl ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Integrating Pbl với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Integrating the Play Billing Library

You are wiring the Play Billing Library into an Android app. This skill covers the client side setup: adding the dependency, building BillingClient, managing the connection, and querying products. Follow the phases in order.

Phase 0: Intent

Confirm what the caller actually wants before you touch code. Pick one:

IntentSignal
First time integrationNo com.android.billingclient dependency yet
Upgrading PBLExisting BillingClient on an older version
Fixing connection bugsSERVICE_DISCONNECTED, missing onBillingSetupFinished callbacks
Adding product queriesBillingClient exists, no queryProductDetailsAsync call

If the request is ambiguous, ask. Do not write Gradle edits or Kotlin until you know the target state.

Phase 1: Discovery

Inspect the project before changing anything.

Check the Gradle setup:

bash
grep -r "com.android.billingclient" --include="*.gradle*"

Check existing BillingClient usage:

bash
grep -rn "BillingClient" --include="*.kt" --include="*.java" src/

Record these facts:

FactWhy it matters
Current PBL versionDrives migration steps (PBL 8 and 9 require PendingPurchasesParams)
Context passed to builderAny context works; BillingClient uses its application context
Whether enablePendingPurchases is calledMissing call throws IllegalArgumentException on build()
Whether auto reconnection is enabledAbsent means you own retry logic
Where BillingClient is instantiatedViewModel, singleton, or Application scoped
Whether KTX is on the classpathDecides callback vs coroutine style
compileSdkPBL 9 needs 35+ (androidx.core 1.15.0)
minSdkPBL 8.1+ needs 23+
Kotlin versionbilling-ktx 9.x needs Kotlin 2.2+; on older Kotlin use plain billing

If you find multiple BillingClient instances in one process, flag it. One instance per process is the rule.

Phase 2: Plan

Before writing code, pick a connection strategy and confirm with the caller.

StrategyUse whenTrade off
Application scoped singletonBilling gates many features, frequent status checksConnection stays open while idle
ViewModel / feature scopedBilling only appears on one or two screensPays setup cost every entry

Then decide:

  1. Callback style or KTX coroutine style. If coroutines are already the norm in the project, pick KTX.
  2. Auto reconnection on or off. Default to on unless you need manual control.
  3. Which product IDs and types (INAPP, SUBS) the initial query covers. Batch up to 20 per call.

Write the plan down. One BillingClient owner, one listener, one connection strategy.

Phase 3: Execute

Step 1 Add the dependency

In the module build.gradle.kts:

kotlin
dependencies {
    implementation("com.android.billingclient:billing-ktx:9.1.0")
}

The billing-ktx artifact pulls in the base library plus coroutine extensions. Drop -ktx if you do not want KTX. PBL 9.x requires compileSdk 35+ and minSdk 23+; billing-ktx 9.x also requires Kotlin 2.2+.

Step 2 Build the BillingClient

Pass any context (the library uses its application context):

kotlin
val billingClient = BillingClient.newBuilder(appContext)
    .setListener(purchasesUpdatedListener)
    .enablePendingPurchases(
        PendingPurchasesParams.newBuilder().enableOneTimeProducts().build()
    )
    .enableAutoServiceReconnection()
    .build()

setListener and enablePendingPurchases(...enableOneTimeProducts()...) are required; build() throws IllegalArgumentException if either is missing. enableAutoServiceReconnection() is optional but strongly recommended.

Step 3 Wire the PurchasesUpdatedListener

One listener per client. Dispatch from it if other components need to react:

kotlin
val purchasesUpdatedListener =
    PurchasesUpdatedListener { result, purchases ->
        when (result.responseCode) {
            BillingResponseCode.OK ->
                purchases?.forEach(::handlePurchase)
            BillingResponseCode.USER_CANCELED -> Unit
            else -> logError(result)
        }
    }

The callback fires on the main thread and can fire while the app is in the background. Update a repository or state holder, not UI directly. Never force unwrap purchases; it is null on non OK responses.

Step 4 Start the connection

Callback form:

kotlin
billingClient.startConnection(object : BillingClientStateListener {
    override fun onBillingSetupFinished(result: BillingResult) {
        if (result.responseCode == BillingResponseCode.OK) {
            onBillingReady()
        }
    }
    override fun onBillingServiceDisconnected() { /* auto retry */ }
})

KTX has no startConnection extension. Use the callback form, or wrap it:

kotlin
suspend fun BillingClient.connect(): BillingResult =
    suspendCancellableCoroutine { cont ->
        startConnection(object : BillingClientStateListener {
            override fun onBillingSetupFinished(result: BillingResult) {
                if (cont.isActive) cont.resume(result)
            }
            override fun onBillingServiceDisconnected() {
                // Resume so the caller never hangs if setup is interrupted
                if (cont.isActive) cont.resume(
                    BillingResult.newBuilder()
                        .setResponseCode(BillingResponseCode.SERVICE_DISCONNECTED)
                        .build()
                )
            }
        })
    }

Do not call billing methods before onBillingSetupFinished fires with OK. Queue pending work and flush on each successful connect.

Step 5 Query product details

Build one query per product type (INAPP and SUBS cannot be mixed in one call; the builder throws IllegalArgumentException), keeping each batch at or under 20 products:

kotlin
val products = listOf(
    QueryProductDetailsParams.Product.newBuilder()
        .setProductId("premium_monthly")
        .setProductType(ProductType.SUBS)
        .build()
)
val params = QueryProductDetailsParams.newBuilder()
    .setProductList(products)
    .build()

Callback form:

kotlin
billingClient.queryProductDetailsAsync(params) { result, queryResult ->
    if (result.responseCode == BillingResponseCode.OK) {
        displayProducts(queryResult.productDetailsList)
        handleUnfetched(queryResult.unfetchedProductList)
    }
}

KTX form:

kotlin
val result = billingClient.queryProductDetails(params)
val details = result.productDetailsList.orEmpty()

The KTX result has no unfetched list and productDetailsList is nullable (use .orEmpty()). Use the callback form if you need Step 6.

Do not cache ProductDetails across sessions. Prices can change; re query each time you display products.

Step 6 Handle UnfetchedProduct results

The callback API's QueryProductDetailsResult may include UnfetchedProduct entries (the KTX ProductDetailsResult does not expose them). Branch on unfetchedProduct.statusCode:

unfetchedProduct.statusCodeAction
INVALID_PRODUCT_ID_FORMATDo not retry; fix the product ID
PRODUCT_NOT_FOUNDCheck the ID and product type in Play Console; a just created product may still be propagating, so retry later, not in a loop
NO_ELIGIBLE_OFFERProduct exists but has no available base plan (subs) or purchase option (one time) for this user; hide it
UNKNOWNLog and hide

Retry the whole query with backoff only when the top level BillingResult is retriable (SERVICE_UNAVAILABLE, ERROR, NETWORK_ERROR, SERVICE_DISCONNECTED). Show the products you did fetch and log the rest.

Step 7 Handle disconnection

With enableAutoServiceReconnection(), PBL re-establishes the connection when you make an API call while disconnected. If a call still returns SERVICE_DISCONNECTED, the library could not reconnect; retry that operation (simple retry in session, backoff in the background). If you disabled auto reconnection, implement backoff yourself starting at one second and capping near fifteen seconds.

Check billingClient.isReady before issuing a call if you need a fast path. Always call endConnection() when the owning scope is destroyed.

Phase 4: Verify

Before you mark the integration done, confirm each of these:

CheckHow
Dependency present./gradlew :app:dependencies lists billing-ktx at the target version
Single client per processgrep -rn "BillingClient.newBuilder" src/ returns one call site
enablePendingPurchases calledBuild passes without IllegalArgumentException at first build()
Listener fires on purchaseRun a test purchase on the internal track; confirm OK branch hit
Connection ready before callsLog onBillingSetupFinished and confirm it precedes queries
Product query returns detailsLog productDetailsList.size for a known batch
Unfetched handling worksQuery a deliberately wrong product ID with the callback API and confirm it appears in unfetchedProductList with PRODUCT_NOT_FOUND (or INVALID_PRODUCT_ID_FORMAT) and is not retried
Disconnect recoveryForce stop the Play Store app while connected (adb shell am force-stop com.android.vending), confirm onBillingServiceDisconnected() fires, then make a billing call and confirm it succeeds without a manual startConnection(). Test NETWORK_ERROR separately in airplane mode
endConnection() on teardownLog it in the owning scope's destroy path

If any row fails, return to Phase 2 and revise the plan. Do not paper over a failing check.

References

  • Full chapter

  • Google Play Billing Library release notes and migration guides for version specific details.

Câu hỏi thường gặp

Kỹ năng AI Integrating Pbl làm được gì?

Use this skill when integrating the Google Play Billing Library client side (adding the dependency, wiring BillingClient, managing its connection lifecycle, and querying product details). Grounded in PBL 9.x.

Vì sao nên dùng Integrating Pbl trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Integrating Pbl là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Integrating Pbl trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/RevenueCat/play-billing-skills/tree/main/google-play/integrating-pbl. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Integrating Pbl?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Integrating Pbl với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Integrating Pbl với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Integrating Pbl có miễn phí không?

Có. Kỹ năng này được RevenueCat phát hành trên GitHub theo giấy phép Apache-2.0. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇