@@ -7,6 +7,7 @@ import android.content.IntentSender
7
7
import android.content.ServiceConnection
8
8
import android.os.Bundle
9
9
import android.os.IBinder
10
+ import android.os.RemoteException
10
11
import androidx.activity.result.IntentSenderRequest
11
12
import com.android.vending.billing.IInAppBillingService
12
13
import ir.cafebazaar.poolakey.ConnectionState
@@ -97,27 +98,26 @@ internal class ServiceBillingConnection(
97
98
override fun onServiceConnected (name : ComponentName ? , service : IBinder ? ) {
98
99
IInAppBillingService .Stub .asInterface(service)
99
100
?.also { billingService = it }
100
- ?.takeIf (
101
- thisIsTrue = {
102
- isPurchaseTypeSupported(
103
- purchaseType = PurchaseType . IN_APP
104
- )
105
- },
106
- andIfNot = {
107
- callbackReference?.get()?.connectionFailed ?.invoke(IAPNotSupportedException () )
108
- }
109
- )
110
- ?. takeIf (
111
- thisIsTrue = {
112
- ! paymentConfiguration.shouldSupportSubscription || isPurchaseTypeSupported(
113
- purchaseType = PurchaseType . SUBSCRIPTION
114
- )
115
- },
116
- andIfNot = {
117
- callbackReference?.get()?.connectionFailed?.invoke(SubsNotSupportedException () )
101
+ ?.also {
102
+ try {
103
+ if ( isPurchaseTypeSupported(purchaseType = PurchaseType . IN_APP )) {
104
+ if ( ! paymentConfiguration.shouldSupportSubscription || isPurchaseTypeSupported(
105
+ purchaseType = PurchaseType . SUBSCRIPTION
106
+ )
107
+ ) {
108
+ callbackReference?.get()?.connectionSucceed ?.invoke()
109
+ } else {
110
+ callbackReference?.get()?.connectionFailed?.invoke(
111
+ SubsNotSupportedException ()
112
+ )
113
+ }
114
+ } else {
115
+ callbackReference?.get()?.connectionFailed?.invoke( IAPNotSupportedException () )
116
+ }
117
+ } catch (exception : RemoteException ) {
118
+ callbackReference?.get()?.connectionFailed?.invoke(exception )
118
119
}
119
- )
120
- ?.also { callbackReference?.get()?.connectionSucceed?.invoke() }
120
+ }
121
121
}
122
122
123
123
private fun isPurchaseTypeSupported (purchaseType : PurchaseType ): Boolean {
0 commit comments