Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

rc-purchase-flow

/rc-purchase-flow

Wdraża zakup RevenueCat na Androidzie: awaitPurchase, obsługę wyjątków, odczyt uprawnień i przywracanie zakupów.

Repozytorium
ai-toolkit ↗
Licencja
MIT
Ostatnia zmiana repozytorium
11.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
2
Przestarzałość

Brak sygnałów. Repozytorium zmienione 11.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Wdraża zakup RevenueCat na Androidzie: awaitPurchase, obsługę wyjątków, odczyt uprawnień i przywracanie zakupów.

Oryginalny opis (EN)

Use this skill when implementing a RevenueCat purchase on Android. Covers awaitPurchase, PurchasesTransactionException, reading CustomerInfo entitlements to grant access, restoring purchases, and the six SDK managed steps that happen inside a single call.

Jak działa

  1. Phase 1: Understand what awaitPurchase() does
  2. Phase 2: Prepare the package
  3. Phase 3: Execute the purchase
  4. Phase 4: Inspect StoreTransaction only if you need it
  5. Phase 5: Restore on reinstall or device switch
  6. Exception types at a glance
  7. References
Sekcje z nagłówków SKILL.md, w oryginale · 116 linii, 648 słów
Podgląd SKILL.md
---
name: rc-purchase-flow
description: Use this skill when implementing a RevenueCat purchase on Android. Covers awaitPurchase, PurchasesTransactionException, reading CustomerInfo entitlements to grant access, restoring purchases, and the six SDK managed steps that happen inside a single call.
license: Apache-2.0; see LICENSE
metadata:
  author: RevenueCat
  source: revenuecat-handbook chapter 6
  keywords:
  - android
  - revenuecat
  - purchase-flow
  - awaitpurchase
  - purchases-transaction-exception
  - customerinfo
  - entitlements
---

# Purchase Flow

A RevenueCat purchase on Android is two lines of code. The SDK handles the billing params, the Play sheet, the purchase token round trip, server side verification, and acknowledgment. You decide which package to pass in and what to do with the returned entitlements.

## Phase 1: Understand what awaitPurchase() does

One call to `Purchases.sharedInstance.awaitPurchase(params)` runs six steps under the hood. You do not write any of this.

| Step | What happens |
|------|--------------|
| 1 | Builds `BillingFlowParams` with the correct `ProductDetailsParams` from your `Package` |
| 2 | Calls `BillingClient.launchBillingFlow()` against the activity you passed |
| 3 | Suspends until the `PurchasesUpdatedListener` result arrives |
| 4 | If `OK`, posts the Play purchase token to the RevenueCat backend |
| 5 | Backend verifies via `purchases.subscriptionsv2.get` or `purchases.products.get` |
| 6 | SDK acknowledges (subs or non-consumables) or consumes (consumables) within the 3 day Google window |

The call returns `PurchaseResult(storeTransaction, customerInfo)`. Retriable failures are retried automatically.

