How to determine active subscription by inspecting receipts

As a part of moving my app to a subscription model, I'm now struggling with allowing the user to manage their active subscription. I have the infrastructure in place to purchase, restore and query all the receipt data from Apple's servers and am currently testing with sandbox accounts. What I'm struggling with is knowing what subscription APPLE thinks the user is subscribed to. This is only a problem when the user wants to change their subscription but either upgrading or downgrading. What can happen is that a user might decide to change their subscription (to take affect after their current subscription expires, etc.) I want to be able to show the user what they are subscribed to, but for the life of me, I don't know how to do it. It's not always the "most recently purchased and still active" subscription as determined by inspecting the receipts.
Obviously I could remove the ability to change the subscription plan from within the app... or just allow only ONE product per group. But that feels wrong. Does anyone know how to simply ask Apple (programatically) "What product is the user currently subscribed to?" Apple's rules say only one product per group, but I can't find this info documented anywhere.

To learn how to unlock content using App Store Server APIs, see 2024 WWDC Explore App Store server APIs for In-App Purchase and 2022 WWDC Explore in-app purchase integration and migration.

"What product is the user currently subscribed to?"

In StoreKit 2, you can use Transaction.currententitlements to determine which products the user is entitled to. For an example of this property, see its description section.

How to determine active subscription by inspecting receipts
 
 
Q