{"id":28254979,"url":"https://github.com/chargebee/chargebee-android","last_synced_at":"2025-06-16T06:31:27.435Z","repository":{"id":38776209,"uuid":"279238499","full_name":"chargebee/chargebee-android","owner":"chargebee","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-22T13:43:39.000Z","size":758,"stargazers_count":9,"open_issues_count":10,"forks_count":7,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-19T20:19:10.699Z","etag":null,"topics":["critical","mobile-subscription"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chargebee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2020-07-13T08:14:39.000Z","updated_at":"2025-04-22T10:06:58.000Z","dependencies_parsed_at":"2023-12-15T14:25:50.692Z","dependency_job_id":"0f378088-35d9-4d37-a304-17399ce7416f","html_url":"https://github.com/chargebee/chargebee-android","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/chargebee/chargebee-android","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chargebee","download_url":"https://codeload.github.com/chargebee/chargebee-android/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-android/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260114290,"owners_count":22960870,"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":["critical","mobile-subscription"],"created_at":"2025-05-19T20:16:38.315Z","updated_at":"2025-06-16T06:31:27.378Z","avatar_url":"https://github.com/chargebee.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chargebee Android\n\n\u003e [!NOTE]  \n\u003e #### Updates for Billing Library 5\n\u003e - SDK Version 2.0: This version includes Google Billing Library 6.2.1 but still uses Google Billing Library 5.0 APIs to fetch product information from the Google Play Console and make purchases. If you’re integrating Chargebee’s SDK for the first time, then use this version, and if you’re migrating from the older version of SDK to this version, follow the migration steps in this [document](https://www.chargebee.com/docs/2.0/mobile-playstore-billing-library-5.html).\n\u003e - SDK Version 1.2.2: This [version](https://github.com/chargebee/chargebee-android/tree/1.x.x) includes Billing Library 6.2.1 but still uses Billing Library 4.0 APIs to fetch product information from the Google Play Console and make purchases. This will enable you to list or update your Android app on the store without any warnings from Google and give you enough time to migrate to version 2.0.\n\u003e - SDK Version 1.1.0: This and less than this version of SDKs use billing library 4.0 APIs that are deprecated by Google. Therefore, it is highly recommended that you upgrade your app and integrate it with SDK version 1.2.0 and above.\n\n\nThis is Chargebee’s Android Software Development Kit (SDK). This SDK makes it efficient and comfortable to build a seamless subscription experience in your Android app. \n\nPost-installation, initialization, and authentication with the Chargebee site, this SDK will support the following process.\n\n1. **Sync In-App Subscriptions with Chargebee:** [Integrate](https://www.chargebee.com/docs/2.0/mobile-playstore-connect.html#chargebee-configuration) Chargebee with Google Play Store to process in-app purchase subscriptions, and track them on your Chargebee account for a single source of truth for subscriptions across the Web and Google Play Store. Use this if you are selling digital goods or services, or are REQUIRED to use Google Play's in-app purchases. \n**For SDK methods to work, ensure that [prerequisites](https://www.chargebee.com/docs/2.0/mobile-playstore-connect.html#prerequisites-configuration) are configured in Chargebee.** \n\n2. **Tokenisation of credit card:** Tokenize credit card information while presenting your user interface. Use this if you are selling physical goods or offline services or are NOT REQUIRED to use Google's in-app purchases.\n\n## Requirements\nThe following requirements must be set up before installing Chargebee’s Android SDK.\n\n* Android Target API Level 31 and above\n* [Android Gradle Plugin](https://developer.android.com/studio/releases/gradle-plugin) 4.2.2\n* [Gradle](https://gradle.org/releases/) 6.1.1+\n* [AndroidX](https://developer.android.com/jetpack/androidx/)\n* Java 8+ and Kotlin\n\n## Installation\nThe `Chargebee-Android` SDK can be installed by adding below dependency to the `build.gradle` file:\n\n```kotlin\nimplementation 'com.chargebee:chargebee-android:2.0.0-beta-4'\n```\n\n## Example project\nThis is an optional step that helps you verify the SDK implementation using this example project. You can download or clone the example project via GitHub.\n\nTo run the example project, follow these steps.\n\n1. Clone the repo - https://github.com/chargebee/chargebee-android.\n\n2. Run build.gradle from the Example directory.\n\n## Configuration\nThere are two types of configuration.\n\n* Configuration for In-App Purchases\n\n* Configuration for credit card using tokenization\n\n### Configuration for In-App Purchases\nTo configure the Chargebee Android SDK for completing and managing In-App Purchases, follow these steps.\n\n1. [Integrate](https://www.chargebee.com/docs/2.0/mobile-playstore-connect.html) Google Play Store with your [Chargebee site](https://app.chargebee.com/sites/select).\n\n2. On the **Sync Overview** page of the web app, click **Set up notifications** and use the generated [App ID](https://www.chargebee.com/docs/1.0/mobile-playstore-notifications.html#app-id) value as **SDK Key**.\n\n3. On the Chargebee site, navigate to **Settings** \u003e **Configure Chargebee** \u003e [API Keys](https://www.chargebee.com/docs/2.0/api_keys.html#create-an-api-key) to create a new [Publishable API Key](https://www.chargebee.com/docs/2.0/api_keys.html#types-of-api-keys_publishable-key) or use an existing Publishable API Key. \n**Note:** During the publishable API key creation you must allow **read-only** access to plans/items otherwise this key will not work in the following step. Read [more](https://www.chargebee.com/docs/2.0/api_keys.html#types-of-api-keys_publishable-key).\n\n4. Initialize the SDK with your Chargebee site, **Publishable API Key**, and SDK Key by including the following snippets in your app delegate during app startup.\n\n```kotlin\nimport com.chargebee.android.Chargebee\n\nChargebee.configure(\n  site = \"your-site\",\n  publishableApiKey = \"api-key\",\n  sdkKey = \"sdk-key\",\n  packageName = \"your-package\"\n) {\n  when (it) {\n    is ChargebeeResult.Success -\u003e {\n      // Success\n    }\n    is ChargebeeResult.Error -\u003e {\n      // Error\n    }\n  }\n}\n```\n### Configuration for credit card using tokenization\nTo configure SDK only for tokenizing credit card details, follow these steps.\n\n1. Initialize the SDK with your Chargebee Site and Publishable/Full Access Key.\n\n2. Initialize the SDK during your app startup by including this in the Android application class' [onCreate](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle)) method.\n\n```kotlin\nimport com.chargebee.android.Chargebee\n\nChargebee.configure(site = \"your-site\", publishableApiKey = \"api-key\")\n\n```\n## Integration\nThis section describes the SDK integration processes.\n\n* Integrating In-App Purchases\n\n* Integrating credit card tokenizationConfigure\n\n### Integrating In-App Purchases\nThe following section describes how to use the SDK to integrate In-App Purchase information. For details on In-App Purchase, read more [here](https://www.chargebee.com/docs/2.0/mobile-in-app-purchases.html).\n\n### Get all IAP Product Identifiers from Chargebee\nEvery In-App Purchase subscription product that you configure in your Play Store account, can be configured in Chargebee as a Plan. Start by retrieving the Google IAP Product IDs from your Chargebee account.\n\n```kotlin\nCBPurchase.retrieveProductIdentifiers(queryParam) {\n    when (it) {\n        is CBProductIDResult.ProductIds -\u003e {\n          Log.i(TAG, \"List of Product Identifiers:  $it\")\n        }\n        is CBProductIDResult.Error -\u003e {\n           Log.e(TAG, \" ${it.exp.message}\")\n            // Handle error here\n        }\n    }\n}\n```\nFor eg. query params above can be \"limit\": \"100\".\n\nThe above function will determine your product catalog version in Chargebee and hit the relevant APIs automatically, to retrieve the Chargebee Plans that correspond to Google IAP products, along with their Google IAP Product IDs.\n\n### Get IAP Products\nRetrieve the Google IAP Product using the following function.\n\n```kotlin\nCBPurchase.retrieveProducts(activity, productIdList= [\"Product ID's from Google Play Console\"],\n      object : CBCallback.ListProductsCallback\u003cArrayList\u003cCBProduct\u003e\u003e {\n               override fun onSuccess(productDetails: ArrayList\u003cCBProduct\u003e) {\n                     Log.i(TAG, \"List of Products:  $productDetails\")\n                }\n                override fun onError(error: CBException) {\n                    Log.e(TAG, \"Error:  ${error.message}\")\n                }\n            })\n```\nYou can present any of the above products to your users for them to purchase.\n\n### Buy or Subscribe Product\nPass the `PurchaseProductParams`, `CBCustomer` and `OfferToken` to the following function when the user chooses the product to purchase.\n\n`CBCustomer` - **Optional object**. Although this is an optional object, we recommend passing the necessary customer details, such as `customerId`, `firstName`, `lastName`, and `email` if it is available before the user subscribes to your App. This ensures that the customer details in your database match the customer details in Chargebee. If the `customerId` is not passed in the customer's details, then the value of `customerId` will be the same as the `SubscriptionId` created in Chargebee.\n\n**Note**: The `customer` parameter in the below code snippet is an instance of `CBCustomer` class that contains the details of the customer who wants to subscribe or buy the product.\n\n```kotlin\nval purchaseParams = PurchaseProductParams(selectedCBProduct, \"selectedOfferToken\")\nval cbCustomer = CBCustomer(\"customerId\",\"firstName\",\"lastName\",\"email\")\nCBPurchase.purchaseProduct(purchaseProductParams = purchaseProductParams, customer = cbCustomer, object : CBCallback.PurchaseCallback\u003cString\u003e{\n      override fun onSuccess(result: ReceiptDetail, status:Boolean) {\n        Log.i(TAG, \"$status\")\n        Log.i(TAG, \"${result.subscription_id}\")\n        Log.i(TAG, \"${result.plan_id}\")   \n      }\n      override fun onError(error: CBException) {\n        Log.e(TAG, \"Error:  ${error.message}\")\n      }\n})\n ```\nThe above function will handle the purchase against Google Play Store and send the IAP token for server-side token verification to your Chargebee account. Use the Subscription ID returned by the above function, to check for Subscription status on Chargebee and confirm the access - granted or denied.\n\n### Invoke Manage Subscriptions in your App\nThe `showManageSubscriptionsSettings()` function is designed to invoke the Manage Subscriptions in your app using Chargebee's Android SDKs. `Chargebee.showManageSubscriptionsSettings()`, opens the Play Store App subscriptions settings page.\n\n### One-Time Purchases\nThe `purchaseNonSubscriptionProduct` function handles the one-time purchase against Google Play Store and sends the IAP receipt for server-side receipt verification to your Chargebee account. Post verification a Charge corresponding to this one-time purchase will be created in Chargebee. There are two types of one-time purchases `consumable` and `non_consumable`.\n\n```kotlin\nCBPurchase.purchaseNonSubscriptionProduct(product = CBProduct, customer = CBCustomer, productType = OneTimeProductType.CONSUMABLE, callback = object : CBCallback.OneTimePurchaseCallback{\n      override fun onSuccess(result: NonSubscription, status:Boolean) {\n        Log.i(TAG, \"invoice ID:  ${result.invoiceId}\")\n        Log.i(TAG, \"charge ID:  ${result.chargeId}\")\n        Log.i(TAG, \"customer ID:  ${result.customerId}\")\n      }\n      override fun onError(error: CBException) {\n        Log.e(TAG, \"Error:  ${error.message}\")\n      }\n})\n ```\n\nThe given code defines a function named `purchaseNonSubscriptionProduct` in the CBPurchase class, which takes four input parameters:\n\n- `product`: An instance of `CBProduct` class,  representing the product to be purchased from the Google Play Store.\n- `customer`: Optional. An instance of `CBCustomer` class, initialized with the customer's details such as `customerId`, `firstName`, `lastName`, and `email`.\n- `productType`: An enum instance of `productType` type, indicating the type of product to be purchased. It can be either .`consumable`, or `non_consumable`.\n- `callback`:  The `OneTimePurchaseCallback` listener will be invoked when product purchase completes.\n\nThe function is called asynchronously, and it returns a `Result` object with a `success` or `failure` case, which can be handled in the listener.\n- If the purchase is successful, the listener will be called with the `success` case, it returns `NonSubscriptionResponse` object. which includes the `customerId`, `chargeId`, and `invoiceId` associated with the purchase.\n- If there is any failure during the purchase, the listener will be called with the `error` case, it returns `CBException`. which includes an error object that can be used to handle the error.\n\n### Restore Purchase\n\nThe `restorePurchases()` function helps to recover your app user's previous purchases without making them pay again. Sometimes, your app user may want to restore their previous purchases after switching to a new device or reinstalling your app. You can use the `restorePurchases()` function to allow your app user to easily restore their previous purchases.\n\nTo retrieve **inactive** purchases along with the **active** purchases for your app user, you can call the `restorePurchases()` function with the `includeInActiveProducts` parameter set to `true`. If you only want to restore active subscriptions, set the parameter to `false`. Here is an example of how to use the `restorePurchases()` function in your code with the `includeInActiveProducts` parameter set to `true`.\n\n`CBCustomer` - **Optional object**. Although this is an optional object, we recommend passing the necessary customer details, such as `customerId`, `firstName`, `lastName`, and `email` if it is available before the user subscribes to your App. This ensures that the customer details in your database match the customer details in Chargebee. If the `customerId` is not passed in the customer's details, then the value of `customerId` will be the same as the `subscriptionId` created in Chargebee. Also, the restored subscriptions will not be associate with existing customerId.\n\n```kotlin\nCBPurchase.restorePurchases(context = current activity context, customer = CBCustomer, includeInActivePurchases = false, object : CBCallback.RestorePurchaseCallback{\n      override fun onSuccess(result: List\u003cCBRestoreSubscription\u003e) {\n        result.forEach {\n          Log.i(javaClass.simpleName, \"Successfully restored purchases\")\n        }  \n      }\n      override fun onError(error: CBException) {\n        Log.e(TAG, \"Error:  ${error.message}\")\n      }\n})\n ```\n\n##### Return Subscriptions Object \nThe `restorePurchases()` function returns an array of subscription objects and each object holds three attributes `subscription_id`, `plan_id`, and `store_status`. The value of `store_status` can be used to verify the subscription status such as `Active`, `InTrial`, `Cancelled` and `Paused`.\n\n##### Error Handling \nIn the event of any failures while finding associated subscriptions for the restored items, The SDK will return an error, as mentioned in the following table.\n\nThese are the possible error codes and their descriptions:\n| Error Code                        | Description                                                                                                                 |\n|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------|\n| `BillingErrorCode.SERVICE_TIMEOUT`            | The request has reached the maximum timeout before Google Play responds.       |\n| `BillingErrorCode.FEATURE_NOT_SUPPORTED` | The requested feature is not supported by the Play Store on the current device.                                             |\n| `BillingErrorCode.SERVICE_UNAVAILABLE`        | The service is currently unavailable.         |\n| `BillingErrorCode.DEVELOPER_ERROR`  | Error resulting from incorrect usage of the API.                                                          |\n| `BillingErrorCode.ERROR`         | Fatal error during the API action.                             |\n| `BillingErrorCode.SERVICE_DISCONNECTED`         | The app is not connected to the Play Store service via the Google Play Billing Library.                             |\n| `BillingErrorCode.UNKNOWN`         | Unknown error occurred.                             |\n\n##### Synchronization of Google Play Store Purchases with Chargebee through Receipt Validation\nReceipt validation is crucial to ensure that the purchases made by your users are synced with Chargebee. In rare cases, when a purchase is made at the Google Play Store, and the network connection goes off or the server not responding, the purchase details may not be updated in Chargebee. In such cases, you can use a retry mechanism by following these steps:\n\n* Add a network listener, as shown in the example project.\n* Save the product identifier in the cache once the purchase is initiated and clear the cache once the purchase is successful.\n* When the network connectivity is lost after the purchase is completed at Google Play Store but not synced with Chargebee, retrieve the product from the cache once the network connection is back and initiate `validateReceipt() / validateReceiptForNonSubscriptions()` by passing activity `Context`, `CBProduct` and `CBCustomer(optional)` as input. This will validate the receipt and sync the purchase in Chargebee as a subscription or one-time purchase. For subscriptions, use the function to `validateReceipt()`;for one-time purchases, use the function `validateReceiptForNonSubscriptions()`.\n\nUse the function available for the retry mechanism.\n##### Function for validating the Subscriptions receipt\n\n```kotlin\nCBPurchase.validateReceipt(context = current activity context, product = CBProduct, customer = CBCustomer, object : CBCallback.PurchaseCallback\u003cString\u003e {\n      override fun onSuccess(result: ReceiptDetail, status: Boolean) {\n        Log.i(TAG, \"$status\")\n        Log.i(TAG, \"${result.subscription_id}\")\n        Log.i(TAG, \"${result.plan_id}\")\n      }\n      override fun onError(error: CBException) {\n        Log.e(TAG, \"Error:  ${error.message}\")\n      }\n})\n ```\n\n##### Function for validating the One-Time Purchases receipt\n\n```kotlin\nCBPurchase.validateReceiptForNonSubscriptions(context = current activity context, product = CBProduct, customer = CBCustomer, productType = OneTimeProductType.CONSUMABLE, object : CBCallback.OneTimePurchaseCallback {\n      override fun onSuccess(result: NonSubscription, status: Boolean) {\n        Log.i(TAG, \"invoice ID:  ${result.invoiceId}\")\n        Log.i(TAG, \"charge ID:  ${result.chargeId}\")\n        Log.i(TAG, \"customer ID:  ${result.customerId}\")\n      }\n      override fun onError(error: CBException) {\n        Log.e(TAG, \"Error:  ${error.message}\")\n      }\n})\n ```\n\n### Get Subscription Status for Existing Subscribers\nThe following are methods for checking the subscription status of a subscriber who already purchased the product.\n\n### Get Subscription Status for Existing Subscribers using Query Parameters\nUse query parameters - Subscription ID, Customer ID, or Status for checking the Subscription status on Chargebee and confirm the access - granted or denied.\n\n```kotlin\nChargebee.retrieveSubscriptions(queryParam= \"[Array of String]\") {\n       when(it){\n             is ChargebeeResult.Success -\u003e{\n                  Log.i(TAG, \"subscription list in array:  ${it}\")\n                  Log.i(TAG, \"subscription status:  ${it?.get(0)?.cb_subscription?.status}\")\n             }\n             is ChargebeeResult.Error -\u003e{\n                  Log.e(TAG, \"Error :  ${it.exp.message}\")\n                  // Handle error here  \n             }\n       }\n}   \n```\nFor example, query parameters can be passed as **\"customer_id\" : \"id\", \"subscription_id\": \"id\", or \"status\": \"active\"**.\n\n### Get Subscription Status for Existing Subscribers using Subscription ID\n\nUse only Subscription ID for checking the Subscription status on Chargebee and confirm the access - granted or denied.\n\n```kotlin\nChargebee.retrieveSubscription(subscriptionId) {\n       when(it){\n             is ChargebeeResult.Success -\u003e{\n                  Log.i(TAG, \"subscription status:  ${it.status}\")\n             }\n             is ChargebeeResult.Error -\u003e{\n                  Log.e(TAG, \"Error :  ${it.exp.message}\")\n                  // Handle error here  \n             }\n       }\n}   \n```\n### Retrieve Entitlements of a Subscription\n\nUse the Subscription ID for fetching the list of [entitlements](https://www.chargebee.com/docs/2.0/entitlements.html) associated with the subscription.\n\n```kotlin\nChargebee.retrieveEntitlements(subscriptionId) {\n      when(it){\n            is ChargebeeResult.Success -\u003e {\n                Log.i(TAG, \"Response:  ${(it.data)}\") \n            }\n            is ChargebeeResult.Error -\u003e{\n                Log.e(TAG, \"Error :  ${it.exp.message}\")\n                // Handle error here\n           }\n     }\n}  \n```\n\n### Integrating credit card tokenization\nThe following section describes how to use the SDK to directly tokenize credit card information if you are NOT REQUIRED to use Google's in-app purchases.\n\n### Product Catalog 2.0\nIf you are using Product Catalog 2.0 in your Chargebee site, then you can use the following functions to retrieve the product to be presented for users to purchase.\n\n### Get all Items\nYou can retrieve the list of items by using the following function.\n\n```kotlin\nChargebee.retrieveAllItems(queryParam) {\n       when (it) {\n           is ChargebeeResult.Success -\u003e {\n                 Log.i(javaClass.simpleName, \"list items :  ${it.data}\")\n           }\n           is ChargebeeResult.Error -\u003e {\n                 Log.d(javaClass.simpleName, \"Error :  ${it.exp.message}\")\n           }\n       }\n}  \n```\nFor example, query parameters can be passed as **\"sort_by[desc]\" : \"name\" OR \"limit\": \"100\"**.\n\n### Get Item Details\nYou can retrieve specific item details by using the following function. Use the Item ID you received from the previous function - Get all items.\n\n```kotlin\nChargebee.retrieveItem(queryParam) {\n       when (it) {\n           is ChargebeeResult.Success -\u003e {\n                 Log.i(javaClass.simpleName, \"item details :  ${it.data}\")\n           }\n           is ChargebeeResult.Error -\u003e {\n                 Log.d(javaClass.simpleName, \"Error :  ${it.exp.message}\")\n           }\n       }\n}  \n```\n\n### Product Catalog 1.0\nIf you are using Product Catalog 1.0 in your Chargebee site, then you can use any of the following relevant functions to retrieve the product to be presented for users to purchase.\n\n### Get All Plans\nYou can retrieve the list of plans by using the following function.\n\n```kotlin\nChargebee.retrieveAllPlans(queryParam) {\n       when (it) {\n           is ChargebeeResult.Success -\u003e {\n                 Log.i(javaClass.simpleName, \"list Plans :  ${it.data}\")\n           }\n           is ChargebeeResult.Error -\u003e {\n                 Log.d(javaClass.simpleName, \"Error :  ${it.exp.message}\")\n           }\n       }\n}  \n```\nFor example, query parameters can be passed as **\"sort_by[desc]\" : \"name\" OR \"limit\": \"100\"**.\n\n### Get Plan Details\nYou can retrieve specific plan details by passing plan ID in the following function.\n\n```kotlin\nChargebee.retrievePlan(queryParam) {\n       when (it) {\n           is ChargebeeResult.Success -\u003e {\n                 Log.i(javaClass.simpleName, \"Plan details :  ${it.data}\")\n           }\n           is ChargebeeResult.Error -\u003e {\n                 Log.d(javaClass.simpleName, \"Error :  ${it.exp.message}\")\n           }\n       }\n}  \n```\n\n### Get Addon Details\nYou can retrieve specific addon details by passing addon ID in the following function.\n\n```kotlin\nChargebee.retrieve(\"addonId\") { addonResult -\u003e\n    try {\n        val addon = addonResult.getData()\n        Log.d(\"success\", addon.toString())\n        // Use addon details here\n    } catch (ex: CBException) {\n        Log.d(\"error\", ex.getMessage());\n        // Handle error here\n    }\n}\n```\n\n### Get Payment Token\nOnce the user selects the product to purchase, and you collect the credit card information, use the following function to tokenize the credit card details against Stripe. You need to have connected your Stripe account to your Chargebee site.\n\n```kotlin\n\nval card = Card(\n    number = \"4321567890123456\",\n    expiryMonth = \"12\",\n    expiryYear = \"29\",\n    cvc = \"123\")\nval paymentDetail = PaymentDetail(\n    currencyCode = \"USD\",\n    type = PaymentMethodType.CARD,\n    card = card)\nChargebee.createTempToken(paymentDetail) { tokenResult -\u003e\n    try {\n        val cbTempToken = tokenResult.getData()\n        Log.d(\"success\", cbTempToken)\n        // Use token here\n    } catch (ex: PaymentException) {\n        Log.d(\"error payment\", ex.toString())\n        // Handle PaymentException here\n    } catch (ex: InvalidRequestException) {\n        Log.d(\"error invalid\", ex.toString())\n        // Handle InvalidRequestException here\n    } catch (ex: OperationFailedException) {\n        Log.d(\"error operation\", ex.toString())\n        // Handle OperationFailedException here\n    }\n}\n```\n## Use the Chargebee Token\nOnce your customer’s card data is processed and stored, and a Chargebee token reference is returned to you, you can use the token in subsequent API calls to process transactions. The following are some endpoints that accept Chargebee tokens for processing.\n\n- [Create a Payment Source for the customer](https://apidocs.chargebee.com/docs/api/payment_sources#create_using_chargebee_token)\n- [Create a Subscription](https://apidocs.chargebee.com/docs/api/subscriptions#create_a_subscription)\n- [Update a Subscription](https://apidocs.chargebee.com/docs/api/subscriptions#update_a_subscription)\n\nPlease refer to the [Chargebee API Docs](https://apidocs.chargebee.com/docs/api) for subsequent integration steps.\n\n\n## License\n\nChargebee is available under the [MIT license](https://opensource.org/licenses/MIT). See the LICENSE file for more info.\n\n## Document in Markdown\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick here to expand...\u003c/summary\u003e\n  \n  Chargebee Android\n  =================\n  \n  This is Chargebee's Android Software Development Kit (SDK). This SDK makes it efficient and comfortable to build a seamless subscription experience in your Android app.\n  \n  Post-installation, initialization, and authentication with the Chargebee site, this SDK will support the following process.\n  \n  -   **Sync In-App Subscriptions with Chargebee**: [Integrate](https://www.chargebee.com/docs/2.0/mobile-playstore-connect.html#chargebee-configuration) Chargebee with Google Play Store to process in-app purchase subscriptions, and track them on your Chargebee account for a single source of truth for subscriptions across the Web and Google Play Store. Use this if you are selling digital goods or services, or are REQUIRED to use Google Play's in-app purchases as per their [app review guidelines](https://support.google.com/googleplay/android-developer/answer/9858738).\n      **For SDK methods to work, ensure that **[**prerequisites**](https://www.chargebee.com/docs/2.0/mobile-playstore-connect.html#prerequisites-configuration)**  are configured in Chargebee.**\n  \n  -   **Tokenisation of credit card**: Tokenize credit card information while presenting your user interface. Use this if you are selling physical goods or offline services or are NOT REQUIRED to use Google's in-app purchases as per their [app review guidelines](https://support.google.com/googleplay/android-developer/answer/9858738).\n  \n  Requirements\n  ------------\n  \n  The following requirements must be set up before installing Chargebee's Android SDK.\n  \n  -   [Android 5.0 (API level 21)](https://developer.android.com/studio/releases/platforms#5.0) and above\n  -   [Android Gradle Plugin](https://developer.android.com/studio/releases/gradle-plugin) 4.0.0\n  -   [Gradle](https://gradle.org/releases/) 6.1.1+\n  -   [AndroidX](https://developer.android.com/jetpack/androidx/)\n  -   [Java 8+](https://www.oracle.com/java/technologies/downloads/#java8) and [Kotlin](https://kotlinlang.org/)\n  \n  Installation\n  ------------\n  \n  To install Chargebee's Android SDK, add the following dependency to the build.gradle file.\n  \n  ```\n  implementation 'com.chargebee:chargebee-android:1.0.25'\n  ```\n  Example project\n  ---------------\n  \n  This is an optional step that helps you  verify the SDK implementation using this example project. You can download or clone the example project via GitHub.\n  \n  To run the example project, follow these steps.\n  \n  1.  Clone the repo - https://github.com/chargebee/chargebee-android.\n  2.  Run build.gradle from the Example directory.\n  \n  Configuration\n  -------------\n  \n  There are two types of configuration.\n  -   Configuration for In-App Purchases\n  -   Configuration for credit card using tokenization\n  \n  ### Configuration for In-App Purchases\n  \n  To configure the Chargebee Android SDK for completing and managing In-App Purchases, follow these steps.\n  \n  1.  [Integrate](https://www.chargebee.com/docs/2.0/mobile-playstore-connect.html)  Google Play Store with your [Chargebee site](https://app.chargebee.com/login).\n  2.  On the**Sync Overview** pageof theweb app, click**Set up notifications**and use the generated[**App ID**](https://www.chargebee.com/docs/1.0/mobile-playstore-notifications.html#app-id)valueas **SDK Key.**\n  3.  On the Chargebee site, navigate to **Settings** \u003e **Configure Chargebee** *\u003e* [**API Keys**](https://www.chargebee.com/docs/2.0/api_keys.html#create-an-api-key) to create a new **Publishable API Key** or use an existing [**Publishable API Key**](https://www.chargebee.com/docs/2.0/api_keys.html#types-of-api-keys_publishable-key).\n      **Note:** During the publishable API key creation you must allow **read-only** access to plans/items otherwise this key will not work in the following step. Read [more](https://www.chargebee.com/docs/2.0/api_keys.html#types-of-api-keys_publishable-key).\n  4.  Initialize the SDK with your Chargebee site, Publishable API Key, and SDK Key by including the following snippets in your app delegate during app startup.\n  \n  ```kotlin\n  import com.chargebee.android.Chargebee\n  \n  Chargebee.configure(site= \"your-site\",\n                      publishableApiKey= \"api_key\",\n                      sdkKey= \"sdk_key\",packageName = \"packageName\")\n  ```\n\n  ### Configuration for credit card using tokenization\n  \n  To configure SDK only for tokenizing credit card details, follow these steps.\n  \n  1.  Initialize the SDK with your Chargebee Site and Publishable/Full Access Key.\n  2.  Initialize the SDK during your app startup by including this in the Android application class' [onCreate](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle)) method.\n  \n  ```kotlin\n  import com.chargebee.android.Chargebee\n  \n  Chargebee.configure(site = \"your-site\", publishableApiKey = \"api_key\")\n  ```\n  \n  Integration\n  -----------\n  \n  This section describes the SDK integration processes.\n  \n  -   Integrating In-App Purchases\n  -   Integrating credit card tokenizationConfigure\n  \n  ### Integrating In-App Purchases\n  \n  The following section describes how to use the SDK to integrate In-App Purchase information. For details on In-App Purchase, read more [here](https://www.chargebee.com/docs/2.0/mobile-in-app-purchases.html).\n\n### Get all IAP Product Identifiers from Chargebee\nEvery In-App Purchase subscription product that you configure in your Play Store account, can be configured in Chargebee as a Plan. Start by retrieving the Google IAP Product IDs from your Chargebee account.\n\n```kotlin\nCBPurchase.retrieveProductIdentifers(queryParam) {\n    when (it) {\n        is CBProductIDResult.ProductIds -\u003e {\n          Log.i(TAG, \"List of Product Identifiers:  $it\")\n        }\n        is CBProductIDResult.Error -\u003e {\n           Log.e(TAG, \" ${it.exp.message}\")\n            // Handle error here\n        }\n    }\n}\n```\nFor eg. query params above can be \"limit\": \"100\".\n\nThe above function will determine your product catalog version in Chargebee and hit the relevant APIs automatically, to retrieve the Chargebee Plans that correspond to Google IAP products, along with their Google IAP Product IDs.\n\n  #### Get IAP Products\n  \n  Retrieve the Google IAP Product using the following function.\n  \n  ```kotlin\n  CBPurchase.retrieveProducts(this, productIdList= \"[Product ID's from Google Play Console]\",\n        object : CBCallback.ListProductsCallback\u003cArrayList\u003cProducts\u003e\u003e {\n                 override fun onSuccess(productDetails: ArrayList\u003cProducts\u003e) {\n                       Log.i(TAG, \"List of Products:  $productDetails\")\n                  }\n                  override fun onError(error: CBException) {\n                      Log.e(TAG, \"Error:  ${error.message}\")\n                     // Handle error here\n                  }\n              })\n  ```\n  \n  You can present any of the above products to your users for purchase.\n  \n  #### Buy or Subscribe Product\n\n  Pass the `CBProduct` and  `CBCustomer` objects to the following function when the user chooses the product to purchase.\n  \n  `CBCustomer` - **Optional object**. Although this is an optional object, we recommend passing the necessary customer details, such as `customerId`, `firstName`, `lastName`, and `email` if it is available before the user subscribes to your App. This ensures that the customer details in your database match the customer details in Chargebee. If the `customerId` is not passed in the customer's details, then the value of `customerId` will be the same as the `SubscriptionId` created in Chargebee.\n  \n  **Note**: The `customer` parameter in the below code snippet is an instance of `CBCustomer` class that contains the details of the customer who wants to subscribe or buy the product.\n\n  ```kotlin\n    CBPurchase.purchaseProduct(product=CBProduct, customer=CBCustomer, object : CBCallback.PurchaseCallback\u003cPurchaseModel\u003e{\n        override fun onSuccess(result: ReceiptDetail, status:Boolean) {\n            Log.i(TAG, \"$status\") \n            Log.i(TAG, \"${result.subscription_id}\")\n            Log.i(TAG, \"${result.plan_id}\")\n        }\n        override fun onError(error: CBException) {\n            Log.e(TAG, \"Error:  ${error.message}\")\n            // Handle error here    \n        }\n        })\n  ```\n  \n  The above function will handle the purchase against Google Play Store and send the IAP token for server-side token verification to your Chargebee account. Use the Subscription ID returned by the above function, to check for Subscription status on Chargebee and confirm the access - granted or denied.\n\n  This function also returns the plan ID associated with a subscription. You can associate JSON metadata with the Google Play Store plans in Chargebee and retrieve the same by passing plan ID to the SDK method - [retrievePlan](https://github.com/chargebee/chargebee-android#get-plan-details)(PC 1.0) or [retrieveItem](https://github.com/chargebee/chargebee-android#get-item-details)(PC 2.0).\n  \n  #### Get Subscription Status for Existing Subscribers\n  \n  The following are methods for checking the subscription status of a subscriber who already purchased the product.\n  \n  ##### Get Subscription Status for Existing Subscribers using Query Parameters\n  \n  Use query parameters - Subscription ID, Customer ID, or Status for checking the Subscription status on Chargebee and confirm the access - granted or denied.\n  \n  ```kotlin\n  Chargebee.retrieveSubscriptions(queryParam= \"[Array of String]\") {\n         when(it){\n               is ChargebeeResult.Success -\u003e{\n                    Log.i(TAG, \"subscription list in array:  ${it}\")\n                    Log.i(TAG, \"subscription status:  ${it?.get(0)?.cb_subscription?.status}\")\n               }\n               is ChargebeeResult.Error -\u003e{\n                    Log.e(TAG, \"Error :  ${it.exp.message}\")\n                    // Handle error here\n               }\n         }\n  }\n  ```\n  \n  For example, query parameters can be passed as ***\"customer_id\" : \"id\"***, ***\"subscription_id\": \"id\"***, or ***\"status\": \"active\"***.\n  \n  ##### Get Subscription Status for Existing Subscribers using Subscription ID\n  \n  Use only Subscription ID for checking the Subscription status on Chargebee and confirm the access - granted or denied.\n  \n  ```kotlin\n  Chargebee.retrieveSubscription(subscriptionId) {\n         when(it){\n               is ChargebeeResult.Success -\u003e{\n                    Log.i(TAG, \"subscription status:  ${it.status}\")\n               }\n               is ChargebeeResult.Error -\u003e{\n                    Log.e(TAG, \"Error :  ${it.exp.message}\")\n                    // Handle error here\n               }\n         }\n  }\n  ```\n\n  ##### Returns Plan Object\n\n  These functions return the plan ID associated with a subscription. You can associate JSON metadata with the Google Play Store plans in Chargebee and retrieve the same by passing plan ID to the SDK method - [retrievePlan](https://github.com/chargebee/chargebee-android#get-plan-details)(PC 1.0) or [retrieveItem](https://github.com/chargebee/chargebee-android#get-item-details)(PC 2.0).\n\n  #### Retrieve Entitlements of a Subscription\n\n  Use the Subscription ID for fetching the list of [entitlements](https://www.chargebee.com/docs/2.0/entitlements.html) associated with the subscription.\n\n  ```kotlin\n  Chargebee.retrieveEntitlements(subscriptionId) {\n      when(it){\n            is ChargebeeResult.Success -\u003e {\n                Log.i(TAG, \"Response:  ${(it.data)}\") \n            }\n            is ChargebeeResult.Error -\u003e{\n                Log.e(TAG, \"Error :  ${it.exp.message}\")\n                // Handle error here\n           }\n     }\n  }  \n  ```\n\n  **Note**: Entitlements feature is available only if your Chargebee site is on [Product Catalog 2.0](https://www.chargebee.com/docs/2.0/product-catalog.html).\n\n  ### Integrating credit card tokenization\n  \n  The following section describes how to use the SDK to directly tokenize credit card information if you are NOT REQUIRED to use Google's in-app purchases.\n  \n  #### Product Catalog 2.0\n  \n  If you are using Product Catalog 2.0 on your Chargebee site, then use the following functions to retrieve the product to be presented for users to purchase.\n  \n  ##### Get all Items\n  \n  Retrieve the list of items by using the following function.\n  \n  ```kotlin\n  Chargebee.retrieveAllItems(queryParam) {\n         when (it) {\n             is ChargebeeResult.Success -\u003e {\n                   Log.i(javaClass.simpleName, \"list items :  ${it.data}\")\n             }\n             is ChargebeeResult.Error -\u003e {\n                   Log.d(javaClass.simpleName, \"Error :  ${it.exp.message}\")\n             }\n         }\n  }\n  ```\n  \n  For example, query parameters can be passed as **\"sort_by[desc]\" : \"name\"** or **\"limit\": \"100\"**.\n  \n  ##### Get Item Details\n  \n  Retrieve specific item details by using the following function. Use the Item ID you received from the previous function - Get all items.\n  \n  ```kotlin\n  Chargebee.retrieveItem(queryParam) {\n         when (it) {\n             is ChargebeeResult.Success -\u003e {\n                   Log.i(javaClass.simpleName, \"item details :  ${it.data}\")\n             }\n             is ChargebeeResult.Error -\u003e {\n                   Log.d(javaClass.simpleName, \"Error :  ${it.exp.message}\")\n             }\n         }\n  }\n  ```\n  \n  #### Product Catalog 1.0\n  \n  If you are using Product Catalog 1.0 on your Chargebee site, then use any of the following relevant functions to retrieve the product to be presented for users to purchase.\n  \n  ##### Get All Plans\n  \n  Retrieve the list of plans by using the following function.\n  \n  ```kotlin\n  Chargebee.retrieveAllPlans(queryParam) {\n         when (it) {\n             is ChargebeeResult.Success -\u003e {\n                   Log.i(javaClass.simpleName, \"list Plans :  ${it.data}\")\n             }\n             is ChargebeeResult.Error -\u003e {\n                   Log.d(javaClass.simpleName, \"Error :  ${it.exp.message}\")\n             }\n         }\n  }\n  ```\n  \n  For example, query parameters can be passed as **\"sort_by[desc]\" : \"name\"** or **\"limit\": \"100\"**.\n  \n  ##### Get Plan Details\n  \n  Retrieve specific plan details by passing plan ID in the following function.\n  \n  ```kotlin\n  Chargebee.retrievePlan(queryParam) {\n         when (it) {\n             is ChargebeeResult.Success -\u003e {\n                   Log.i(javaClass.simpleName, \"Plan details :  ${it.data}\")\n             }\n             is ChargebeeResult.Error -\u003e {\n                   Log.d(javaClass.simpleName, \"Error :  ${it.exp.message}\")\n             }\n         }\n  }\n  ```\n  \n  ##### Get Addon Details\n  \n  You can retrieve specific addon details by passing addon ID in the following function.\n  \n  ```kotlin\n  Chargebee.retrieve(\"addonId\") { addonResult -\u003e\n      try {\n          val addon = addonResult.getData()\n          Log.d(\"success\", addon.toString())\n          // Use addon details here\n      } catch (ex: CBException) {\n          Log.d(\"error\", ex.getMessage());\n          // Handle error here\n      }\n  }\n  ```\n  \n  ### Get Payment Token\n  \n  Once the user selects the product to purchase, and you collect the credit card information, use the following function to tokenize the credit card details against Stripe. You need to have connected your Stripe account to your Chargebee site.\n  \n  ```kotlin\n  val card = Card(\n      number = \"4321567890123456\",\n      expiryMonth = \"12\",\n      expiryYear = \"29\",\n      cvc = \"123\")\n  val paymentDetail = PaymentDetail(\n      currencyCode = \"USD\",\n      type = PaymentMethodType.CARD,\n      card = card)\n  Chargebee.createTempToken(paymentDetail) { tokenResult -\u003e\n      try {\n          val cbTempToken = tokenResult.getData()\n          Log.d(\"success\", cbTempToken)\n          // Use token here\n      } catch (ex: PaymentException) {\n          Log.d(\"error payment\", ex.toString())\n          // Handle PaymentException here\n      } catch (ex: InvalidRequestException) {\n          Log.d(\"error invalid\", ex.toString())\n          // Handle InvalidRequestException here\n      } catch (ex: OperationFailedException) {\n          Log.d(\"error operation\", ex.toString())\n          // Handle OperationFailedException here\n      }\n  }\n  ```\n  \n  ### Use the Chargebee Token\n  \n  Once your customer's card data is processed and stored and a Chargebee token reference is returned to you, use the token in subsequent API calls to process transactions.\n  \n  The following are some endpoints that accept Chargebee tokens for processing.\n  \n  -   [Create a Payment Source for the customer](https://apidocs.chargebee.com/docs/api/payment_sources#create_using_chargebee_token)\n  -   [Create a Subscription](https://apidocs.chargebee.com/docs/api/subscriptions#create_a_subscription)\n  -   [Update a Subscription](https://apidocs.chargebee.com/docs/api/subscriptions#update_a_subscription)\n  \n  Please refer to the [Chargebee API Docs](https://apidocs.chargebee.com/docs/api) for subsequent integration steps.\n  \n  License\n  -------\n  \n  Chargebee is available under the [MIT license](https://opensource.org/licenses/MIT). For more information, see the LICENSE file.\n  \n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchargebee%2Fchargebee-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchargebee%2Fchargebee-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchargebee%2Fchargebee-android/lists"}