Skip to content

Commit 0e5f63c

Browse files
committed
Use first offer token if not specified
1 parent 0b9eb83 commit 0e5f63c

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

android/src/main/java/IapPlugin.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,16 @@ class IapPlugin(private val activity: Activity): Plugin(activity), PurchasesUpda
219219
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && productDetailsResult.productDetailsList.isNotEmpty()) {
220220
val productDetails = productDetailsResult.productDetailsList[0]
221221

222-
val productDetailsParamsList = if (args.offerToken != null) {
223-
listOf(
224-
BillingFlowParams.ProductDetailsParams.newBuilder()
225-
.setProductDetails(productDetails)
226-
.setOfferToken(args.offerToken!!)
227-
.build()
228-
)
229-
} else {
230-
listOf(
231-
BillingFlowParams.ProductDetailsParams.newBuilder()
232-
.setProductDetails(productDetails)
233-
.build()
234-
)
235-
}
222+
// Get offer token from args or from first available subscription offer
223+
val offerToken = args.offerToken ?:
224+
productDetails.subscriptionOfferDetails?.firstOrNull()?.offerToken
225+
226+
val productDetailsParamsBuilder = BillingFlowParams.ProductDetailsParams.newBuilder()
227+
.setProductDetails(productDetails)
228+
229+
offerToken?.let { productDetailsParamsBuilder.setOfferToken(it) }
230+
231+
val productDetailsParamsList = listOf(productDetailsParamsBuilder.build())
236232

237233
val billingFlowParamsBuilder = BillingFlowParams.newBuilder()
238234
.setProductDetailsParamsList(productDetailsParamsList)

0 commit comments

Comments
 (0)