diff --git a/README.md b/README.md index 49b9068..170d362 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.21' +implementation 'com.chargebee:chargebee-android:1.0.22' ``` ## Example project @@ -474,7 +474,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.21' + implementation 'com.chargebee:chargebee-android:1.0.22' ``` Example project --------------- diff --git a/chargebee/build.gradle b/chargebee/build.gradle index 1d0961b..252996f 100644 --- a/chargebee/build.gradle +++ b/chargebee/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 21 targetSdkVersion 30 versionCode 1 - versionName "1.0.21" + versionName "1.0.22" 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 b827ac7..ce7912b 100644 --- a/chargebee/src/main/java/com/chargebee/android/billingservice/BillingClientManager.kt +++ b/chargebee/src/main/java/com/chargebee/android/billingservice/BillingClientManager.kt @@ -398,6 +398,13 @@ class BillingClientManager(context: Context) : PurchasesUpdatedListener { ) ) + private fun itemNotOwnedException(): CBException { + return CBException(ErrorDetail( + message = BillingErrorCode.ITEM_NOT_OWNED.message, + httpStatusCode = BillingErrorCode.ITEM_NOT_OWNED.code + )) + } + private fun queryPurchaseHistoryFromStore( connectionStatus: Boolean ) { @@ -517,7 +524,10 @@ class BillingClientManager(context: Context) : PurchasesUpdatedListener { } } - internal fun validateReceiptWithChargebee(product: CBProduct, completionCallback: CBCallback.PurchaseCallback ) { + internal fun validateReceiptWithChargebee( + product: CBProduct, + completionCallback: CBCallback.PurchaseCallback + ) { this.purchaseCallBack = completionCallback onConnected({ status -> if (status) @@ -525,7 +535,13 @@ class BillingClientManager(context: Context) : PurchasesUpdatedListener { val purchaseTransaction = purchaseHistoryList.filter { it.productId.first() == product.productId } - validateReceipt(purchaseTransaction.first().purchaseToken, product) + val transaction = purchaseTransaction.firstOrNull() + transaction?.let { + validateReceipt(transaction.purchaseToken, product) + } ?: run { + completionCallback.onError(itemNotOwnedException()) + } + } else completionCallback.onError( connectionError @@ -582,14 +598,24 @@ class BillingClientManager(context: Context) : PurchasesUpdatedListener { } } - internal fun validateNonSubscriptionReceiptWithChargebee(product: CBProduct, completionCallback: CBCallback.OneTimePurchaseCallback) { + internal fun validateNonSubscriptionReceiptWithChargebee( + product: CBProduct, + completionCallback: CBCallback.OneTimePurchaseCallback + ) { + this.oneTimePurchaseCallback = completionCallback onConnected({ status -> if (status) queryPurchaseHistory { purchaseHistoryList -> val purchaseTransaction = purchaseHistoryList.filter { it.productId.first() == product.productId } - validateNonSubscriptionReceipt(purchaseTransaction.first().purchaseToken, product) + val transaction = purchaseTransaction.firstOrNull() + transaction?.let { + validateNonSubscriptionReceipt(transaction.purchaseToken, product) + } ?: run { + completionCallback.onError(itemNotOwnedException()) + } + } else completionCallback.onError( connectionError