Λογότυπο Backend Architecture

Backend Architecture

Οργανισμός
RevenueCat
backend-architecture

Use this skill when building a backend for Google Play Billing receipt verification. Covers receiving purchase tokens from the client, calling the Google Play Developer API to verify, storing subscription state, and exposing a production ready verification endpoint.

Επισκόπηση

ΕκδότηςRevenueCat
Αποθετήριοplay-billing-skills
Όνομα δεξιότηταςbackend-architecture
Αστέρια
58
Διακλαδώσεις
0
Συνοδευτικά αρχεία
Μόνο οδηγίες
Άδεια χρήσηςApache-2.0
Σύνδεσμοι
  • Οδηγίες σε Markdown

    Ένα αρχείο SKILL.md που το μοντέλο φορτώνει όταν χρειάζεται, ώστε να καταναλώνει token μόνο όταν ένα αίτημα είναι πράγματι σχετικό.

  • Λειτουργεί με οποιοδήποτε LLM

    Οι δεξιότητες AI είναι απλό Markdown, όχι κώδικας για συγκεκριμένο πάροχο, επομένως αυτή η δεξιότητα λειτουργεί με GPT, Claude, Gemini, Grok ή ένα τοπικό μοντέλο.

  • Αυτοτελής

    Όλα όσα χρειάζεται το μοντέλο περιλαμβάνονται στις οδηγίες — χωρίς επιπλέον αρχεία για συγχρονισμό.

  • Ανοιχτού κώδικα

    Δημοσιεύτηκε στο GitHub από τον λογαριασμό RevenueCat. Ελέγξτε τα αρχεία της δεξιότητας στο αποθετήριο πριν την εγκαταστήσετε.

Εγκατάσταση

Εγκαταστήστε τη δεξιότητα AI Backend Architecture στο TypingMind για να τη χρησιμοποιείτε με οποιοδήποτε LLM ή προσθέστε τη σε άλλον πράκτορα 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/backend-architecture
  4. Ενεργοποιήστε τη δεξιότητα σε κάθε συνομιλία όπου θέλετε να είναι διαθέσιμη.
Πρόσθετα → Δεξιότητες → Προσθήκη δεξιότητας → Από URL του GitHub, έπειτα επικολλήστε το URL του φακέλου και πατήστε «Συνέχεια».
2

Εγκατάσταση σε άλλον πράκτορα AI

Κάθε πράκτορας AI που υποστηρίζει τη μορφή 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/backend-architecture .claude/skills/backend-architecture
Επανεκκινήστε το Claude Code μετά την αντιγραφή, ώστε να εντοπίσει τη νέα δεξιότητα.

Χρησιμοποιήστε τη στο TypingMind

Ενεργοποιήστε τη δεξιότητα Backend Architecture σε οποιαδήποτε συνομιλία στο TypingMind και το μοντέλο αναλαμβάνει τα υπόλοιπα. Το όνομα και η περιγραφή της περιλαμβάνονται στην προτροπή συστήματος και, μόλις προκύψει ένα σχετικό αίτημα, το μοντέλο φορτώνει μόνο του τις πλήρεις οδηγίες — δεν χρειάζεται ποτέ να την καλείτε χειροκίνητα και δεν καταναλώνει token μέχρι να χρησιμοποιηθεί πραγματικά.

Το μοντέλο φορτώνει αυτόματα τη δεξιότητα Backend Architecture μόλις λάβει ένα σχετικό αίτημα.

Λειτουργεί με οποιοδήποτε μοντέλο AI

