{"id":19462775,"url":"https://github.com/mvojtkovszky/billinghelper","last_synced_at":"2025-10-17T14:20:03.977Z","repository":{"id":144214312,"uuid":"289740188","full_name":"mvojtkovszky/BillingHelper","owner":"mvojtkovszky","description":"Simplify the use of Google Play Billing Library (v7.1.1). Handles client connection, querying product details, owned purchases, different purchase types, acknowledging purchases, verify purchase signatures etc.","archived":false,"fork":false,"pushed_at":"2024-11-03T20:49:30.000Z","size":226,"stargazers_count":38,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2024-11-03T21:27:05.899Z","etag":null,"topics":["android","android-billing","android-billing-library","android-library","billing","google-billing","kotlin","library","purchases-android","subscriptions-and-payments"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mvojtkovszky.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-23T18:03:17.000Z","updated_at":"2024-10-29T09:15:25.000Z","dependencies_parsed_at":"2023-12-07T12:29:22.734Z","dependency_job_id":"7dc59cb7-8db3-4626-bc92-ad4c92c6ef9e","html_url":"https://github.com/mvojtkovszky/BillingHelper","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvojtkovszky%2FBillingHelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvojtkovszky%2FBillingHelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvojtkovszky%2FBillingHelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvojtkovszky%2FBillingHelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mvojtkovszky","download_url":"https://codeload.github.com/mvojtkovszky/BillingHelper/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223992708,"owners_count":17237501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-billing","android-billing-library","android-library","billing","google-billing","kotlin","library","purchases-android","subscriptions-and-payments"],"created_at":"2024-11-10T18:05:31.268Z","updated_at":"2025-10-17T14:20:03.961Z","avatar_url":"https://github.com/mvojtkovszky.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BillingHelper\nSimplify the use of Google Play Billing Library (v8.0.0). \nHandles client connection, querying product details, owned purchases, different purchase types, \nacknowledging purchases, verify purchase signatures etc.\n\n## How does it work?\nMake sure your `Activity`/`Fragment` implements `BillingListener` and initializes `BillingHelper`\n``` kotlin\nclass MainActivity: AppCompatActivity(), BillingListener {\n\n    lateinit var billing: BillingHelper\n\n    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {\n        super.onCreate(savedInstanceState, persistentState)\n\n        // Construct helper - by default, connection will be initialized immediately with product \n        // details and owned purchases queried. All events are reported via billingListener.\n        // At least one of productInAppPurchases or productSubscriptions is required.\n        // For more configuration options, check BillingHelper constructor parameters.\n        billing = BillingHelper(\n            context = this, \n            productInAppPurchases = listOf(\"inAppPurchaseProductName1\", \"inAppPurchaseProductName2\"),\n            productSubscriptions = listOf(\"subscriptionProductName\"),\n            billingListener = this\n        )\n    }\n\n    override fun onDestroy() {\n        super.onDestroy()\n        // make sure to clean it up when you're done\n        billing.endClientConnection()\n    }\n\n    override fun onBillingEvent(event: BillingEvent, message: String?) {\n        // receive an event based on calls to billing\n    }\n}\n```\n\n\u003cbr/\u003eUse any of its public methods or attributes, `BillingHelper` will do all the heavy lifting and always report changes via `BillingListener`\n``` kotlin\nfun consumePurchase(purchase: Purchase)\nfun endClientConnection()\nfun getPurchasesWithProductName(productName: String): List\u003cPurchase\u003e\nfun getProductDetails(productName: String): ProductDetails?\nfun getUnfetchedProducts(): List\u003cUnfetchedProduct\u003e\nfun isPurchased(productName: String): Boolean\nfun launchPurchaseFlow(activity: Activity, productName: String)\nfun initClientConnection(queryForProductDetailsOnConnected: Boolean, queryForOwnedPurchasesOnConected: Boolean)\nfun initQueryOwnedPurchases()\nfun initQueryProductDetails()\nfun acknowledgePurchases(purchases: List\u003cPurchase\u003e)\nfun isFeatureSupported(feature: String)\nfun addBillingListener(listener: BillingListener)\nfun removeBillingListener(listener: BillingListener)\n\nvar queryProductDetailsOnConnected: Boolean\nvar queryOwnedPurchasesOnConnected: Boolean\nvar queryPurchaseHistoryRecordsOnConnected: Boolean\nvar autoAcknowledgePurchases: Boolean\nvar enableLogging: Boolean\n\nvar billingClient: BillingClient\n    private set\nval billingReady: Boolean\nval connectionState: Int\nvar purchasesQueried: Boolean\n    private set\nvar productDetailsQueried: Boolean\n    private set\nvar isConnectionFailure: Boolean\n    private set\nval purchasesPresentable: Boolean\n```\n\n\u003cbr/\u003e`BillingEvent` includes all of the things you might be interested in, served via `BillingListener`\n``` kotlin\nenum class BillingEvent {\n    BILLING_CONNECTED,\n    BILLING_CONNECTION_FAILED,\n    BILLING_DISCONNECTED,\n    QUERY_PRODUCT_DETAILS_COMPLETE,\n    QUERY_PRODUCT_DETAILS_FAILED,\n    QUERY_OWNED_PURCHASES_COMPLETE,\n    QUERY_OWNED_PURCHASES_FAILED,\n    PURCHASE_COMPLETE,\n    PURCHASE_FAILED,\n    PURCHASE_CANCELLED,\n    PURCHASE_ACKNOWLEDGE_SUCCESS,\n    PURCHASE_ACKNOWLEDGE_FAILED,\n    CONSUME_PURCHASE_SUCCESS,\n    CONSUME_PURCHASE_FAILED\n}\n```\n\n\u003cbr/\u003eYou can also make use of provided `PriceUtil` object to format prices in various ways\n``` kotlin\n// Get formatted price for a product\nval formattedPrice = getProductDetails(yourProductName).getFormattedPrice() // \"16.80 EUR\"\nval dividedPrice = getProductDetails(yourProductName).getFormattedPriceDivided(4) // \"4.20 EUR\"\n``` \n\n## Best practices\nSince library caches latest state of products and purchases as they are known to an instance based \non the data requested, it's suggested to rely on a **single instance** of BillingHelper in your app.\n\u003cbr/\u003e\nOtherwise you may need to check for the latest information before using the purchased items or \nitem details (manually handle the Optimistic Concurrency Control).\n\n\n## Great! How do I get started?\nMake sure root build.gradle repositories include JitPack\n``` gradle\nallprojects {\n    repositories {\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n\nAnd BillingHelper dependency is added to app build.gradle\n``` gradle\ndependencies {\n    implementation \"com.github.mvojtkovszky:BillingHelper:$latest_version\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvojtkovszky%2Fbillinghelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmvojtkovszky%2Fbillinghelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvojtkovszky%2Fbillinghelper/lists"}