@@ -68,7 +68,7 @@ import java.lang.ref.WeakReference
6868/* *
6969 * Main OpenIapModule implementation for Android
7070 */
71- class OpenIapModule (private val context : Context ) : PurchasesUpdatedListener {
71+ class OpenIapModule (private val context : Context ) : OpenIapProtocol, PurchasesUpdatedListener {
7272
7373 companion object {
7474 private const val TAG = " OpenIapModule"
@@ -83,7 +83,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
8383 private val purchaseErrorListeners = mutableSetOf<OpenIapPurchaseErrorListener >()
8484 private var currentPurchaseCallback: ((Result <List <Purchase >>) -> Unit )? = null
8585
86- val initConnection: MutationInitConnectionHandler = {
86+ override val initConnection: MutationInitConnectionHandler = {
8787 withContext(Dispatchers .IO ) {
8888 suspendCancellableCoroutine<Boolean > { continuation ->
8989 initBillingClient(
@@ -97,7 +97,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
9797 }
9898 }
9999
100- val endConnection: MutationEndConnectionHandler = {
100+ override val endConnection: MutationEndConnectionHandler = {
101101 withContext(Dispatchers .IO ) {
102102 runCatching {
103103 billingClient?.endConnection()
@@ -107,7 +107,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
107107 }
108108 }
109109
110- val fetchProducts: QueryFetchProductsHandler = { params ->
110+ override val fetchProducts: QueryFetchProductsHandler = { params ->
111111 withContext(Dispatchers .IO ) {
112112 val client = billingClient ? : throw OpenIapError .NotPrepared
113113 if (! client.isReady) throw OpenIapError .NotPrepared
@@ -140,11 +140,11 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
140140 }
141141 }
142142 }
143- val getAvailablePurchases: QueryGetAvailablePurchasesHandler = { _ ->
143+ override val getAvailablePurchases: QueryGetAvailablePurchasesHandler = { _ ->
144144 withContext(Dispatchers .IO ) { restorePurchasesHelper(billingClient) }
145145 }
146146
147- val getActiveSubscriptions: QueryGetActiveSubscriptionsHandler = { subscriptionIds ->
147+ override val getActiveSubscriptions: QueryGetActiveSubscriptionsHandler = { subscriptionIds ->
148148 withContext(Dispatchers .IO ) {
149149 val purchases = queryPurchases(billingClient, BillingClient .ProductType .SUBS )
150150 val filtered = if (subscriptionIds.isNullOrEmpty()) {
@@ -158,11 +158,11 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
158158 }
159159 }
160160
161- val hasActiveSubscriptions: QueryHasActiveSubscriptionsHandler = { subscriptionIds ->
161+ override val hasActiveSubscriptions: QueryHasActiveSubscriptionsHandler = { subscriptionIds ->
162162 getActiveSubscriptions(subscriptionIds).isNotEmpty()
163163 }
164164
165- val requestPurchase: MutationRequestPurchaseHandler = { props ->
165+ override val requestPurchase: MutationRequestPurchaseHandler = { props ->
166166 val purchases = withContext(Dispatchers .IO ) {
167167 val androidArgs = props.toAndroidPurchaseArgs()
168168 val activity = currentActivityRef?.get() ? : (context as ? Activity )
@@ -313,7 +313,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
313313 queryPurchases(billingClient, billingType)
314314 }
315315
316- val finishTransaction: MutationFinishTransactionHandler = { purchase, isConsumable ->
316+ override val finishTransaction: MutationFinishTransactionHandler = { purchase, isConsumable ->
317317 withContext(Dispatchers .IO ) {
318318 val client = billingClient ? : throw OpenIapError .NotPrepared
319319 if (! client.isReady) throw OpenIapError .NotPrepared
@@ -344,7 +344,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
344344 }
345345 }
346346
347- val acknowledgePurchaseAndroid: MutationAcknowledgePurchaseAndroidHandler = { purchaseToken ->
347+ override val acknowledgePurchaseAndroid: MutationAcknowledgePurchaseAndroidHandler = { purchaseToken ->
348348 withContext(Dispatchers .IO ) {
349349 val client = billingClient ? : throw OpenIapError .NotPrepared
350350 val params = AcknowledgePurchaseParams .newBuilder().setPurchaseToken(purchaseToken).build()
@@ -361,7 +361,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
361361 }
362362 }
363363
364- val consumePurchaseAndroid: MutationConsumePurchaseAndroidHandler = { purchaseToken ->
364+ override val consumePurchaseAndroid: MutationConsumePurchaseAndroidHandler = { purchaseToken ->
365365 withContext(Dispatchers .IO ) {
366366 val client = billingClient ? : throw OpenIapError .NotPrepared
367367 val params = ConsumeParams .newBuilder().setPurchaseToken(purchaseToken).build()
@@ -378,7 +378,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
378378 }
379379 }
380380
381- val deepLinkToSubscriptions: MutationDeepLinkToSubscriptionsHandler = { options ->
381+ override val deepLinkToSubscriptions: MutationDeepLinkToSubscriptionsHandler = { options ->
382382 val pkg = options?.packageNameAndroid ? : context.packageName
383383 val uri = if (! options?.skuAndroid.isNullOrBlank()) {
384384 Uri .parse(" https://play.google.com/store/account/subscriptions?sku=${options!! .skuAndroid} &package=$pkg " )
@@ -389,14 +389,14 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
389389 context.startActivity(intent)
390390 }
391391
392- val restorePurchases: MutationRestorePurchasesHandler = {
392+ override val restorePurchases: MutationRestorePurchasesHandler = {
393393 withContext(Dispatchers .IO ) {
394394 restorePurchasesHelper(billingClient)
395395 Unit
396396 }
397397 }
398398
399- val validateReceipt: MutationValidateReceiptHandler = { throw OpenIapError .NotSupported }
399+ override val validateReceipt: MutationValidateReceiptHandler = { throw OpenIapError .NotSupported }
400400
401401 private val purchaseError: SubscriptionPurchaseErrorHandler = {
402402 onPurchaseError(this ::addPurchaseErrorListener, this ::removePurchaseErrorListener)
@@ -406,15 +406,15 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
406406 onPurchaseUpdated(this ::addPurchaseUpdateListener, this ::removePurchaseUpdateListener)
407407 }
408408
409- val queryHandlers: QueryHandlers = QueryHandlers (
409+ override val queryHandlers: QueryHandlers = QueryHandlers (
410410 fetchProducts = fetchProducts,
411411 getActiveSubscriptions = getActiveSubscriptions,
412412 getAvailablePurchases = getAvailablePurchases,
413413 getStorefrontIOS = { getStorefront() },
414414 hasActiveSubscriptions = hasActiveSubscriptions
415415 )
416416
417- val mutationHandlers: MutationHandlers = MutationHandlers (
417+ override val mutationHandlers: MutationHandlers = MutationHandlers (
418418 acknowledgePurchaseAndroid = acknowledgePurchaseAndroid,
419419 consumePurchaseAndroid = consumePurchaseAndroid,
420420 deepLinkToSubscriptions = deepLinkToSubscriptions,
@@ -426,7 +426,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
426426 validateReceipt = validateReceipt
427427 )
428428
429- val subscriptionHandlers: SubscriptionHandlers = SubscriptionHandlers (
429+ override val subscriptionHandlers: SubscriptionHandlers = SubscriptionHandlers (
430430 purchaseError = purchaseError,
431431 purchaseUpdated = purchaseUpdated
432432 )
@@ -455,19 +455,19 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
455455 }
456456 }
457457
458- fun addPurchaseUpdateListener (listener : OpenIapPurchaseUpdateListener ) {
458+ override fun addPurchaseUpdateListener (listener : OpenIapPurchaseUpdateListener ) {
459459 purchaseUpdateListeners.add(listener)
460460 }
461461
462- fun removePurchaseUpdateListener (listener : OpenIapPurchaseUpdateListener ) {
462+ override fun removePurchaseUpdateListener (listener : OpenIapPurchaseUpdateListener ) {
463463 purchaseUpdateListeners.remove(listener)
464464 }
465465
466- fun addPurchaseErrorListener (listener : OpenIapPurchaseErrorListener ) {
466+ override fun addPurchaseErrorListener (listener : OpenIapPurchaseErrorListener ) {
467467 purchaseErrorListeners.add(listener)
468468 }
469469
470- fun removePurchaseErrorListener (listener : OpenIapPurchaseErrorListener ) {
470+ override fun removePurchaseErrorListener (listener : OpenIapPurchaseErrorListener ) {
471471 purchaseErrorListeners.remove(listener)
472472 }
473473
@@ -557,7 +557,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
557557 })
558558 }
559559
560- fun setActivity (activity : Activity ? ) {
560+ override fun setActivity (activity : Activity ? ) {
561561 currentActivityRef = activity?.let { WeakReference (it) }
562562 }
563563}
0 commit comments