Οι δεξιότητες AI είναι οδηγίες σε απλό κείμενο Markdown και όχι κώδικας για συγκεκριμένο πάροχο, οπότε η δεξιότητα Backend Architecture δεν περιορίζεται στο μοντέλο για το οποίο γράφτηκε. Εγκαταστήστε τη μία φορά στο TypingMind και χρησιμοποιήστε τη με GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ή ένα τοπικό μοντέλο που εκτελείτε εσείς — πάντα με τα δικά σας κλειδιά API.

  • Φόρτωση μόνο όταν χρειάζεται

    Η προτροπή συστήματος περιλαμβάνει μόνο το όνομα και την περιγραφή. Οι οδηγίες ανακτώνται με το πρώτο σχετικό αίτημα, οπότε μια δεξιότητα που δεν χρησιμοποιείται δεν έχει κόστος.

  • Αλλάξτε μοντέλο κατά τη διάρκεια της συνομιλίας

    Επειδή η δεξιότητα αποτελείται από οδηγίες και όχι από κώδικα, η αλλαγή μοντέλου δεν επηρεάζει τη λειτουργία της — το επόμενο μοντέλο διαβάζει το ίδιο αρχείο SKILL.md.

Οδηγίες δεξιότητας

Αυτό είναι το περιεχόμενο του αρχείου SKILL.md που φορτώνει το μοντέλο. Διαβάστε το πριν από την εγκατάσταση — μια δεξιότητα αποτελείται από οδηγίες που θα ακολουθήσει το μοντέλο σας.

Backend Architecture for Play Billing

The client is not trustworthy. Client side signature checks can be patched out, APKs can be modified, and local purchase data can be faked or replayed. Your backend must treat the purchase token as an opaque value to verify with Google. This skill walks you through the verification pipeline, from receiving a token to persisting entitlement state.

Phase 1: Scope

Confirm the following before you write code.

  • You know which product types you sell (subscriptions, consumables, non consumables). The API endpoint differs per type.
  • You have a user identity model. Each purchase token must map to one user account on your server.
  • You have (or can add) a database for purchase records. The schema uses purchaseToken as the primary key.
  • You have a plan for acknowledgement within 3 days (prepaid plans shorter than one week: within half the plan duration). Unacknowledged purchases auto refund.
  • You have a Google Play Console account and can manage Users and permissions.

If any of these are missing, stop and resolve before continuing.

Phase 2: Plan

2.1 Configure Google Play Developer API access

Do these steps once per project.

  1. In Google Cloud Console, create or pick a project (linking it to Play Console is no longer required).
  2. In Cloud Console, enable the Google Play Android Developer API.
  3. Create a service account (for example play-billing-backend). No Cloud IAM roles are required.
  4. Generate a JSON key from the service account and store it as a secret. Never commit it.
  5. Back in Play Console, open Users and permissions, invite the service account email, and grant it View financial data, orders, and cancellation survey responses and Manage orders and subscriptions on your app.

For containerized deployments on Google Cloud, prefer Workload Identity Federation over JSON key files. GoogleCredentials.getApplicationDefault() picks up the attached service account automatically.

2.2 Map the seven step verification flow

Every purchase follows the same pipeline. Plan each step in code before wiring them.

  1. Receive purchase token from client.
  2. Call Google Play Developer API to fetch purchase state.
  3. Validate response fields (lineItems[].productId or productId against the claimed product). The package is bound by the packageName in the request path, so a token from another app is rejected by the API.
  4. Check purchase state is active or purchased.
  5. Check the token is not already processed (idempotency).
  6. Persist record and grant entitlement.
  7. Acknowledge the purchase with Google.

2.3 Pick your database key

Use purchaseToken as the primary key for purchase records.

IdentifierUse it as key?Reason
purchaseTokenYesWhat the Developer API accepts. Stable across subscription renewals.
orderIdNo (store only)Changes every renewal (appended ..0, ..1). Useful for support and reconciliation.
linkedPurchaseTokenNo (foreign key)Points to the previous token in an upgrade or downgrade chain.

Phase 3: Execute

3.1 Build the authenticated Play Publisher client

Initialize once at startup. The client is thread safe and caches access tokens internally.

