Package 

Class NativeBillingManager


  • 
    public final class NativeBillingManager
    
                        

    Orchestrates native Google Play Billing operations.

    This is the primary class that app developers interact with for:

    • Initiating purchases (subscriptions and in-app products)

    • Restoring purchases

    • Querying product details and prices

    • Managing entitlement state

    Internally delegates to:

    • BillingConnectionManager for connection lifecycle

    • ReceiptVerifier for server-side receipt verification

    • EntitlementCache for local entitlement persistence

    • PriceResolver for product price resolution

    Usage:

    val billing = NativeBillingManager(context, receiptVerifier, entitlementCache)
    billing.initialize()
    
    // Purchase
    val result = billing.purchase(activity, "premium_monthly")
    
    // Check entitlement
    val isPremium = billing.entitlementCache.hasActiveSubscription
    • Method Detail

      • isKnownSubscriptionProduct

         final Boolean isKnownSubscriptionProduct(String productId)

        Best-effort answer to "does productId auto-renew?" for the RevenueCat / Adapty forward paths.

        Those hosts drive the purchase through the provider's own SDK, so neither a Play Purchase nor a server-verified Entitlement is in scope when they call forwardPurchaseSuccess — yet they must obey the same rule as the native path, or every RC/Adapty customer keeps the exact hole this fix closes. Sources, in order:

        • the entitlement the server verified for this product (expiresAt != null — the same discriminator isSubscriptionPurchase uses),

        • the Play SUBS catalogue PriceResolver queried this session. Neither knows → false (a one-off). Hosts that DO know pass isSubscription explicitly to forwardPurchaseSuccess, which always wins over this inference.

      • initialize

         final Unit initialize()

        Initialize the billing system. Must be called before any billing operations. Typically called after AppDNA.configure() and onReady.

      • purchase

         final PurchaseResult purchase(Activity activity, String productId, PurchaseOptions options)

        Initiate a subscription or one-time-product purchase.

        SPEC-070-A A.27 — Queries both SUBS and INAPP product types in parallel, picks whichever Play returns details for, and launches the matching billing flow. Subscriptions take precedence to mirror iOS (Billing/NativeBillingManager.swift queries StoreKit which returns SUBS first).

        SPEC-070-A A.28 — When options.appAccountToken is supplied, plumbs it through BillingFlowParams.setObfuscatedAccountId so the receipt Play returns is correlatable with the host's user identity (and is reflected in Google Play Console as the obfuscated account ID for fraud / chargeback investigations).

        Parameters:
        activity - The Activity to launch the billing flow from.
        productId - The Google Play product ID to purchase.
        options - Optional purchase parameters (offer token, account token).
      • refreshEntitlementCache

         final Unit refreshEntitlementCache()

        SPEC-401 Fix 1D — silent entitlement-cache refresh.

        Same query path as restorePurchases (SUBS + INAPP via Play Billing queryPurchasesAsync) but skips the user-visible parts: no purchase_restored analytics events, no fireOnRestoreCompleted delegate callbacks. Designed for AppDNA.identify and host-driven post-auth refresh hooks where firing user-visible restore events would be wrong.

        Errors are swallowed and logged at warning level — callers must be able to chain without try/catch (identify is fire-and-forget). On failure the cache stays at whatever it was before; no state mutation.

      • getProducts

         final List<ProductInfo> getProducts(List<String> productIds)

        Get product information for a list of subscription product IDs.

        Parameters:
        productIds - The product IDs to query.
      • destroy

         final Unit destroy()

        Shut down the billing system and release all resources.