Back to Docs

b4xlib API Reference

Complete method and property reference for B4XPurchaseManager.

Initialize
MethodParametersReturnsDescription
InitializeParent, BillingKey, AppId, ApiKeyInitialize the library. BillingKey is your Google Play license key (pass "" for iOS). AppId and ApiKey from the dashboard.
IsInitializedBooleanReturns 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.
Product Management
MethodParametersReturnsDescription
AddProductProductId, Title, DescriptionAdd a non-consumable product for in-app purchase.
AddConsumableProductProductId, Title, DescriptionAdd a consumable product (can be purchased multiple times).
ClearProductsRemove all configured products.
AddSubscriptionProductId, BasePlanId, Title, Description, BillingPeriodAdd a subscription. BasePlanId is Android-only (pass "" for iOS).
ClearSubscriptionsRemove all configured subscriptions.
UI Customization
MethodParametersReturnsDescription
SetThemeColorsPrimary As Int, Secondary As Int, Accent As Int, Background1 As Int, Background2 As IntSet 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, DescriptionAdd a feature card to purchase/subscription screens.
ClearFeaturesRemove all configured features.
Purchase Flow
MethodParametersReturnsDescription
ShowInAppPurchaseBooleanShow the in-app purchase screen. Returns True if purchase was successful.
ShowSubscriptionPurchaseBooleanShow 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.
RestorePurchasesBooleanRestore previous in-app purchases from the store.
RestoreSubscriptionsBooleanRestore previous subscriptions from the store.
HidePurchaseScreenProgrammatically close any active purchase/subscription screen.
Status
MethodParametersReturnsDescription
CheckStatusLoad cached status and trigger background validation if cache is expired. Instant, non-blocking. Call on page appear.
ValidateNowBooleanForce immediate live validation (bypasses cache). 1 credit per call.
IsUnlockedBooleanTrue if user owns a non-consumable product (cached, instant).
IsSubscriptionActiveBooleanTrue if user has a valid subscription (cached, instant).
GetActiveSubscriptionIdStringActive subscription product ID, or "" if none.
GetSubscriptionExpiryDateLongSubscription expiry date in ticks, or 0 if not available.
IsActiveBooleanTrue if a purchase/subscription screen is currently showing.
ValidationInProgressBooleanTrue if a live backend validation is currently running.
Consumables
MethodParametersReturnsDescription
GetConsumableCountIntCurrent consumable count (locally tracked on-device only — consider syncing with your own server for cross-device support).
AddConsumablesCountAdd consumables after a successful purchase.
SetConsumableCountCountSet 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
ShowPrivacyPolicyShow privacy policy in a full-screen overlay. Uses custom content if set, otherwise built-in template.
ShowTermsOfServiceShow 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
ExportPrivacyPolicyInappBooleanExport rendered privacy policy (in-app). Logs HTML to IDE log and saves as bpm-privacy-policy-inapp.html.
ExportPrivacyPolicySubscriptionBooleanExport rendered privacy policy (subscription). Logs HTML to IDE log and saves as bpm-privacy-policy-subscription.html.
ExportTermsOfServiceBooleanExport 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).