-
public final class NativeBillingManagerOrchestrates 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
-
-
Field Summary
Fields Modifier and Type Field Description private StringcurrentPaywallIdprivate StringcurrentExperimentId
-
Method Summary
Modifier and Type Method Description final StringgetCurrentPaywallId()Attribution context for the current purchase. final UnitsetCurrentPaywallId(String currentPaywallId)Attribution context for the current purchase. final StringgetCurrentExperimentId()final UnitsetCurrentExperimentId(String currentExperimentId)final BooleanisKnownSubscriptionProduct(String productId)Best-effort answer to "does productId auto-renew?" for the RevenueCat / Adapty forward paths. final Map<String, Object>purchaseEventProps(String productId, String provider)final Unitinitialize()Initialize the billing system. final PurchaseResultpurchase(Activity activity, String productId, PurchaseOptions options)Initiate a subscription or one-time-product purchase. final UnitrefreshEntitlementCache()SPEC-401 Fix 1D — silent entitlement-cache refresh. final List<Entitlement>restorePurchases()final List<ProductInfo>getProducts(List<String> productIds)Get product information for a list of subscription product IDs. final Unitdestroy()Shut down the billing system and release all resources. -
-
Method Detail
-
getCurrentPaywallId
final String getCurrentPaywallId()
Attribution context for the current purchase.
-
setCurrentPaywallId
final Unit setCurrentPaywallId(String currentPaywallId)
Attribution context for the current purchase.
-
getCurrentExperimentId
final String getCurrentExperimentId()
-
setCurrentExperimentId
final Unit setCurrentExperimentId(String currentExperimentId)
-
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
Purchasenor a server-verifiedEntitlementis in scope when they callforwardPurchaseSuccess— 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 passisSubscriptionexplicitly toforwardPurchaseSuccess, 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
SUBSandINAPPproduct types in parallel, picks whichever Play returns details for, and launches the matching billing flow. Subscriptions take precedence to mirror iOS (Billing/NativeBillingManager.swiftqueries StoreKit which returns SUBS first).SPEC-070-A A.28 — When options.appAccountToken is supplied, plumbs it through
BillingFlowParams.setObfuscatedAccountIdso 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: nopurchase_restoredanalytics events, nofireOnRestoreCompleteddelegate 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.
-
restorePurchases
final List<Entitlement> restorePurchases()
-
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.
-
-
-
-