1
1
package net.mullvad.mullvadvpn.lib.billing
2
2
3
3
import android.app.Activity
4
+ import android.util.Log
4
5
import com.android.billingclient.api.BillingClient.BillingResponseCode
5
6
import com.android.billingclient.api.Purchase
6
7
import kotlinx.coroutines.flow.Flow
@@ -22,6 +23,7 @@ import net.mullvad.mullvadvpn.lib.payment.model.ProductId
22
23
import net.mullvad.mullvadvpn.lib.payment.model.PurchaseResult
23
24
import net.mullvad.mullvadvpn.lib.payment.model.VerificationResult
24
25
import net.mullvad.mullvadvpn.model.PlayPurchase
26
+ import net.mullvad.mullvadvpn.model.PlayPurchasePaymentToken
25
27
26
28
class BillingPaymentRepository (
27
29
private val billingRepository : BillingRepository ,
@@ -38,7 +40,7 @@ class BillingPaymentRepository(
38
40
emit(
39
41
billingRepository
40
42
.queryProducts(listOf (ProductIds .OneMonth ))
41
- .toPaymentAvailability(productIdToPaymentStatus)
43
+ .toPaymentAvailability(productIdToPaymentStatus),
42
44
)
43
45
}
44
46
@@ -50,6 +52,8 @@ class BillingPaymentRepository(
50
52
51
53
val productDetailsResult = billingRepository.queryProducts(listOf (productId.value))
52
54
55
+ Log .d(" LOLZ" , " responseCode=${productDetailsResult.responseCode()} " )
56
+ Log .d(" LOLZ" , " error" , productDetailsResult.toBillingException())
53
57
val productDetails =
54
58
when (productDetailsResult.responseCode()) {
55
59
BillingResponseCode .OK -> {
@@ -63,8 +67,8 @@ class BillingPaymentRepository(
63
67
emit(
64
68
PurchaseResult .Error .FetchProductsError (
65
69
productId,
66
- productDetailsResult.toBillingException()
67
- )
70
+ productDetailsResult.toBillingException(),
71
+ ),
68
72
)
69
73
return @flow
70
74
}
@@ -79,23 +83,23 @@ class BillingPaymentRepository(
79
83
emit(PurchaseResult .Error .TransactionIdError (productId, null ))
80
84
return @flow
81
85
},
82
- { it }
86
+ { it.value },
83
87
)
84
88
85
89
val result =
86
90
billingRepository.startPurchaseFlow(
87
91
productDetails = productDetails,
88
92
obfuscatedId = obfuscatedId,
89
- activityProvider = activityProvider
93
+ activityProvider = activityProvider,
90
94
)
91
95
92
96
if (result.responseCode == BillingResponseCode .OK ) {
93
97
emit(PurchaseResult .BillingFlowStarted )
94
98
} else {
95
99
emit(
96
100
PurchaseResult .Error .BillingError (
97
- BillingException (result.responseCode, result.debugMessage)
98
- )
101
+ BillingException (result.responseCode, result.debugMessage),
102
+ ),
99
103
)
100
104
return @flow
101
105
}
@@ -118,8 +122,8 @@ class BillingPaymentRepository(
118
122
verifyPurchase(event.purchases.first())
119
123
.fold(
120
124
{ PurchaseResult .Error .VerificationError (null ) },
121
- { PurchaseResult .Completed .Success }
122
- )
125
+ { PurchaseResult .Completed .Success },
126
+ ),
123
127
)
124
128
}
125
129
}
@@ -140,8 +144,8 @@ class BillingPaymentRepository(
140
144
verifyPurchase(purchases.first())
141
145
.fold(
142
146
{ VerificationResult .Error .VerificationError (null ) },
143
- { VerificationResult .Success }
144
- )
147
+ { VerificationResult .Success },
148
+ ),
145
149
)
146
150
} else {
147
151
emit(VerificationResult .NothingToVerify )
@@ -158,7 +162,7 @@ class BillingPaymentRepository(
158
162
playPurchaseRepository.verifyPlayPurchase(
159
163
PlayPurchase (
160
164
productId = purchase.products.first(),
161
- purchaseToken = purchase.purchaseToken,
162
- )
165
+ purchaseToken = PlayPurchasePaymentToken ( purchase.purchaseToken) ,
166
+ ),
163
167
)
164
168
}
0 commit comments