b4xlib API Reference
Complete method and property reference for B4XPurchaseManager.
Initialize
| Method | Parameters | Returns | Description |
|---|---|---|---|
| Initialize | Parent, BillingKey, AppId, ApiKey | — | Initialize the library. BillingKey is your Google Play license key (pass "" for iOS). AppId and ApiKey from the dashboard. |
| IsInitialized | — | Boolean | Returns True if Initialize has been called successfully. |
Display Properties
| Property | Type | Default | Description |
|---|---|---|---|
| DisplayAppName | String | "" | Overrides the app name on purchase/subscription screens. Defaults to the app's own name if empty. |
| DisplayTagline | String | "Unlock the Full Experience" | Tagline displayed below the app name. |
| DarkMode | Boolean | False | Set to True for dark theme on all screens and overlays. |
Privacy & Legal Properties
| Property | Type | Default | Description |
|---|---|---|---|
| PolicyCompanyName | String | "" | Company name for privacy policy and terms templates. Recommended for subscriptions. |
| PolicyEmailAddress | String | "" | Contact email for privacy policy and terms templates. |
| PolicyEffectiveDate | String | "" | Effective date for legal documents (e.g., "January 1, 2025"). Defaults to today. |
| CustomPrivacyPolicyInapp | String | "" | Custom privacy policy for in-app purchases. URL or raw HTML. Empty = built-in template. |
| CustomPrivacyPolicySubscription | String | "" | Custom privacy policy for subscriptions. URL or raw HTML. Empty = built-in template. |
| CustomTermsOfService | String | "" | Custom terms of service. URL or raw HTML. Empty = built-in template. |
Development
| Property | Type | Default | Description |
|---|---|---|---|
| DebugValidation | Boolean | False | Uses faster revalidation intervals (minutes instead of hours) for development. Ignored in release builds. |
Product Management
| Method | Parameters | Returns | Description |
|---|---|---|---|
| AddProduct | ProductId, Title, Description | — | Add a non-consumable product for in-app purchase. |
| AddConsumableProduct | ProductId, Title, Description | — | Add a consumable product (can be purchased multiple times). |
| ClearProducts | — | — | Remove all configured products. |
| AddSubscription | ProductId, BasePlanId, Title, Description, BillingPeriod | — | Add a subscription. BasePlanId is Android-only (pass "" for iOS). |
| ClearSubscriptions | — | — | Remove all configured subscriptions. |
UI Customization
| Method | Parameters | Returns | Description |
|---|---|---|---|
| SetThemeColors | Primary 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. |
| AddFeature | Emoji, Title, Description | — | Add a feature card to purchase/subscription screens. |
| ClearFeatures | — | — | Remove all configured features. |
Purchase Flow
| Method | Parameters | Returns | Description |
|---|---|---|---|
| ShowInAppPurchase | — | Boolean | Show the in-app purchase screen. Returns True if purchase was successful. |
| ShowSubscriptionPurchase | — | Boolean | Show the subscription screen. Returns True if subscription was successful. |
| PurchaseProduct | ProductId | Boolean | Purchase a product directly without showing the purchase screen. For custom UI. |
| PurchaseSubscription | ProductId, BasePlanId | Boolean | Purchase a subscription directly without showing the subscription screen. For custom UI. |
| RestorePurchases | — | Boolean | Restore previous in-app purchases from the store. |
| RestoreSubscriptions | — | Boolean | Restore previous subscriptions from the store. |
| HidePurchaseScreen | — | — | Programmatically close any active purchase/subscription screen. |
Status
| Method | Parameters | Returns | Description |
|---|---|---|---|
| CheckStatus | — | — | Load cached status and trigger background validation if cache is expired. Instant, non-blocking. Call on page appear. |
| ValidateNow | — | Boolean | Force immediate live validation (bypasses cache). 1 credit per call. |
| IsUnlocked | — | Boolean | True if user owns a non-consumable product (cached, instant). |
| IsSubscriptionActive | — | Boolean | True if user has a valid subscription (cached, instant). |
| GetActiveSubscriptionId | — | String | Active subscription product ID, or "" if none. |
| GetSubscriptionExpiryDate | — | Long | Subscription expiry date in ticks, or 0 if not available. |
| IsActive | — | Boolean | True if a purchase/subscription screen is currently showing. |
| ValidationInProgress | — | Boolean | True if a live backend validation is currently running. |
Consumables
| Method | Parameters | Returns | Description |
|---|---|---|---|
| GetConsumableCount | — | Int | Current consumable count (locally tracked on-device only — consider syncing with your own server for cross-device support). |
| AddConsumables | Count | — | Add consumables after a successful purchase. |
| SetConsumableCount | Count | — | Set consumable count directly. Use on app launch to sync local count with your server's authoritative count. |
| UseConsumables | Count | Boolean | Deduct consumables. Returns True if enough available, False otherwise. |
Privacy & Terms
| Method | Parameters | Returns | Description |
|---|---|---|---|
| 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 OnlyDisabled 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.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| ExportPrivacyPolicyInapp | — | Boolean | Export rendered privacy policy (in-app). Logs HTML to IDE log and saves as bpm-privacy-policy-inapp.html. |
| ExportPrivacyPolicySubscription | — | Boolean | Export rendered privacy policy (subscription). Logs HTML to IDE log and saves as bpm-privacy-policy-subscription.html. |
| ExportTermsOfService | — | Boolean | Export rendered terms of service. Logs HTML to IDE log and saves as bpm-terms-of-service.html. |
Testing
Development Only| Method | Parameters | Returns | Description |
|---|---|---|---|
| ResetPurchaseForTesting | ProductId | Boolean | Android: consumes purchase token. iOS: clears local cache. |
| ResetSubscriptionForTesting | ProductId | Boolean | Android: consumes subscription token. iOS: not supported (returns False). |