@@ -8,6 +8,7 @@ import com.apphud.sdk.domain.ApphudNonRenewingPurchase
8
8
import com.apphud.sdk.domain.ApphudProduct
9
9
import com.apphud.sdk.domain.ApphudSubscription
10
10
import com.apphud.sdk.domain.ApphudUser
11
+ import com.apphud.sdk.internal.ServiceLocator
11
12
import com.apphud.sdk.internal.callback_status.PurchaseCallbackStatus
12
13
import com.apphud.sdk.internal.callback_status.PurchaseUpdatedCallbackStatus
13
14
import com.apphud.sdk.internal.domain.model.PurchaseContext
@@ -208,7 +209,7 @@ private fun ApphudInternal.purchaseInternal(
208
209
)
209
210
ApphudLog .log(" Purchase Pending" )
210
211
callback?.invoke(ApphudPurchaseResult (null , null , purchase, error))
211
- storage .isNeedSync = true
212
+ ServiceLocator .instance.sharedPreferencesStorage .isNeedSync = true
212
213
}
213
214
Purchase .PurchaseState .PURCHASED -> {
214
215
val product = apphudProduct.productDetails
@@ -292,7 +293,7 @@ internal fun ApphudInternal.lookupFreshPurchase(extraMessage: String = "resend_f
292
293
mFreshPurchase
293
294
}
294
295
}
295
- if ((purchaseCallbacks.isNotEmpty() && purchasingProduct != null ) || storage .isNeedSync) {
296
+ if ((purchaseCallbacks.isNotEmpty() && purchasingProduct != null ) || ServiceLocator .instance.sharedPreferencesStorage .isNeedSync) {
296
297
297
298
launch(Dispatchers .Main ) { apphudListener?.apphudDidReceivePurchase(purchase) }
298
299
@@ -319,7 +320,7 @@ internal fun ApphudInternal.lookupFreshPurchase(extraMessage: String = "resend_f
319
320
val newPurchases =
320
321
customer.purchases.firstOrNull { it.productId == purchase.products.first() }
321
322
322
- storage .isNeedSync = false
323
+ ServiceLocator .instance.sharedPreferencesStorage .isNeedSync = false
323
324
handleCheckSubmissionResult(customer, purchase, newSubscriptions, newPurchases, false )
324
325
}
325
326
}
@@ -402,7 +403,7 @@ internal fun ApphudInternal.handleObservedPurchase(
402
403
403
404
private fun ApphudInternal.processPurchaseError (status : PurchaseUpdatedCallbackStatus .Error ) {
404
405
if (status.result.responseCode == BillingClient .BillingResponseCode .ITEM_ALREADY_OWNED ) {
405
- storage .isNeedSync = true
406
+ ServiceLocator .instance.sharedPreferencesStorage .isNeedSync = true
406
407
coroutineScope.launch(errorHandler) {
407
408
ApphudLog .log(" ProcessPurchaseError: syncPurchases()" )
408
409
fetchNativePurchases(forceRefresh = true )
@@ -428,7 +429,7 @@ private suspend fun ApphudInternal.sendCheckToApphud(
428
429
) {
429
430
val localCurrentUser = currentUser
430
431
when {
431
- localCurrentUser == null -> storage .isNeedSync = true
432
+ localCurrentUser == null -> ServiceLocator .instance.sharedPreferencesStorage .isNeedSync = true
432
433
fallbackMode -> {
433
434
runCatchingCancellable {
434
435
RequestManager .purchased(
@@ -484,7 +485,7 @@ private suspend fun ApphudInternal.sendCheckToApphud(
484
485
val newPurchases =
485
486
customer.purchases.firstOrNull { it.productId == purchase.products.first() }
486
487
487
- storage .isNeedSync = false
488
+ ServiceLocator .instance.sharedPreferencesStorage .isNeedSync = false
488
489
handleCheckSubmissionResult(customer, purchase, newSubscriptions, newPurchases, false )
489
490
}
490
491
}
@@ -513,7 +514,7 @@ private suspend fun ApphudInternal.sendCheckToApphud(
513
514
}
514
515
}
515
516
}
516
- storage .isNeedSync = true
517
+ ServiceLocator .instance.sharedPreferencesStorage .isNeedSync = true
517
518
518
519
handleCheckSubmissionResult(null , purchase, null , null , false )
519
520
}
@@ -552,7 +553,7 @@ internal fun ApphudInternal.addTempPurchase(
552
553
// nothing
553
554
}
554
555
}
555
- storage .isNeedSync = true
556
+ ServiceLocator .instance.sharedPreferencesStorage .isNeedSync = true
556
557
handleCheckSubmissionResult(apphudUser, purchase, newSubscription, newPurchase, true )
557
558
}
558
559
@@ -619,7 +620,7 @@ internal suspend fun ApphudInternal.trackPurchase(
619
620
ApphudLog .logE(" trackPurchase: could not found purchase for product $productId " )
620
621
}
621
622
} else {
622
- storage .isNeedSync = true
623
+ ServiceLocator .instance.sharedPreferencesStorage .isNeedSync = true
623
624
withContext(Dispatchers .Main ) {
624
625
syncPurchases(observerMode = true )
625
626
}
0 commit comments