kotlin
fun createPublisherClient(): AndroidPublisher {
    val credentials = GoogleCredentials
        .getApplicationDefault()
        .createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER))
    val transport = GoogleNetHttpTransport.newTrustedTransport()
    return AndroidPublisher.Builder(
        transport,
        GsonFactory.getDefaultInstance(),
        HttpCredentialsAdapter(credentials),
    ).setApplicationName("your-app-backend").build()
}

3.2 Expose the verification endpoint

The client posts the purchase token, product ID, and user ID. Your endpoint runs the full pipeline and returns a final entitlement decision.

kotlin
@PostMapping("/purchases/verify")
fun verify(@RequestBody req: VerifyRequest): VerifyResponse {
    val sub = publisher.purchases().subscriptionsv2()
        .get(packageName, req.purchaseToken).execute()
    validateOrThrow(sub, req.productId)
    requireEntitled(sub)
    return processPurchase(req.userId, req.purchaseToken, sub)
}

3.3 Call the Developer API for subscriptions

purchases.subscriptionsv2.get is the source of truth for subscription state.

kotlin
fun getSubscription(packageName: String, token: String): SubscriptionPurchaseV2 =
    publisher.purchases().subscriptionsv2().get(packageName, token).execute()

Fields to read from the response:

FieldPurpose
subscriptionStateActive, canceled, in grace period, on hold, paused, expired, pending, or pending purchase canceled.
lineItems[].productIdProduct sold. Must match what the client claimed.
lineItems[].expiryTimeCurrent period end.
linkedPurchaseTokenPrevious token in upgrade or downgrade chain.
acknowledgementStateWhether you have acknowledged yet.
externalAccountIdentifiersObfuscated account and profile IDs from the purchase flow.

Grant (or keep) the entitlement when subscriptionState is SUBSCRIPTION_STATE_ACTIVE or SUBSCRIPTION_STATE_IN_GRACE_PERIOD, or is SUBSCRIPTION_STATE_CANCELED while lineItems[].expiryTime is still in the future (requireEntitled(sub) in 3.2 implements this rule). Do not grant on SUBSCRIPTION_STATE_PENDING, SUBSCRIPTION_STATE_ON_HOLD, SUBSCRIPTION_STATE_PAUSED, SUBSCRIPTION_STATE_EXPIRED, or SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED.

3.4 Call the Developer API for one time products

purchases.products.get requires the product ID in the path.

kotlin
fun getProduct(packageName: String, productId: String, token: String): ProductPurchase =
    publisher.purchases().products().get(packageName, productId, token).execute()
FieldMeaning
purchaseState0 purchased, 1 canceled, 2 pending. Grant only on 0.
consumptionState0 not consumed, 1 consumed.
acknowledgementState0 not acknowledged, 1 acknowledged.
orderIdStore for support and reconciliation.

3.5 Persist the record with idempotency

Use the purchase token as the primary key. Check for duplicates before granting.

kotlin
data class PurchaseRecord(
    val purchaseToken: String,
    val userId: String,
    val productId: String,
    val orderId: String?,
    val purchaseState: String,
    val linkedPurchaseToken: String?,
    val acknowledgedAt: Instant?,
    val grantedAt: Instant,
)
kotlin
fun processPurchase(userId: String, token: String, sub: SubscriptionPurchaseV2) {
    sub.linkedPurchaseToken?.let { purchaseRepository.deactivate(it) }
    if (purchaseRepository.findByToken(token) != null) return
    purchaseRepository.save(recordFrom(userId, token, sub))
    entitlementService.activate(userId, sub.lineItems.first().productId)
}

Deactivating the linked token prevents two active entitlements after an upgrade or downgrade.

3.6 Acknowledge within 3 days (half the plan duration for short prepaid plans)

Acknowledge from the backend after the entitlement is granted. If acknowledgement fails, retry with backoff. A top up on a prepaid plan is a new token that must also be acknowledged in time, or Google revokes the top up and the remaining subscription and refunds the user.

