How can I access the number of sessions remaining data about a pricing plan subscription from a backend JavaScript function?
I am trying to write a backend function that will either cancel or change the end date of a subscription to a pricing plan when the number of sessions remaining is zero. (Of course, it could also be a check for number of sessions booked on the subscription equal to the number of sessions on the plan, but I couldn’t figure that out either.) The goal being that the automatically-generated pricing plan label should no longer be shown on a contact once all of the available sessions for that plan have been redeemed.
The reason I need this is that the pricing plan label remains on the member contact even after the all of the sessions paid for have been redeemed. I would like to be able to terminate the subscription in a scheduled job that runs once per day, so that the label is removed for used-up pricing plans and I can do a dashboard or JS query of active, paid members that only includes people who actually have a pricing plan that can book sessions. If they have no sessions remaining on the pricing plan, then I wouldn’t consider them an active member. I would also like to be able to print a list of members who have active pricing plans to bring to a session when internet access isn’t available.
I have looked in the pricing plans backend documentation and can’t seem to locate any functionality that would allow me to do this. I see that I can use listOrders() to query for active pricing plan orders, and the result gives me a subscriptionId for each order. But haven’t found anywhere that allows me use the subscriptionId to query details about the subscription, such as sessions remaining.
Any advice is appreciated. Thanks.