diff --git a/README.md b/README.md
index fde8c79..eee687e 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ The following requirements must be set up before installing Chargebee’s Androi
The `Chargebee-Android` SDK can be installed by adding below dependency to the `build.gradle` file:
```kotlin
-implementation 'com.chargebee:chargebee-android:1.0.8'
+implementation 'com.chargebee:chargebee-android:1.0.9'
```
## Example project
@@ -347,7 +347,7 @@ Chargebee is available under the [MIT license](https://opensource.org/licenses/M
To install Chargebee's Android SDK, add the following dependency to the build.gradle file.
```
- implementation 'com.chargebee:chargebee-android:1.0.8'
+ implementation 'com.chargebee:chargebee-android:1.0.9'
```
Example project
---------------
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 89f51ce..36a7f0b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -22,6 +22,7 @@
+
diff --git a/app/src/main/java/com/chargebee/example/MainActivity.kt b/app/src/main/java/com/chargebee/example/MainActivity.kt
index 87700ba..ba2a8f8 100644
--- a/app/src/main/java/com/chargebee/example/MainActivity.kt
+++ b/app/src/main/java/com/chargebee/example/MainActivity.kt
@@ -27,6 +27,8 @@ import com.chargebee.example.items.ItemActivity
import com.chargebee.example.items.ItemsActivity
import com.chargebee.example.plan.PlanInJavaActivity
import com.chargebee.example.plan.PlansActivity
+import com.chargebee.example.plan.UpgradePlanActivity
+import com.chargebee.example.util.Constants.PRICE_KEY
import com.chargebee.example.subscription.SubscriptionActivity
import com.chargebee.example.token.TokenizeActivity
import com.chargebee.example.util.CBMenu
@@ -124,6 +126,15 @@ class MainActivity : BaseActivity(), ListItemsAdapter.ItemClickListener {
val intent = Intent(this, SubscriptionActivity::class.java)
startActivity(intent)
}
+ CBMenu.UpgradePlan.value -> {
+ val intent = Intent(this, UpgradePlanActivity::class.java)
+ startActivity(intent)
+ }
+ CBMenu.PriceChange.value -> {
+ val intent = Intent(this, UpgradePlanActivity::class.java)
+ intent.putExtra(PRICE_KEY, "priceChange")
+ startActivity(intent)
+ }
else ->{
Log.i(javaClass.simpleName, " Not implemented" )
}
diff --git a/app/src/main/java/com/chargebee/example/billing/BillingViewModel.kt b/app/src/main/java/com/chargebee/example/billing/BillingViewModel.kt
index f175266..f48a647 100644
--- a/app/src/main/java/com/chargebee/example/billing/BillingViewModel.kt
+++ b/app/src/main/java/com/chargebee/example/billing/BillingViewModel.kt
@@ -1,5 +1,6 @@
package com.chargebee.example.billing
+import android.content.Context
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
@@ -25,6 +26,8 @@ class BillingViewModel : ViewModel() {
var subscriptionList: MutableLiveData?> = MutableLiveData()
var error: MutableLiveData = MutableLiveData()
private var subscriptionId: String = ""
+ var updateProductPurchaseResult: MutableLiveData = MutableLiveData()
+ var priceChangeLiveData: MutableLiveData = MutableLiveData()
fun purchaseProduct(product: CBProduct, customerID: String) {
@@ -102,4 +105,80 @@ class BillingViewModel : ViewModel() {
}
}
}
+
+ fun updatePurchase(productIdList: ArrayList, oldPurchaseToken: String, context: Context){
+ CBPurchase.retrieveProducts(context,
+ productIdList,object : CBCallback.ListProductsCallback>{
+ override fun onSuccess(productIDs: ArrayList) {
+ if (productIDs.size > 0) {
+ CBPurchase.updateProduct(context, productIDs.first(),oldPurchaseToken, object : CBCallback.PurchaseCallback{
+ override fun onSuccess(purchaseToken: String, status:Boolean) {
+ Log.i(TAG, "purchaseToken: $purchaseToken")
+ updateProductPurchaseResult.postValue(purchaseToken)
+ }
+ override fun onError(error: CBException) {
+ try {
+ cbException.postValue(error.message)
+ }catch (exp: Exception){
+ Log.i(TAG, "Exception :${exp.message}")
+ }
+ }
+
+ })
+ } else {
+ Log.i(javaClass.simpleName,"Product id not found in Google Play")
+ cbException.postValue("Product id not found in Google Play")
+ }
+ }
+
+ override fun onError(error: CBException) {
+ Log.e(javaClass.simpleName, "Error: ${error.message}")
+ try {
+ cbException.postValue(error.message)
+ }catch (exp: Exception){
+ Log.e(TAG, "Exception :${exp.message}")
+ }
+ }
+
+ })
+
+ }
+
+ fun priceChangeUpdate(productIdList: ArrayList, context: Context){
+ CBPurchase.retrieveProducts(
+ context,
+ productIdList,
+ object : CBCallback.ListProductsCallback> {
+ override fun onSuccess(productIDs: ArrayList) {
+ if (productIDs.size > 0) {
+ CBPurchase.priceChangeConfirmation(productIDs.first(), object: CBCallback.PriceChangeCallback{
+ override fun onSuccess(response: String) {
+ priceChangeLiveData.postValue(response)
+ }
+
+ override fun onError(error: CBException) {
+ Log.e(javaClass.simpleName,"Error in Price Change: ${error.message}")
+ try {
+ cbException.postValue(error.message)
+ }catch (exp: Exception){
+ Log.i(TAG, "Exception :${exp.message}")
+ }
+ }
+
+ })
+ } else {
+ Log.i(javaClass.simpleName,"Product id not found in Google Play")
+ cbException.postValue("Product id not found in Google Play")
+ }
+ }
+ override fun onError(error: CBException) {
+ Log.e(javaClass.simpleName, "Error: ${error.message}")
+ try {
+ cbException.postValue(error.message)
+ }catch (exp: Exception){
+ Log.e(TAG, "Exception :${exp.message}")
+ }
+ }
+ })
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/chargebee/example/plan/UpgradePlanActivity.kt b/app/src/main/java/com/chargebee/example/plan/UpgradePlanActivity.kt
new file mode 100644
index 0000000..165c521
--- /dev/null
+++ b/app/src/main/java/com/chargebee/example/plan/UpgradePlanActivity.kt
@@ -0,0 +1,88 @@
+package com.chargebee.example.plan
+
+import android.content.Context
+import android.os.Bundle
+import android.text.TextUtils
+import android.util.Log
+import android.view.View
+import android.widget.Button
+import android.widget.TextView
+import androidx.lifecycle.Observer
+import com.chargebee.example.BaseActivity
+import com.chargebee.example.R
+import com.chargebee.example.billing.BillingActivity
+import com.chargebee.example.billing.BillingViewModel
+import com.chargebee.example.util.Constants
+import com.google.android.material.textfield.TextInputEditText
+import com.google.android.material.textfield.TextInputLayout
+
+class UpgradePlanActivity : BaseActivity() {
+
+ private var mBillingViewModel : BillingViewModel? = null
+ private lateinit var mProductIdInput: TextInputEditText
+ private lateinit var mPurchaseTokenInput: TextInputEditText
+ private lateinit var mBuyProductButton: Button
+ private lateinit var mPriceChangeButton: Button
+ private lateinit var mPurchaseTokenInputLayout: TextInputLayout
+ private lateinit var mTvPriceChange: TextView
+ lateinit var context: Context
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_upgradeplan)
+ context = this
+ mBillingViewModel = BillingViewModel()
+ mProductIdInput = findViewById(R.id.productIdInput)
+ mPurchaseTokenInput = findViewById(R.id.purchaseTokenInput)
+ mBuyProductButton = findViewById(R.id.buyBtn)
+ mPriceChangeButton = findViewById(R.id.btnpricechange)
+ mPurchaseTokenInputLayout = findViewById(R.id.purchaseTokenInputLayout)
+ mTvPriceChange = findViewById(R.id.textView)
+
+ val priceChange = intent.getStringExtra(Constants.PRICE_KEY)
+ if(priceChange !=null){
+ mPurchaseTokenInputLayout.visibility = View.GONE
+ mBuyProductButton.visibility = View.GONE
+ mTvPriceChange.text = "Plan Price Change"
+
+ }else{
+ mPurchaseTokenInputLayout.visibility = View.VISIBLE
+ mPriceChangeButton.visibility = View.GONE
+ mTvPriceChange.text = "Plan Upgrade/Downgrade"
+
+ }
+
+ this.mBillingViewModel!!.updateProductPurchaseResult.observeForever{
+ hideProgressDialog()
+ if (!TextUtils.isEmpty(it))
+ alertSuccess(it)
+ }
+
+ this.mBillingViewModel!!.priceChangeLiveData.observeForever{
+ hideProgressDialog()
+ if (!TextUtils.isEmpty(it))
+ alertSuccess(it)
+ }
+ this.mBillingViewModel!!.cbException.observeForever{
+ if (!TextUtils.isEmpty(it))
+ alertSuccess(it)
+ }
+
+ mBuyProductButton.setOnClickListener{
+ var productId = mProductIdInput.text.toString()
+ val purchaseToken = mPurchaseTokenInput.text.toString()
+
+ val array = arrayListOf(productId)
+ this.mBillingViewModel!!.updatePurchase(array, purchaseToken, context)
+ }
+
+ mPriceChangeButton.setOnClickListener{
+ var productId = mProductIdInput.text.toString()
+ val productIdList = ArrayList()
+ productIdList.add(productId)
+ this.mBillingViewModel!!.priceChangeUpdate(productIdList, context)
+
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/chargebee/example/util/CBMenu.kt b/app/src/main/java/com/chargebee/example/util/CBMenu.kt
index 630d5f5..cc3ed1e 100644
--- a/app/src/main/java/com/chargebee/example/util/CBMenu.kt
+++ b/app/src/main/java/com/chargebee/example/util/CBMenu.kt
@@ -11,6 +11,8 @@ enum class CBMenu(val value: String) {
ProductIDs("Get Google Play Product Identifiers"),
GetProducts("Get Products"),
SubsStatus("Get Subscription Status"),
- SubsList("Get Subscriptions List")
+ SubsList("Get Subscriptions List"),
+ UpgradePlan("Upgrade/Downgrade Plan"),
+ PriceChange("Price Change")
}
diff --git a/app/src/main/java/com/chargebee/example/util/Constants.kt b/app/src/main/java/com/chargebee/example/util/Constants.kt
index 700be5d..01f4dbe 100644
--- a/app/src/main/java/com/chargebee/example/util/Constants.kt
+++ b/app/src/main/java/com/chargebee/example/util/Constants.kt
@@ -2,4 +2,5 @@ package com.chargebee.example.util
object Constants {
const val PRODUCTS_LIST_KEY = "products"
+ const val PRICE_KEY = "priceChange"
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_upgradeplan.xml b/app/src/main/res/layout/activity_upgradeplan.xml
new file mode 100644
index 0000000..ecf3901
--- /dev/null
+++ b/app/src/main/res/layout/activity_upgradeplan.xml
@@ -0,0 +1,78 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/chargebee/build.gradle b/chargebee/build.gradle
index 2077b11..f8407f0 100644
--- a/chargebee/build.gradle
+++ b/chargebee/build.gradle
@@ -9,7 +9,7 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
- versionName "1.0.8"
+ versionName "1.0.9"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
diff --git a/chargebee/src/main/java/com/chargebee/android/billingservice/BillingClientManager.kt b/chargebee/src/main/java/com/chargebee/android/billingservice/BillingClientManager.kt
index 33227de..e3b6ad7 100644
--- a/chargebee/src/main/java/com/chargebee/android/billingservice/BillingClientManager.kt
+++ b/chargebee/src/main/java/com/chargebee/android/billingservice/BillingClientManager.kt
@@ -7,6 +7,7 @@ import android.os.Looper
import android.text.TextUtils
import android.util.Log
import com.android.billingclient.api.*
+import com.android.billingclient.api.BillingClient.BillingResponseCode.*
import com.chargebee.android.ErrorDetail
import com.chargebee.android.exceptions.CBException
import com.chargebee.android.exceptions.ChargebeeResult
@@ -28,9 +29,11 @@ class BillingClientManager constructor(
private var callBack : CBCallback.ListProductsCallback>
private var purchaseCallBack: CBCallback.PurchaseCallback? = null
private val skusWithSkuDetails = arrayListOf()
- private val TAG = "BillingClientManager"
+ private val TAG = javaClass.simpleName
var customerID : String = ""
lateinit var product: CBProduct
+ var oldPurchaseToken: String? = null
+ lateinit var newSkuDetails: SkuDetails
init {
mContext = context
@@ -52,7 +55,7 @@ class BillingClientManager constructor(
BillingClient.BillingResponseCode.OK -> {
Log.i(
TAG,
- "onBillingSetupFinished() -> successfully for ${billingClient.toString()}."
+ "Google Billing Setup Done!"
)
loadProductDetails(BillingClient.SkuType.SUBS, skuList, callBack)
}
@@ -79,7 +82,6 @@ class BillingClientManager constructor(
TAG,
"onBillingSetupFinished() -> Client is already in the process of connecting to billing service"
)
-
}
else -> {
Log.i(TAG, "onBillingSetupFinished -> with error: ${billingResult.debugMessage}.")
@@ -119,7 +121,7 @@ class BillingClientManager constructor(
.setType(skuType)
.build()
- queryAllPurchases()
+ // queryAllPurchases()
billingClient.querySkuDetailsAsync(
params
@@ -140,7 +142,7 @@ class BillingClientManager constructor(
Log.i(TAG, "Product details :$skusWithSkuDetails")
callBack.onSuccess(productIDs = skusWithSkuDetails)
}catch (ex: CBException){
- callBack.onError(CBException(ErrorDetail(GPErrorCode.UnknownError.errorMsg)))
+ callBack.onError(CBException(ErrorDetail(billingResult.debugMessage)))
Log.e(TAG, "exception :" + ex.message)
}
}else{
@@ -152,7 +154,6 @@ class BillingClientManager constructor(
Log.e(TAG, "exception :$exp.message")
callBack.onError(CBException(ErrorDetail("${exp.message}")))
}
-
}
/* Purchase the product: Initiates the billing flow for an In-app-purchase */
@@ -176,8 +177,8 @@ class BillingClientManager constructor(
.takeIf { billingResult -> billingResult.responseCode != BillingClient.BillingResponseCode.OK
}?.let { billingResult ->
Log.e(TAG, "Failed to launch billing flow $billingResult")
+ purchaseCallBack.onError(CBException(ErrorDetail(GPErrorCode.LaunchBillingFlowError.errorMsg)))
}
-
}
/* Checks if the specified feature is supported by the Play Store */
@@ -206,7 +207,7 @@ class BillingClientManager constructor(
/* Google Play calls this method to deliver the result of the Purchase Process/Operation */
override fun onPurchasesUpdated(billingResult: BillingResult, purchases: MutableList?) {
when (billingResult.responseCode) {
- BillingClient.BillingResponseCode.OK -> {
+ OK -> {
purchases?.forEach { purchase ->
when (purchase.purchaseState) {
Purchase.PurchaseState.PURCHASED -> {
@@ -221,29 +222,41 @@ class BillingClientManager constructor(
}
}
}
- BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> {
- Log.e(TAG, "onPurchasesUpdated: ITEM_ALREADY_OWNED")
+ ITEM_ALREADY_OWNED -> {
+ Log.e(TAG, "Billing response code : ITEM_ALREADY_OWNED")
purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.ProductAlreadyOwned.errorMsg)))
}
- BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> {
+ SERVICE_DISCONNECTED -> {
connectToBillingService()
}
- BillingClient.BillingResponseCode.ITEM_UNAVAILABLE -> {
- Log.e(TAG, "onPurchasesUpdated: ITEM_UNAVAILABLE")
+ ITEM_UNAVAILABLE -> {
+ Log.e(TAG, "Billing response code : ITEM_UNAVAILABLE")
purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.ProductUnavailable.errorMsg)))
}
- BillingClient.BillingResponseCode.USER_CANCELED ->{
- Log.e(TAG, "onPurchasesUpdated : USER_CANCELED ")
+ USER_CANCELED ->{
+ Log.e(TAG, "Billing response code : USER_CANCELED ")
purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.CanceledPurchase.errorMsg)))
}
- BillingClient.BillingResponseCode.ITEM_NOT_OWNED ->{
- Log.e(TAG, "onPurchasesUpdated : ITEM_NOT_OWNED ")
+ ITEM_NOT_OWNED ->{
+ Log.e(TAG, "Billing response code : ITEM_NOT_OWNED ")
purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.ProductNotOwned.errorMsg)))
}
- else -> {
- Log.e(TAG, "Failed to PurchasesUpdated"+billingResult.responseCode)
+ SERVICE_TIMEOUT -> {
+ Log.e(TAG, "Billing response code :SERVICE_TIMEOUT ")
+ purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.PlayServiceTimeOut.errorMsg)))
+ }
+ SERVICE_UNAVAILABLE -> {
+ Log.e(TAG, "Billing response code: SERVICE_UNAVAILABLE")
+ purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.PlayServiceUnavailable.errorMsg)))
+ }
+ ERROR -> {
+ Log.e(TAG, "Billing response code: ERROR")
purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.UnknownError.errorMsg)))
}
+ DEVELOPER_ERROR -> {
+ Log.e(TAG, "Billing response code: DEVELOPER_ERROR")
+ purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.DeveloperError.errorMsg)))
+ }
}
}
@@ -264,7 +277,13 @@ class BillingClientManager constructor(
Log.i(TAG, "Purchase Token -${purchase.purchaseToken}")
billingClient.endConnection()
- validateReceipt(purchase.purchaseToken, product)
+ if(TextUtils.isEmpty(oldPurchaseToken) && oldPurchaseToken ==null){
+ validateReceipt(purchase.purchaseToken, product)
+ }else{
+ purchaseCallBack?.onSuccess(purchase.purchaseToken, true)
+ oldPurchaseToken = null
+ }
+
}
} catch (ex: CBException) {
@@ -342,4 +361,61 @@ class BillingClientManager constructor(
}
}
}
+ /* Update Purchases on existing plan */
+ fun updatePurchaseFlow(context: Context, skuDetails: SkuDetails, oldPurchaseToken: String, updateCallBack : CBCallback.PurchaseCallback) {
+ Log.i(TAG, "oldPurchaseToken : $oldPurchaseToken")
+ this.purchaseCallBack = updateCallBack
+ this.oldPurchaseToken = oldPurchaseToken
+ val updateParams = oldPurchaseToken.let {
+ BillingFlowParams.SubscriptionUpdateParams.newBuilder()
+ .setOldSkuPurchaseToken(it.trim())
+ .setReplaceSkusProrationMode(BillingFlowParams.ProrationMode.IMMEDIATE_WITH_TIME_PRORATION)
+ .build()
+ }
+
+ val billingFlowParams = updateParams.let {
+ BillingFlowParams.newBuilder()
+ .setSkuDetails(skuDetails)
+ .setSubscriptionUpdateParams(it)
+ .build()
+ }
+ billingClient.launchBillingFlow(mContext as Activity, billingFlowParams)
+ .takeIf { billingResult -> billingResult.responseCode != BillingClient.BillingResponseCode.OK
+ }?.let { billingResult ->
+ Log.e(TAG, "Failed to launch billing flow $billingResult")
+ purchaseCallBack?.onError(CBException(ErrorDetail(GPErrorCode.LaunchBillingFlowError.errorMsg)))
+ }
+
+ }
+ /* This method will handle the Price Change confirmation with Google play */
+ fun priceChangeConfirmationFlow(cbProduct: CBProduct, priceChangeCallBack: CBCallback.PriceChangeCallback){
+ val priceChangeParams = PriceChangeFlowParams.newBuilder()
+ .setSkuDetails(cbProduct.skuDetails)
+ .build()
+ billingClient.launchPriceChangeConfirmationFlow(mContext as Activity, priceChangeParams) {
+ billingResult ->
+ when(billingResult.responseCode){
+ BillingClient.BillingResponseCode.OK ->{
+ Log.i(TAG, "User has accepted/Confirmed Price change")
+ Log.i(TAG, billingResult.debugMessage)
+ if (billingResult.debugMessage.isEmpty())
+ priceChangeCallBack.onError(CBException(ErrorDetail("Success")))
+ else
+ priceChangeCallBack.onError(CBException(ErrorDetail(billingResult.debugMessage)))
+ }
+ BillingClient.BillingResponseCode.USER_CANCELED,
+ BillingClient.BillingResponseCode.SERVICE_DISCONNECTED,
+ BillingClient.BillingResponseCode.SERVICE_TIMEOUT,
+ BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE,
+ BillingClient.BillingResponseCode.DEVELOPER_ERROR,
+ BillingClient.BillingResponseCode.ERROR ->{
+ if (billingResult.debugMessage.isEmpty())
+ priceChangeCallBack.onError(CBException(ErrorDetail(GPErrorCode.UnknownError.errorMsg)))
+ else
+ priceChangeCallBack.onError(CBException(ErrorDetail(billingResult.debugMessage)))
+ }
+ }
+
+ }
+ }
}
diff --git a/chargebee/src/main/java/com/chargebee/android/billingservice/CBCallback.kt b/chargebee/src/main/java/com/chargebee/android/billingservice/CBCallback.kt
index 5f05fe3..9826eea 100644
--- a/chargebee/src/main/java/com/chargebee/android/billingservice/CBCallback.kt
+++ b/chargebee/src/main/java/com/chargebee/android/billingservice/CBCallback.kt
@@ -17,4 +17,8 @@ interface CBCallback {
fun onError(error: CBException)
}
+ interface PriceChangeCallback {
+ fun onSuccess(response: String)
+ fun onError(error: CBException)
+ }
}
\ No newline at end of file
diff --git a/chargebee/src/main/java/com/chargebee/android/billingservice/CBPurchase.kt b/chargebee/src/main/java/com/chargebee/android/billingservice/CBPurchase.kt
index c1cffa2..7bc23c7 100644
--- a/chargebee/src/main/java/com/chargebee/android/billingservice/CBPurchase.kt
+++ b/chargebee/src/main/java/com/chargebee/android/billingservice/CBPurchase.kt
@@ -45,6 +45,15 @@ object CBPurchase {
callBack.onError(ex)
}
}
+ @JvmStatic
+ fun updateProduct(context: Context, cbProduct: CBProduct,oldPurchaseToken:String, callBack : CBCallback.PurchaseCallback ) {
+ try {
+ billingClientManager?.updatePurchaseFlow(context,cbProduct.skuDetails,oldPurchaseToken, callBack)
+ }catch (ex: CBException){
+ Log.i(javaClass.simpleName, "Exception in updateProduct ")
+ callBack.onError(ex)
+ }
+ }
/* Buy the product with/without customer Id */
@JvmStatic
fun purchaseProduct(
@@ -54,10 +63,14 @@ object CBPurchase {
CBAuthentication.isSDKKeyValid(Chargebee.sdkKey){
when(it){
is ChargebeeResult.Success -> {
- if (billingClientManager?.isBillingClientReady() == true && billingClientManager?.isFeatureSupported() == true) {
- billingClientManager?.purchase(product, customerID, callback)
- } else {
- callback.onError(CBException(ErrorDetail("Play services not available")))
+ if (billingClientManager?.isFeatureSupported() == true) {
+ if (billingClientManager?.isBillingClientReady() == true) {
+ billingClientManager?.purchase(product, customerID, callback)
+ } else {
+ callback.onError(CBException(ErrorDetail(GPErrorCode.BillingClientNotReady.errorMsg)))
+ }
+ }else {
+ callback.onError(CBException(ErrorDetail(GPErrorCode.FeatureNotSupported.errorMsg)))
}
}
is ChargebeeResult.Error ->{
@@ -220,4 +233,13 @@ object CBPurchase {
return list.toTypedArray()
}
+ fun priceChangeConfirmation(cbProduct: CBProduct, priceChangeCallBack: CBCallback.PriceChangeCallback){
+ try {
+ billingClientManager?.priceChangeConfirmationFlow(cbProduct, priceChangeCallBack)
+ }catch (ex: CBException){
+ Log.i(javaClass.simpleName, "Exception in priceChangeConfirmation ")
+ priceChangeCallBack.onError(ex)
+ }
+ }
+
}
\ No newline at end of file
diff --git a/chargebee/src/main/java/com/chargebee/android/billingservice/GPErrorCode.kt b/chargebee/src/main/java/com/chargebee/android/billingservice/GPErrorCode.kt
index 4b45854..edcd27a 100644
--- a/chargebee/src/main/java/com/chargebee/android/billingservice/GPErrorCode.kt
+++ b/chargebee/src/main/java/com/chargebee/android/billingservice/GPErrorCode.kt
@@ -1,22 +1,21 @@
package com.chargebee.android.billingservice
enum class GPErrorCode(val errorMsg: String) {
- UnknownError("Unknown error"),
- PlayStoreError("There was an issue with the Play Store service"),
- BillingUnavailable("The Billing service is unavailable on the device"),
- PurchasePending("Purchase is pending"),
+
+ BillingUnavailable("The Billing API version is not supported"),
+ PurchasePending("Purchase is in pending state"),
PurchaseUnspecified("Unspecified state of the purchase"),
PurchaseInvalid("Failure of purchase"),
PurchaseReceiptNotFound("Receipt not found"),
- CanceledPurchase("User pressed back or canceled a dialog for purchase"),
+ CanceledPurchase("User pressed back or canceled a dialog"),
ProductNotOwned("Failure to consume purchase since item is not owned"),
ProductAlreadyOwned("Failure to purchase since item is already owned"),
- FeatureNotSupported("The requested feature is not supported"),
- ProductUnavailable("Requested product is not available for purchase or its SKU was not found"),
- ParseResponseFailed("A problem occurred when serializing or deserializing data"),
- ProductNotFound("Failure to purchase since the Chargebee product was not found"),
- LaunchError("There was an error on launching Chargebee SDK"),
- SkuDetailsError("Failure to retrieve SkuDetails for the in-app product ID"),
- InvalidCredentials("SDK key is invalid or not set"),
- InvalidClientUid("Client Uid is invalid or not set"),
+ FeatureNotSupported("The requested feature is not supported by Play Store on the current device"),
+ ProductUnavailable("Requested product is not available for purchase"),
+ PlayServiceTimeOut("The request has reached the maximum timeout before Google Play responds"),
+ PlayServiceUnavailable("Network connection is down"),
+ LaunchBillingFlowError("Failed to launch billing flow, try again later"),
+ UnknownError("Fatal error during the API action"),
+ DeveloperError("Invalid arguments provided to the API"),
+ BillingClientNotReady("Play services not available"),
}
\ No newline at end of file