kotlin
fun acknowledgeSubscription(packageName: String, productId: String, token: String) {
    publisher.purchases().subscriptions()
        .acknowledge(packageName, productId, token, SubscriptionPurchasesAcknowledgeRequest())
        .execute()
}

For one time products, pick the call that matches the product type.

Product typeAPI callNotes
Non consumablepurchases.products.acknowledgeGrants permanent ownership.
Consumablepurchases.products.consumeAlso acknowledges. Do not call both.
Subscriptionpurchases.subscriptions.acknowledgeRenewals are already acknowledged.

3.7 Retry transient errors

Back off on 429 and 503. Respect Retry-After when present.

kotlin
fun <T> executeWithRetry(maxAttempts: Int = 3, block: () -> T): T {
    repeat(maxAttempts) { attempt ->
        try { return block() } catch (e: GoogleJsonResponseException) {
            if (e.statusCode !in listOf(429, 503)) throw e
            Thread.sleep((1L shl attempt) * 1000L)
        }
    }
    throw RuntimeException("Retries exhausted")
}

3.8 Stay inside your quota

Quota is per minute and per bucket: by default 3,000 queries per minute for each bucket. subscriptionsv2.get counts against the Subscriptions bucket and products.get against the One-time Purchases bucket, independently. Apply all four practices.

  • Cache verification results for 5 to 15 minutes keyed by token.
  • Use Real Time Developer Notifications through Pub Sub for state changes instead of polling.
  • Serve entitlement checks from your database. Do not call Google on every app launch.
  • Monitor quota in Cloud Console and alert at 80 percent.

Phase 4: Verify

Before you call the backend done, confirm:

  • A purchase token posted twice results in exactly one entitlement grant (idempotency).
  • An upgrade produces a new token whose linkedPurchaseToken deactivates the old entitlement.
  • A pending purchase with purchaseState == 2 is stored but not granted until it transitions to 0.
  • Acknowledgement happens after the grant and within 3 days. Simulate a missed acknowledgement and confirm the auto refund.
  • A Play Store resubscription after the old subscription expired arrives only as a SUBSCRIPTION_PURCHASED RTDN with a new token and no linkedPurchaseToken. Map it to the user with outOfAppPurchaseContext.expiredExternalAccountIdentifiers or outOfAppPurchaseContext.expiredPurchaseToken from subscriptionsv2.get, then acknowledge it from the backend within 3 days (optionally passing externalAccountIds in the acknowledge body). A resubscription before expiry sets linkedPurchaseToken.
  • The service account JSON key is not in git, not in logs, and rotates on a schedule.
  • Load tests do not push any per minute quota bucket above 80 percent.

References

Συχνές ερωτήσεις

Τι κάνει η δεξιότητα AI Backend Architecture;

Use this skill when building a backend for Google Play Billing receipt verification. Covers receiving purchase tokens from the client, calling the Google Play Developer API to verify, storing subscription state, and exposing a production ready verification endpoint.

Γιατί να χρησιμοποιήσετε τη δεξιότητα Backend Architecture στο TypingMind;

Επειδή την εγκαθιστάτε μία φορά και τη χρησιμοποιείτε με οποιοδήποτε μοντέλο. Η Backend Architecture είναι απλό Markdown και όχι κώδικας ειδικά για κάποιον πάροχο, επομένως η ίδια δεξιότητα λειτουργεί με GPT-5, Claude, Gemini, Grok ή ένα τοπικό μοντέλο — και μπορείτε να αλλάξετε μοντέλο κατά τη διάρκεια της συνομιλίας χωρίς να διακοπεί η λειτουργία της. Το TypingMind λειτουργεί με τα δικά σας κλειδιά API, οπότε πληρώνετε απευθείας τους παρόχους αντί για συνδρομή ανά θέση χρήστη, ενώ οι δεξιότητες και οι συνομιλίες σας παραμένουν στον δικό σας χώρο αποθήκευσης.

Πώς εγκαθιστώ τη δεξιότητα Backend Architecture στο TypingMind;

