Back to Docs

b4xlib API Reference

Complete method and property reference for B4XPurchaseManager.

Initialize
MethodParametersReturnsDescription
InitializeParent, BillingKey, AppId, ApiKey—Initialize the library. BillingKey is your Google Play license key (ignored on iOS). AppId is your app identifier from the BPM dashboard (not your package name). ApiKey is required (starts with "bpm_").
IsInitialized—BooleanReturns True if Initialize has been called successfully.
Display Properties
PropertyTypeDefaultDescription
DisplayAppNameString""Overrides the app name on purchase/subscription screens. Defaults to the app's own name if empty.
DisplayTaglineString"Unlock the Full Experience"Tagline displayed below the app name.
DarkModeBooleanFalseSet to True for dark theme on all screens and overlays.
Privacy & Legal Properties
PropertyTypeDefaultDescription
PolicyCompanyNameString""Company name for privacy policy and terms templates. Recommended for subscriptions.
PolicyEmailAddressString""Contact email for privacy policy and terms templates.
PolicyEffectiveDateString""Effective date for legal documents (e.g., "January 1, 2025"). Defaults to today.
CustomPrivacyPolicyInappString""Custom privacy policy for in-app purchases. URL or raw HTML. Empty = built-in template.
CustomPrivacyPolicySubscriptionString""Custom privacy policy for subscriptions. URL or raw HTML. Empty = built-in template.
CustomTermsOfServiceString""Custom terms of service. URL or raw HTML. Empty = built-in template.
Development
PropertyTypeDefaultDescription
DebugValidationBooleanFalseUses faster revalidation intervals (minutes instead of hours) for development. Ignored in release builds.
AdvancedDebugModeBooleanFalseVerbose on-device product-fetch diagnostics for "products not showing" — logs the product IDs requested and what the store returned (id, price, title, description), plus a platform-specific checklist. Talks directly to the store (no backend, no credits). Leave off for production.
AutoInappValidationBooleanFalseIn-app purchases re-validate only for the first 21 days (the refund window) by default, then automatic checks stop — you re-validate on demand with ValidateNow. Set True to keep auto-validating every 14 days instead. Subscriptions are unaffected.
Product Management
MethodParametersReturnsDescription
AddProductProductId, Title, Description—Add a non-consumable product for in-app purchase.
AddConsumableProductProductId, Title, Description, Quantity—Add a consumable product. Quantity defines how many consumables are automatically awarded per purchase.
ClearProducts——Remove all configured products.
AddSubscriptionProductId, BasePlanId, Title, Description, BillingPeriod—Add a subscription. BasePlanId must match Google Play Console (ignored on iOS).
ClearSubscriptions——Remove all configured subscriptions.
UI Customization
MethodParametersReturnsDescription
SetThemeColorsPrimary As Int, Secondary As Int, Accent As Int, Background1 As Int, Background2 As Int—Set theme colors for purchase/subscription screens. Pass 0 for any color to use defaults. Accepts 0xFFRRGGBB hex literals, xui.Color_RGB(), Colors.Red, etc.
AddFeatureEmoji, Title, Description—Add a feature card to purchase/subscription screens.
ClearFeatures——Remove all configured features.
Purchase Flow
MethodParametersReturnsDescription
ShowInAppPurchase—BooleanShow the in-app purchase screen. Returns True if purchase was successful.
ShowSubscriptionPurchase—BooleanShow the subscription screen. Returns True if subscription was successful.
PurchaseProductProductIdBooleanPurchase a product directly without showing the purchase screen. For custom UI.
PurchaseSubscriptionProductId, BasePlanIdBooleanPurchase a subscription directly without showing the subscription screen. For custom UI.
RestorePurchases—BooleanRestore previous in-app purchases from the store.
RestoreSubscriptions—BooleanRestore previous subscriptions from the store.
HidePurchaseScreen——Programmatically close any active purchase/subscription screen.
Status
MethodParametersReturnsDescription
CheckStatus——Load cached status and trigger background validation if cache is expired. Instant, non-blocking. Call on page appear.
ValidateNow—BooleanForce immediate live validation (bypasses cache). Costs 1 credit per configured type.
IsUnlocked—BooleanTrue if user owns a non-consumable product (cached, instant).
IsSubscriptionActive—BooleanTrue if user has a valid subscription (cached, instant).
GetActiveSubscriptionId—StringActive subscription product ID, or "" if none.
GetSubscriptionExpiryDate—LongSubscription expiry date in ticks, or 0 if not available.
IsActive—BooleanTrue if a purchase/subscription screen is currently showing.
ValidationInProgress—BooleanTrue if a live backend validation is currently running.
Consumables
MethodParametersReturnsDescription
GetConsumableCount—IntCurrent consumable count (locally tracked on-device only — consider syncing with your own server for cross-device support).
AddConsumablesCount—Add consumables after a successful purchase.
SetConsumableCountCount—Set consumable count directly. Use on app launch to sync local count with your server's authoritative count.
UseConsumablesCountBooleanDeduct consumables. Returns True if enough available, False otherwise.
Privacy & Terms
MethodParametersReturnsDescription
ShowPrivacyPolicy——Show privacy policy in a full-screen overlay. Uses custom content if set, otherwise built-in template.
ShowTermsOfService——Show terms of service in a full-screen overlay. Uses custom content if set, otherwise built-in template.
Export
Debug Only

Disabled in release builds. Exported HTML is logged directly to the B4X IDE log as a single copyable line (framed by purple markers), and also saved to a device directory. Right-click the HTML line in the IDE log → Copy Line → paste into your editor or LLM for customization.

MethodParametersReturnsDescription
ExportPrivacyPolicyInapp—BooleanExport rendered privacy policy (in-app). Logs HTML to IDE log and saves as bpm-privacy-policy-inapp.html.
ExportPrivacyPolicySubscription—BooleanExport rendered privacy policy (subscription). Logs HTML to IDE log and saves as bpm-privacy-policy-subscription.html.
ExportTermsOfService—BooleanExport rendered terms of service. Logs HTML to IDE log and saves as bpm-terms-of-service.html.
Testing
Development Only
MethodParametersReturnsDescription
ResetPurchaseForTestingProductIdBooleanAndroid: consumes purchase token. iOS: clears local cache.
ResetSubscriptionForTestingProductIdBooleanAndroid: consumes subscription token. iOS: not supported (returns False).