Skip to content

Commit 7f43635

Browse files
MarkusPettersson98Pururun
authored andcommitted
Expose play purchase API via gRPC
1 parent c651385 commit 7f43635

File tree

11 files changed

+449
-283
lines changed

11 files changed

+449
-283
lines changed

android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingPaymentRepository.kt

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.mullvad.mullvadvpn.lib.billing
22

33
import android.app.Activity
4+
import android.util.Log
45
import com.android.billingclient.api.BillingClient.BillingResponseCode
56
import com.android.billingclient.api.Purchase
67
import kotlinx.coroutines.flow.Flow
@@ -22,6 +23,7 @@ import net.mullvad.mullvadvpn.lib.payment.model.ProductId
2223
import net.mullvad.mullvadvpn.lib.payment.model.PurchaseResult
2324
import net.mullvad.mullvadvpn.lib.payment.model.VerificationResult
2425
import net.mullvad.mullvadvpn.model.PlayPurchase
26+
import net.mullvad.mullvadvpn.model.PlayPurchasePaymentToken
2527

2628
class BillingPaymentRepository(
2729
private val billingRepository: BillingRepository,
@@ -38,7 +40,7 @@ class BillingPaymentRepository(
3840
emit(
3941
billingRepository
4042
.queryProducts(listOf(ProductIds.OneMonth))
41-
.toPaymentAvailability(productIdToPaymentStatus)
43+
.toPaymentAvailability(productIdToPaymentStatus),
4244
)
4345
}
4446

@@ -50,6 +52,8 @@ class BillingPaymentRepository(
5052

5153
val productDetailsResult = billingRepository.queryProducts(listOf(productId.value))
5254

55+
Log.d("LOLZ", "responseCode=${productDetailsResult.responseCode()}")
56+
Log.d("LOLZ", "error", productDetailsResult.toBillingException())
5357
val productDetails =
5458
when (productDetailsResult.responseCode()) {
5559
BillingResponseCode.OK -> {
@@ -63,8 +67,8 @@ class BillingPaymentRepository(
6367
emit(
6468
PurchaseResult.Error.FetchProductsError(
6569
productId,
66-
productDetailsResult.toBillingException()
67-
)
70+
productDetailsResult.toBillingException(),
71+
),
6872
)
6973
return@flow
7074
}
@@ -79,23 +83,23 @@ class BillingPaymentRepository(
7983
emit(PurchaseResult.Error.TransactionIdError(productId, null))
8084
return@flow
8185
},
82-
{ it }
86+
{ it.value },
8387
)
8488

8589
val result =
8690
billingRepository.startPurchaseFlow(
8791
productDetails = productDetails,
8892
obfuscatedId = obfuscatedId,
89-
activityProvider = activityProvider
93+
activityProvider = activityProvider,
9094
)
9195

9296
if (result.responseCode == BillingResponseCode.OK) {
9397
emit(PurchaseResult.BillingFlowStarted)
9498
} else {
9599
emit(
96100
PurchaseResult.Error.BillingError(
97-
BillingException(result.responseCode, result.debugMessage)
98-
)
101+
BillingException(result.responseCode, result.debugMessage),
102+
),
99103
)
100104
return@flow
101105
}
@@ -118,8 +122,8 @@ class BillingPaymentRepository(
118122
verifyPurchase(event.purchases.first())
119123
.fold(
120124
{ PurchaseResult.Error.VerificationError(null) },
121-
{ PurchaseResult.Completed.Success }
122-
)
125+
{ PurchaseResult.Completed.Success },
126+
),
123127
)
124128
}
125129
}
@@ -140,8 +144,8 @@ class BillingPaymentRepository(
140144
verifyPurchase(purchases.first())
141145
.fold(
142146
{ VerificationResult.Error.VerificationError(null) },
143-
{ VerificationResult.Success }
144-
)
147+
{ VerificationResult.Success },
148+
),
145149
)
146150
} else {
147151
emit(VerificationResult.NothingToVerify)
@@ -158,7 +162,7 @@ class BillingPaymentRepository(
158162
playPurchaseRepository.verifyPlayPurchase(
159163
PlayPurchase(
160164
productId = purchase.products.first(),
161-
purchaseToken = purchase.purchaseToken,
162-
)
165+
purchaseToken = PlayPurchasePaymentToken(purchase.purchaseToken),
166+
),
163167
)
164168
}

android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingRepository.kt

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.lib.billing
22

33
import android.app.Activity
44
import android.content.Context
5+
import android.util.Log
56
import com.android.billingclient.api.BillingClient
67
import com.android.billingclient.api.BillingClient.BillingResponseCode
78
import com.android.billingclient.api.BillingClientStateListener
@@ -155,6 +156,7 @@ class BillingRepository(context: Context) {
155156
private suspend fun queryProductDetails(productIds: List<String>): ProductDetailsResult {
156157
return try {
157158
ensureConnected()
159+
Log.d("LOLZ", "ensureConnected")
158160

159161
val productList =
160162
productIds.map { productId ->
@@ -166,10 +168,13 @@ class BillingRepository(context: Context) {
166168
val params = QueryProductDetailsParams.newBuilder()
167169
params.setProductList(productList)
168170

171+
Log.d("LOLZ", "params=" + params.build())
169172
billingClient.queryProductDetails(params.build())
170173
} catch (billingException: BillingException) {
174+
Log.d("LOLZ", "Exception", billingException)
171175
ProductDetailsResult(billingException.toBillingResult(), null)
172176
} catch (t: Throwable) {
177+
Log.d("LOLZ", "Exception lolz", t)
173178
ProductDetailsResult(
174179
BillingResult.newBuilder().setResponseCode(BillingResponseCode.ERROR).build(),
175180
null

0 commit comments

Comments
 (0)