@@ -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"
@@ -84,7 +84,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
8484 private val purchaseErrorListeners = mutableSetOf<OpenIapPurchaseErrorListener >()
8585 private var currentPurchaseCallback: ((Result <List <Purchase >>) -> Unit )? = null
8686
87- val initConnection: MutationInitConnectionHandler = {
87+ override val initConnection: MutationInitConnectionHandler = {
8888 withContext(Dispatchers .IO ) {
8989 suspendCancellableCoroutine<Boolean > { continuation ->
9090 initBillingClient(
@@ -98,7 +98,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
9898 }
9999 }
100100
101- val endConnection: MutationEndConnectionHandler = {
101+ override val endConnection: MutationEndConnectionHandler = {
102102 withContext(Dispatchers .IO ) {
103103 runCatching {
104104 billingClient?.endConnection()
@@ -108,7 +108,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
108108 }
109109 }
110110
111- val fetchProducts: QueryFetchProductsHandler = { params ->
111+ override val fetchProducts: QueryFetchProductsHandler = { params ->
112112 withContext(Dispatchers .IO ) {
113113 val client = billingClient ? : throw OpenIapError .NotPrepared
114114 if (! client.isReady) throw OpenIapError .NotPrepared
@@ -141,11 +141,11 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
141141 }
142142 }
143143 }
144- val getAvailablePurchases: QueryGetAvailablePurchasesHandler = { _ ->
144+ override val getAvailablePurchases: QueryGetAvailablePurchasesHandler = { _ ->
145145 withContext(Dispatchers .IO ) { restorePurchasesHelper(billingClient) }
146146 }
147147
148- val getActiveSubscriptions: QueryGetActiveSubscriptionsHandler = { subscriptionIds ->
148+ override val getActiveSubscriptions: QueryGetActiveSubscriptionsHandler = { subscriptionIds ->
149149 withContext(Dispatchers .IO ) {
150150 val androidPurchases = queryPurchases(billingClient, BillingClient .ProductType .SUBS )
151151 .filterIsInstance<PurchaseAndroid >()
@@ -159,11 +159,11 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
159159 }
160160 }
161161
162- val hasActiveSubscriptions: QueryHasActiveSubscriptionsHandler = { subscriptionIds ->
162+ override val hasActiveSubscriptions: QueryHasActiveSubscriptionsHandler = { subscriptionIds ->
163163 getActiveSubscriptions(subscriptionIds).isNotEmpty()
164164 }
165165
166- val requestPurchase: MutationRequestPurchaseHandler = { props ->
166+ override val requestPurchase: MutationRequestPurchaseHandler = { props ->
167167 val purchases = withContext(Dispatchers .IO ) {
168168 val androidArgs = props.toAndroidPurchaseArgs()
169169 val activity = currentActivityRef?.get() ? : fallbackActivity
@@ -314,7 +314,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
314314 queryPurchases(billingClient, billingType)
315315 }
316316
317- val finishTransaction: MutationFinishTransactionHandler = { purchase, isConsumable ->
317+ override val finishTransaction: MutationFinishTransactionHandler = { purchase, isConsumable ->
318318 withContext(Dispatchers .IO ) {
319319 val client = billingClient ? : throw OpenIapError .NotPrepared
320320 if (! client.isReady) throw OpenIapError .NotPrepared
@@ -345,7 +345,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
345345 }
346346 }
347347
348- val acknowledgePurchaseAndroid: MutationAcknowledgePurchaseAndroidHandler = { purchaseToken ->
348+ override val acknowledgePurchaseAndroid: MutationAcknowledgePurchaseAndroidHandler = { purchaseToken ->
349349 withContext(Dispatchers .IO ) {
350350 val client = billingClient ? : throw OpenIapError .NotPrepared
351351 val params = AcknowledgePurchaseParams .newBuilder().setPurchaseToken(purchaseToken).build()
@@ -362,7 +362,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
362362 }
363363 }
364364
365- val consumePurchaseAndroid: MutationConsumePurchaseAndroidHandler = { purchaseToken ->
365+ override val consumePurchaseAndroid: MutationConsumePurchaseAndroidHandler = { purchaseToken ->
366366 withContext(Dispatchers .IO ) {
367367 val client = billingClient ? : throw OpenIapError .NotPrepared
368368 val params = ConsumeParams .newBuilder().setPurchaseToken(purchaseToken).build()
@@ -379,7 +379,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
379379 }
380380 }
381381
382- val deepLinkToSubscriptions: MutationDeepLinkToSubscriptionsHandler = { options ->
382+ override val deepLinkToSubscriptions: MutationDeepLinkToSubscriptionsHandler = { options ->
383383 val pkg = options?.packageNameAndroid ? : context.packageName
384384 val uri = if (! options?.skuAndroid.isNullOrBlank()) {
385385 Uri .parse(" https://play.google.com/store/account/subscriptions?sku=${options!! .skuAndroid} &package=$pkg " )
@@ -390,14 +390,14 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
390390 context.startActivity(intent)
391391 }
392392
393- val restorePurchases: MutationRestorePurchasesHandler = {
393+ override val restorePurchases: MutationRestorePurchasesHandler = {
394394 withContext(Dispatchers .IO ) {
395395 restorePurchasesHelper(billingClient)
396396 Unit
397397 }
398398 }
399399
400- val validateReceipt: MutationValidateReceiptHandler = { throw OpenIapError .NotSupported }
400+ override val validateReceipt: MutationValidateReceiptHandler = { throw OpenIapError .NotSupported }
401401
402402 private val purchaseError: SubscriptionPurchaseErrorHandler = {
403403 onPurchaseError(this ::addPurchaseErrorListener, this ::removePurchaseErrorListener)
@@ -407,15 +407,15 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
407407 onPurchaseUpdated(this ::addPurchaseUpdateListener, this ::removePurchaseUpdateListener)
408408 }
409409
410- val queryHandlers: QueryHandlers = QueryHandlers (
410+ override val queryHandlers: QueryHandlers = QueryHandlers (
411411 fetchProducts = fetchProducts,
412412 getActiveSubscriptions = getActiveSubscriptions,
413413 getAvailablePurchases = getAvailablePurchases,
414414 getStorefrontIOS = { getStorefront() },
415415 hasActiveSubscriptions = hasActiveSubscriptions
416416 )
417417
418- val mutationHandlers: MutationHandlers = MutationHandlers (
418+ override val mutationHandlers: MutationHandlers = MutationHandlers (
419419 acknowledgePurchaseAndroid = acknowledgePurchaseAndroid,
420420 consumePurchaseAndroid = consumePurchaseAndroid,
421421 deepLinkToSubscriptions = deepLinkToSubscriptions,
@@ -427,7 +427,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
427427 validateReceipt = validateReceipt
428428 )
429429
430- val subscriptionHandlers: SubscriptionHandlers = SubscriptionHandlers (
430+ override val subscriptionHandlers: SubscriptionHandlers = SubscriptionHandlers (
431431 purchaseError = purchaseError,
432432 purchaseUpdated = purchaseUpdated
433433 )
@@ -456,19 +456,19 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
456456 }
457457 }
458458
459- fun addPurchaseUpdateListener (listener : OpenIapPurchaseUpdateListener ) {
459+ override fun addPurchaseUpdateListener (listener : OpenIapPurchaseUpdateListener ) {
460460 purchaseUpdateListeners.add(listener)
461461 }
462462
463- fun removePurchaseUpdateListener (listener : OpenIapPurchaseUpdateListener ) {
463+ override fun removePurchaseUpdateListener (listener : OpenIapPurchaseUpdateListener ) {
464464 purchaseUpdateListeners.remove(listener)
465465 }
466466
467- fun addPurchaseErrorListener (listener : OpenIapPurchaseErrorListener ) {
467+ override fun addPurchaseErrorListener (listener : OpenIapPurchaseErrorListener ) {
468468 purchaseErrorListeners.add(listener)
469469 }
470470
471- fun removePurchaseErrorListener (listener : OpenIapPurchaseErrorListener ) {
471+ override fun removePurchaseErrorListener (listener : OpenIapPurchaseErrorListener ) {
472472 purchaseErrorListeners.remove(listener)
473473 }
474474
@@ -558,7 +558,7 @@ class OpenIapModule(private val context: Context) : PurchasesUpdatedListener {
558558 })
559559 }
560560
561- fun setActivity (activity : Activity ? ) {
561+ override fun setActivity (activity : Activity ? ) {
562562 currentActivityRef = activity?.let { WeakReference (it) }
563563 }
564564}
0 commit comments