A more detailed explanation -
1) User already owns a subscription
In this case when you call billingClient.queryPurchases(), which returns a PurchaseResult. This has details such as the purchaseToken and the sku as well as the packagename. This call is made every time the app starts or a MainActivity is Resumed, because if someone buys your IAP offline you also need to acknowledge a purchase (more on this here)
This means you can also let the user "Manage" subscription, so the deeplink to link to is:
https://play.google.com/store/account/subscriptions?sku=skuName&package=packageName
2) User is about to buy a subscription:
The way to do this is capture productId or Sku of the SUBS IAP you created in the Play console. Then you build the flowParams, and then you can call
val flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
.build()
billingClient.launchBillingFlow(activity, flowParams)
If successful, this means you get back two things: BillingResult and MutableList<Purchase>. If the BillingResult is OK, and the list returned is not empty, the purchase was succesful. This object also has the sku and packageName, so you follow the same deeplink as above for the user to Manage their subscription.
3) The user has canceled their subscription, and their subscription has expired but is within any of the Resubscribe period conditions stated here
This is when you show this deeplink:
https://play.google.com/store/account/subscriptions, so they can restore or resubscribe the same Sku they had before.
p.s. One thing to note is the Play Store app supports multiple users. So the deeplink will only work if the Play Store app has the correct user selected.