See the [Purchase Flow chapter on revenuecat.com](https://www.revenuecat.com/guides/revenuecat-android-sdk/the-purchase-flow) for the six-step diagram and the full picture.

## Phase 2: Prepare the package

You need a `Package` from offerings before you can purchase. Fetch offerings, let your UI pick one, and hold the activity.

```kotlin
val offerings = Purchases.sharedInstance.awaitOfferings()
val pkg = offerings.current?.monthly ?: return
```

If you need a specific offer instead of the default, resolve a `SubscriptionOption` and pass that to `PurchaseParams.Builder` instead of the package.

```kotlin
val option = pkg.product.subscriptionOptions
    ?.firstOrNull { it.tags.contains("promo_50_off") }
    ?: pkg.product.defaultOption
    ?: return
```

For EU personalized pricing, chain `.isPersonalizedPrice(true)` on the builder so Play shows the customized price notice.

## Phase 3: Execute the purchase

Build the params, await the purchase, read `customerInfo` to gate access, and handle the two expected error branches.

```kotlin
try {
    val result = Purchases.sharedInstance.awaitPurchase(
        PurchaseParams.Builder(activity, pkg).build()
    )
    val customerInfo = result.customerInfo
    if (customerInfo.entitlements["pro"]?.isActive == true) {
        navigateToApp()
    }
} catch (e: PurchasesTransactionException) {
    when {
        e.userCancelled -> { /* backed out, do nothing */ }
        e.error.code == PurchasesErrorCode.ProductAlreadyPurchasedError ->
            showMessage("You already have this subscription")
        else -> showError(userFacingMessage(e.error)) // log e.error.message; mapping in rc-error-handling
    }
}
```

Rules for this block:

- `PurchaseResult` is `@Poko`. Access fields as `result.customerInfo` and `result.storeTransaction`. Do not destructure with `val (transaction, customerInfo) = result`.
- `customerInfo.entitlements["<id>"]?.isActive == true` is the gate. Do not check `storeTransaction` to decide access.
- `PurchasesTransactionException` is the only exception type thrown by `awaitPurchase`. Catch it, branch on `userCancelled` first, then on `e.error.code`.
- User cancellation is not an error to surface. Swallow it.

If you prefer callbacks over coroutines, `purchaseWith(params, onError, onSuccess)` is the equivalent entry point.

## Phase 4: Inspect StoreTransaction only if you need it

`result.storeTransaction` is available but usually unused. `customerInfo` is the source of truth for entitlements. If you need transaction level data for logging or your own backend:

| Field | Type | Notes |
|-------|------|-------|
| `orderId` | `String?` | Null for restored purchases |
| `purchaseToken` | `String` | Raw Play purchase token |
| `productIds` | `List<String>` | Product IDs in the transaction |
| `purchaseTime` | `Long` | Epoch millis |
| `type` | `ProductType` | `SUBS` or `INAPP` |

## Phase 5: Restore on reinstall or device switch

Restore runs `queryPurchasesAsync()`, posts everything found to RevenueCat, and returns the fresh `CustomerInfo`. Gate access the same way you do after a purchase.

```kotlin
try {
    val customerInfo = Purchases.sharedInstance.awaitRestore()
    if (customerInfo.entitlements["pro"]?.isActive == true) {
        navigateToApp()
    } else {
        showMessage("No active purchases found")
    }
} catch (e: PurchasesException) {
    showError(userFacingMessage(e.error)) // log e.error.message
}
```

Note the exception type. `awaitRestore()` throws `PurchasesException`, not `PurchasesTransactionException`. There is no `userCancelled` flag to check because no billing sheet is shown.

## Exception types at a glance

| Call | Thrown exception | Has `userCancelled`? |
|------|------------------|----------------------|
| `awaitPurchase(params)` | `PurchasesTransactionException` | Yes |
| `awaitRestore()` | `PurchasesException` | No |

## References

- [Full chapter](https://www.revenuecat.com/guides/revenuecat-android-sdk/the-purchase-flow)

Wersje

W bazie nie ma innych skilli o nazwie rc-purchase-flow.

Migawka bazy z 13.11.2026 · wersja paczki 8b56b4265e3f (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 90revenuecat-testing
    Pomaga testować zakupy i subskrypcje RevenueCat, konfigurować sandbox, debugować zakup, przywracanie i okres próbny, weryfikować uprawnienia i zdarzenia oraz pisać plan QA dla zakupów w aplikacji.
  • 90revenuecat-purchase-flow
    Wdraża logikę zakupu i przywracania subskrypcji w RevenueCat: pobieranie ofert, obsługę błędów i anulowania.
  • 90revenuecat-purchase-flow
    Implementuje w RevenueCat przepływ zakupu i przywracania zakupów: pobieranie ofert, kupno pakietu, obsługę błędów i anulowania, także dla własnego paywalla.
  • 100rc-one-time-products
    Sprzedaje produkty jednorazowe na Androidzie przez RevenueCat: pobiera oferty, wykonuje zakup i polega na SDK przy potwierdzaniu.
  • 100integrate-revenuecat
    Konfiguruje RevenueCat po stronie panelu i instaluje SDK Purchases w aplikacji, dodając subskrypcje i zakupy w aplikacji.
  • 90mobile-in-app-purchase
    Pomaga wdrażać zakupy w aplikacji: konfigurację produktów, subskrypcje, walidację paragonów i przywracanie zakupów.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.