Skip to content

Commit

Permalink
Jitpack Version: 3.0.3
Browse files Browse the repository at this point in the history
- Removed deprecated code (enablePendingPurchases from billing v7
- Fixed fetching purchases issue upon any single purchase/upgrade
  • Loading branch information
epegasus committed Jan 20, 2025
1 parent 4ac5aac commit c9e34f6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
*.iml
.gradle
.idea
.idea/caches
.idea/inspectionProfiles
.idea/AndroidProjectSystem.xml
.idea/appInsightsSettings.xml
.idea/compiler.xml
.idea/deploymentTargetDropDown.xml
.idea/deploymentTargetSelector.xml
.idea/gradle.xml
.idea/kotlinc.xml
.idea/migrations.xml
.idea/misc.xml
.idea/runConfigurations.xml
.idea/vcs.xml
.idea/workspace.xml
.DS_Store
/local.properties
/build
Expand Down
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.android.billingclient.api.BillingClientStateListener
import com.android.billingclient.api.BillingFlowParams
import com.android.billingclient.api.BillingResult
import com.android.billingclient.api.ConsumeParams
import com.android.billingclient.api.PendingPurchasesParams
import com.android.billingclient.api.ProductDetails
import com.android.billingclient.api.Purchase
import com.android.billingclient.api.PurchasesUpdatedListener
Expand All @@ -27,6 +28,7 @@ import com.hypersoft.billing.extensions.toFormattedDate
import com.hypersoft.billing.interfaces.OnPurchaseListener
import com.hypersoft.billing.states.Result
import com.hypersoft.billing.utils.QueryUtils
import com.hypersoft.billing.utils.ValidationUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -48,12 +50,12 @@ open class BillingRepository(context: Context) {
private val billingClient by lazy {
BillingClient.newBuilder(context)
.setListener(purchasesListener)
.enablePendingPurchases()
.enablePendingPurchases(PendingPurchasesParams.newBuilder().enableOneTimeProducts().build())
.build()
}

private val queryUtils: QueryUtils by lazy { QueryUtils(billingClient) }
private val validationUtils: com.hypersoft.billing.utils.ValidationUtils by lazy { com.hypersoft.billing.utils.ValidationUtils(billingClient) }
private val validationUtils: ValidationUtils by lazy { ValidationUtils(billingClient) }

/**
* @property _purchasesSharedFlow: Collect (observe) this, to get user's purchase list currently owns
Expand Down Expand Up @@ -230,8 +232,8 @@ open class BillingRepository(context: Context) {
*/

protected fun fetchPurchases() {
// Clear lists
_purchases.clear()
// New List
var purchaseList = arrayListOf<Purchase>()

// Determine product types to be fetched
val hasInApp = userQueryList.any { it.first == BillingClient.ProductType.INAPP }
Expand All @@ -241,14 +243,14 @@ open class BillingRepository(context: Context) {

// Query for product types to be fetched
when {
hasBoth -> queryPurchases(BillingClient.ProductType.INAPP, true)
hasInApp -> queryPurchases(BillingClient.ProductType.INAPP, false)
hasSubs -> queryPurchases(BillingClient.ProductType.SUBS, false)
hasBoth -> queryPurchases(purchaseList, BillingClient.ProductType.INAPP, true)
hasInApp -> queryPurchases(purchaseList, BillingClient.ProductType.INAPP, false)
hasSubs -> queryPurchases(purchaseList, BillingClient.ProductType.SUBS, false)
else -> processPurchases()
}
}

private fun queryPurchases(productType: String, hasBoth: Boolean) {
private fun queryPurchases(purchaseList: ArrayList<Purchase>, productType: String, hasBoth: Boolean) {
when (productType) {
BillingClient.ProductType.INAPP -> Result.setResultState(ResultState.CONSOLE_PURCHASE_PRODUCTS_INAPP_FETCHING)
BillingClient.ProductType.SUBS -> Result.setResultState(ResultState.CONSOLE_PURCHASE_PRODUCTS_SUB_FETCHING)
Expand All @@ -259,7 +261,7 @@ open class BillingRepository(context: Context) {
{ billingResult, purchases ->
Log.i(TAG, "BillingRepository: $productType -> Purchases: $purchases")
if (BillingResponse(billingResult.responseCode).isOk) {
_purchases.addAll(purchases)
purchaseList.addAll(purchases)
when (productType) {
BillingClient.ProductType.INAPP -> Result.setResultState(ResultState.CONSOLE_PURCHASE_PRODUCTS_INAPP_FETCHING_SUCCESS)
BillingClient.ProductType.SUBS -> Result.setResultState(ResultState.CONSOLE_PURCHASE_PRODUCTS_SUB_FETCHING_SUCCESS)
Expand All @@ -272,9 +274,11 @@ open class BillingRepository(context: Context) {
}

if (productType == BillingClient.ProductType.INAPP && hasBoth) {
queryPurchases(BillingClient.ProductType.SUBS, false)
queryPurchases(purchaseList, BillingClient.ProductType.SUBS, false)
return@queryPurchasesAsync
}
_purchases.clear()
_purchases.addAll(purchaseList)
processPurchases()
}
}
Expand Down Expand Up @@ -607,7 +611,7 @@ open class BillingRepository(context: Context) {
response.isOk -> {
Result.setResultState(ResultState.PURCHASING_SUCCESSFULLY)
handlePurchase(purchasesList)
//fetchPurchases()
fetchPurchases()
return@PurchasesUpdatedListener
}

Expand Down

0 comments on commit c9e34f6

Please sign in to comment.