Skip to content

Commit

Permalink
Fixed getProductDetails for subs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreaming-Codes committed Jun 14, 2024
1 parent b27d8df commit 0b47ba7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions android/src/main/java/MobilePayments.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ class MobilePayments(private val activity: Activity) {
throw IllegalStateException("Billing response code: ${productsDetails.billingResult.responseCode}")
}

val productDetails = productsDetails.productDetailsList?.firstOrNull()
val productDetailsList = productsDetails.productDetailsList?.firstOrNull()
?: throw IllegalStateException("Product details list is empty.")

return BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(productDetails).build()
val productDetailsBuilder = BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(productDetailsList);

if (productType == ProductType.SUBS) {
productDetailsList.subscriptionOfferDetails?.firstOrNull()?.offerToken?.let { offerToken ->
productDetailsBuilder.setOfferToken(offerToken)
}
}

return productDetailsBuilder.build()
} ?: throw IllegalStateException("BillingClient not initialized.")
}

Expand Down

0 comments on commit 0b47ba7

Please sign in to comment.