Reputation: 1
How can I make a purchase using RevenueCat v6.0.0 by Kotlin, I can see in their Docs :
Purchases.sharedInstance.purchaseWith(
PurchaseParams.Builder(this, aPackage).build(),
onError = { error, userCancelled -> /* No purchase */ },
onSuccess = { storeTransaction, customerInfo ->
if (customerInfo.entitlements["my_entitlement_identifier"]?.isActive == true) {
// Unlock that great "pro" content
}
}
)
But Unfortunately I can't create this (aPackage) variable, for example if I have a product ID named: "monthly_sub", How can I get it and then pass it in this method (purchaseWith)?
I've tried to apply the docs and expect it to open Google Play paywall to make the purchase.
Upvotes: -1
Views: 350
Reputation: 518
Bare with me, I might be missing some small thing, but one thing you could do is get your products, and use what you get back to perform the purchase:
Get your products with:
Purchases.sharedInstance.getProductsWith(
productIds = listOf("your_product_group_id"),
type = ProductType.SUBS,
onError = { error ->
// Error
}
) { productList ->
// Just get the first element as an example
productList.firstOrNull()?.let {
// You wouldn't do it this way per se, but just to show how can it be done
performPurchase(storeProduct = it)
}
}
Perform the purchase:
fun performPurchase(storeProduct: StoreProduct) {
Purchases.sharedInstance.purchaseWith(
purchaseParams = PurchaseParams.Builder(this, storeProduct).build(),
onError = { error, userCancelled ->
// Error
}
) { purchase, customerInfo ->
// Success
}
}
If you need a Paywall approach I think you can also refer to this piece of code.
Upvotes: 0