-
public final class OpenIapStoreOpenIapStore (Android) Convenience store that wraps an OpenIapProtocol implementation (Play, Horizon, or Amazon) and exposes suspend APIs with observable StateFlows for UI layers to consume.
-
-
Field Summary
Fields Modifier and Type Field Description private final StateFlow<Boolean>isConnectedprivate final StateFlow<List<Product>>productsprivate final StateFlow<List<ProductSubscription>>subscriptionsprivate final StateFlow<List<Purchase>>availablePurchasesprivate final StateFlow<Purchase>currentPurchaseprivate final StateFlow<IapStatus>statusprivate final SuspendFunction1<InitConnectionConfig, Boolean>initConnectionprivate final SuspendFunction0<Boolean>endConnectionprivate final SuspendFunction1<ProductRequest, FetchProductsResult>fetchProductsprivate final SuspendFunction1<PurchaseOptions, List<Purchase>>getAvailablePurchasesprivate final SuspendFunction1<RequestPurchaseProps, RequestPurchaseResult>requestPurchaseprivate final SuspendFunction2<Purchase, Boolean, Unit>finishTransaction
-
Constructor Summary
Constructors Constructor Description OpenIapStore(Context context)OpenIapStore(Context context, String store)OpenIapStore(Context context, String store, String appId)OpenIapStore(OpenIapProtocol module)
-
Method Summary
Modifier and Type Method Description final StateFlow<Boolean>getIsConnected()final StateFlow<List<Product>>getProducts()final StateFlow<List<ProductSubscription>>getSubscriptions()final StateFlow<List<Purchase>>getAvailablePurchases()final StateFlow<Purchase>getCurrentPurchase()final StateFlow<IapStatus>getStatus()final SuspendFunction1<InitConnectionConfig, Boolean>getInitConnection()Initialize the store connection. final SuspendFunction0<Boolean>getEndConnection()Close the store connection and release resources. final SuspendFunction1<ProductRequest, FetchProductsResult>getFetchProducts()Retrieve products or subscriptions from Google Play by SKU. final SuspendFunction1<PurchaseOptions, List<Purchase>>getGetAvailablePurchases()List the owned/available purchases held by Play Billing — non-consumables, active subscriptions, and any pending transactions returned by BillingClient.queryPurchasesAsyncfor INAPP + SUBS.final SuspendFunction1<RequestPurchaseProps, RequestPurchaseResult>getRequestPurchase()Initiate a purchase flow. final SuspendFunction2<Purchase, Boolean, Unit>getFinishTransaction()Complete a purchase transaction. final UnitsetActivity(Activity activity)final Unitclear()Clear listeners and transient state. final BooleaninitConnection()Initialize the store connection. final List<ActiveSubscription>getActiveSubscriptions(List<String> subscriptionIds)Get details of all currently active subscriptions. final BooleanhasActiveSubscriptions(List<String> subscriptionIds)Check whether the user has any active subscription. final UnitdeepLinkToSubscriptions(DeepLinkOptions options)Open the platform's subscription management UI. final BillingProgramAvailabilityResultAndroidisBillingProgramAvailable(BillingProgramAndroid program)Check whether a billing program (e.g., External Payments) is available. final BillingProgramReportingDetailsAndroidcreateBillingProgramReportingDetails(BillingProgramAndroid program, DeveloperBillingTypeAndroid developerBillingType)Create the reporting payload Google requires after a Developer-Provided Billing transaction (Play Billing 8.3.0+). final BooleanlaunchExternalLink(Activity activity, LaunchExternalLinkParamsAndroid params)Launch an external content/offer link from inside the Billing Programs flow (Play Billing 8.2.0+). final BooleanopenRedeemOfferCode(Activity activity)Open the Google Play offer/promo code redemption page (https://play.google.com/redeem) so the user can enter a code. final BillingChoiceInfoAndroidgetBillingChoiceInfo(GetBillingChoiceInfoParamsAndroid params)Fetch Billing Choice display assets for developer-rendered choice screens (Play Billing 9.1.0+). final BillingResultAndroidshowBillingProgramInformationDialog(Activity activity, BillingProgramInformationDialogParamsAndroid params)Show the mandatory information dialog before a developer-rendered, in-app Billing Choice screen (Play Billing 9.1.0+). final InAppMessageResultAndroidshowInAppMessages(Activity activity, InAppMessageParamsAndroid params)Show Play billing in-app messages such as payment issues or price-change confirmations. final UnitenableBillingProgram(BillingProgramAndroid program)Enable a billing program for the next connection (8.2.0+; Billing Choice 9.1.0+). final UnitaddPurchaseUpdateListener(OpenIapPurchaseUpdateListener listener)final UnitremovePurchaseUpdateListener(OpenIapPurchaseUpdateListener listener)final UnitaddPurchaseErrorListener(OpenIapPurchaseErrorListener listener)final UnitremovePurchaseErrorListener(OpenIapPurchaseErrorListener listener)final UnitaddUserChoiceBillingListener(OpenIapUserChoiceBillingListener listener)final UnitremoveUserChoiceBillingListener(OpenIapUserChoiceBillingListener listener)final UnitaddDeveloperProvidedBillingListener(OpenIapDeveloperProvidedBillingListener listener)final UnitremoveDeveloperProvidedBillingListener(OpenIapDeveloperProvidedBillingListener listener)final UnitaddSubscriptionBillingIssueListener(OpenIapSubscriptionBillingIssueListener listener)final UnitremoveSubscriptionBillingIssueListener(OpenIapSubscriptionBillingIssueListener listener)final UnitpostStatusMessage(String message, PurchaseResultStatus status, String productId)final UnitclearStatusMessage()-
-
Method Detail
-
getIsConnected
final StateFlow<Boolean> getIsConnected()
-
getProducts
final StateFlow<List<Product>> getProducts()
-
getSubscriptions
final StateFlow<List<ProductSubscription>> getSubscriptions()
-
getAvailablePurchases
final StateFlow<List<Purchase>> getAvailablePurchases()
-
getCurrentPurchase
final StateFlow<Purchase> getCurrentPurchase()
-
getInitConnection
final SuspendFunction1<InitConnectionConfig, Boolean> getInitConnection()
Initialize the store connection. Must be called before any other IAP API.
-
getEndConnection
final SuspendFunction0<Boolean> getEndConnection()
Close the store connection and release resources.
-
getFetchProducts
final SuspendFunction1<ProductRequest, FetchProductsResult> getFetchProducts()
Retrieve products or subscriptions from Google Play by SKU.
-
getGetAvailablePurchases
final SuspendFunction1<PurchaseOptions, List<Purchase>> getGetAvailablePurchases()
List the owned/available purchases held by Play Billing — non-consumables, active subscriptions, and any pending transactions returned by
BillingClient.queryPurchasesAsyncfor INAPP + SUBS. Use this to restore purchases or to recover anything not finished previously. (iOS usesTransaction.unfinished/Transaction.allsemantics; on Android the concept is "owned by the user", not strictly "unfinished".)
-
getRequestPurchase
final SuspendFunction1<RequestPurchaseProps, RequestPurchaseResult> getRequestPurchase()
Initiate a purchase flow. The result is delivered via the purchase update listener, NOT through the return value.
-
getFinishTransaction
final SuspendFunction2<Purchase, Boolean, Unit> getFinishTransaction()
Complete a purchase transaction. Call after server-side verification.
-
setActivity
final Unit setActivity(Activity activity)
-
initConnection
final Boolean initConnection()
Initialize the store connection. Must be called before any other IAP API.
Convenience overload — calls the config-accepting variant with
null.
-
getActiveSubscriptions
final List<ActiveSubscription> getActiveSubscriptions(List<String> subscriptionIds)
Get details of all currently active subscriptions.
-
hasActiveSubscriptions
final Boolean hasActiveSubscriptions(List<String> subscriptionIds)
Check whether the user has any active subscription.
-
deepLinkToSubscriptions
final Unit deepLinkToSubscriptions(DeepLinkOptions options)
Open the platform's subscription management UI.
-
isBillingProgramAvailable
final BillingProgramAvailabilityResultAndroid isBillingProgramAvailable(BillingProgramAndroid program)
Check whether a billing program (e.g., External Payments) is available.
-
createBillingProgramReportingDetails
final BillingProgramReportingDetailsAndroid createBillingProgramReportingDetails(BillingProgramAndroid program, DeveloperBillingTypeAndroid developerBillingType)
Create the reporting payload Google requires after a Developer-Provided Billing transaction (Play Billing 8.3.0+).
-
launchExternalLink
final Boolean launchExternalLink(Activity activity, LaunchExternalLinkParamsAndroid params)
Launch an external content/offer link from inside the Billing Programs flow (Play Billing 8.2.0+).
-
openRedeemOfferCode
final Boolean openRedeemOfferCode(Activity activity)
Open the Google Play offer/promo code redemption page (https://play.google.com/redeem) so the user can enter a code. A listener can receive the redeemed purchase while the app has an active billing connection; reconcile available purchases when the app resumes. Does not require the billing client to be initialized.
-
getBillingChoiceInfo
final BillingChoiceInfoAndroid getBillingChoiceInfo(GetBillingChoiceInfoParamsAndroid params)
Fetch Billing Choice display assets for developer-rendered choice screens (Play Billing 9.1.0+).
-
showBillingProgramInformationDialog
final BillingResultAndroid showBillingProgramInformationDialog(Activity activity, BillingProgramInformationDialogParamsAndroid params)
Show the mandatory information dialog before a developer-rendered, in-app Billing Choice screen (Play Billing 9.1.0+).
-
showInAppMessages
final InAppMessageResultAndroid showInAppMessages(Activity activity, InAppMessageParamsAndroid params)
Show Play billing in-app messages such as payment issues or price-change confirmations.
-
enableBillingProgram
final Unit enableBillingProgram(BillingProgramAndroid program)
Enable a billing program for the next connection (8.2.0+; Billing Choice 9.1.0+). This should be called BEFORE initConnection to configure the BillingClient.
- Parameters:
program- The billing program to enable
-
addPurchaseUpdateListener
final Unit addPurchaseUpdateListener(OpenIapPurchaseUpdateListener listener)
-
removePurchaseUpdateListener
final Unit removePurchaseUpdateListener(OpenIapPurchaseUpdateListener listener)
-
addPurchaseErrorListener
final Unit addPurchaseErrorListener(OpenIapPurchaseErrorListener listener)
-
removePurchaseErrorListener
final Unit removePurchaseErrorListener(OpenIapPurchaseErrorListener listener)
-
addUserChoiceBillingListener
final Unit addUserChoiceBillingListener(OpenIapUserChoiceBillingListener listener)
-
removeUserChoiceBillingListener
final Unit removeUserChoiceBillingListener(OpenIapUserChoiceBillingListener listener)
-
addDeveloperProvidedBillingListener
final Unit addDeveloperProvidedBillingListener(OpenIapDeveloperProvidedBillingListener listener)
-
removeDeveloperProvidedBillingListener
final Unit removeDeveloperProvidedBillingListener(OpenIapDeveloperProvidedBillingListener listener)
-
addSubscriptionBillingIssueListener
final Unit addSubscriptionBillingIssueListener(OpenIapSubscriptionBillingIssueListener listener)
-
removeSubscriptionBillingIssueListener
final Unit removeSubscriptionBillingIssueListener(OpenIapSubscriptionBillingIssueListener listener)
-
postStatusMessage
final Unit postStatusMessage(String message, PurchaseResultStatus status, String productId)
-
clearStatusMessage
final Unit clearStatusMessage()
-
-
-
-