Στο TypingMind, ανοίξτε Πρόσθετα → Δεξιότητες → Εγκατάσταση από το GitHub και επικολλήστε τη διεύθυνση https://github.com/RevenueCat/play-billing-skills/tree/main/google-play/backend-architecture. Το TypingMind διαβάζει το αρχείο SKILL.md και εγκαθιστά τη δεξιότητα, την οποία μπορείτε να ενεργοποιείτε ανά συνομιλία.

Ποια μοντέλα AI μπορούν να χρησιμοποιήσουν τη δεξιότητα Backend Architecture;

Οποιοδήποτε μοντέλο συνδέετε στο TypingMind. Οι δεξιότητες AI είναι απλές οδηγίες Markdown και όχι κώδικας ειδικά για κάποιον πάροχο, επομένως τα GPT, Claude, Gemini, Grok και τα τοπικά μοντέλα μπορούν όλα να φορτώσουν αυτή τη δεξιότητα όταν ένα αίτημα αντιστοιχεί σε αυτή.

Με πόσα μοντέλα AI μπορώ να χρησιμοποιήσω τη δεξιότητα Backend Architecture;

Με όσα θέλετε. Στο TypingMind μπορείτε να χρησιμοποιήσετε τη δεξιότητα Backend Architecture με οποιοδήποτε μοντέλο υποστηρίζει δεξιότητες, όπως τα GPT, Claude, Gemini, Grok, DeepSeek, Mistral και Llama, χρησιμοποιώντας τα δικά σας κλειδιά API.

Είναι δωρεάν η δεξιότητα AI Backend Architecture;

Ναι. Δημοσιεύεται στο GitHub από τον λογαριασμό RevenueCat με την άδεια χρήσης Apache-2.0. Πληρώνετε μόνο τον δικό σας πάροχο AI για τα token που χρησιμοποιείτε.

Τι είναι οι δεξιότητες AI;

Μια δεξιότητα AI είναι ένα επαναχρησιμοποιήσιμο πακέτο οδηγιών που διδάσκει σε ένα μοντέλο AI πώς να εκτελεί μια συγκεκριμένη εργασία. Ακολουθεί την ανοιχτή μορφή Agent Skills: ένα αρχείο SKILL.md με όνομα και περιγραφή, μαζί με τυχόν σενάρια κώδικα, πρότυπα ή αρχεία αναφοράς που μπορεί να χρειαστεί το μοντέλο. Το μοντέλο διαβάζει τις οδηγίες μόνο όταν το αίτημά σας αντιστοιχεί στη δεξιότητα, οπότε μια εγκατεστημένη δεξιότητα δεν κοστίζει τίποτα μέχρι να χρησιμοποιηθεί.

Σε τι διαφέρουν οι δεξιότητες AI από τα πρόσθετα ή τους συνδέσμους MCP;

Ένα πρόσθετο ή ένας σύνδεσμος MCP παρέχει στο μοντέλο νέα εργαλεία που μπορεί να καλέσει — κώδικα που εκτελείται κάπου και επιστρέφει ένα αποτέλεσμα. Μια δεξιότητα AI παρέχει αντί γι’ αυτό γνώσεις και διαδικασίες στο μοντέλο: πώς να προσεγγίσει μια εργασία, ποια βήματα να ακολουθήσει και ποια χαρακτηριστικά έχει ένα καλό αποτέλεσμα. Οι δεξιότητες είναι απλό Markdown, επομένως δεν χρειάζονται διακομιστή, κλειδί API ή περιβάλλον εκτέλεσης και λειτουργούν με οποιοδήποτε μοντέλο.

Προβολή όλων

Δημιουργήστε τώρα τον δικό σας χώρο εργασίας AI

Εγγραφείτε στο ενημερωτικό μας δελτίο για να ενημερώνεστε για νέες λειτουργίες και μελλοντικές κληρώσεις δώρων 👇