Let me describe what I am trying to do to see if anyone has any recommendations.
My website is a subscription based WebApp. A user must have a valid subscription in order to access certain pages on my site.
My website has it's own authentication system. When a user signs up with our website, a chargebee customer is created for them and then their "customer_id" is saved to their account in our database.
Then using the the hosted_page.checkout_new API I send those users to the checkout page while passing their customer_id to the page so chargebee knows they are an existing user.
What happens next is where I have questions. When those users have completed the checkout process and now have valid subscriptions, how should my site "verify" that the current user does have a valid subscription? I've seen that the list subscription API using the customer_id as a filter may work. But is that good practice?
Are there any major issues with what I am trying to achieve? Maybe there is a better way?
I appreciate any help!
You could implement your use case by following these steps :
Step 1: Create a customer on Chargebee when a user signs up on your website and then use the Hosted Pages Checkout New API while passing in the existing customer id as a parameter.
Please save the hosted page id for the next step.
Step 2: When the customer tries to access your website, use the Retrieve a Hosted Page API using the hosted page id as a parameter to get the subscription id of the created subscription.
Step 3: Using the subscription id as a parameter, use the Retrieve a subscription API to get the current state of the subscription.
Step 4: If the “status” parameter of the response is set to “active” then allow the customer to access the pages on the site.
Alternatively, you could configure webhooks for your Chargebee site and monitor for Subscription Created events for allowing customers to your site.
Webhooks also allows you to monitor all kinds of event occurrences in the subscription lifecycle like Subscription Updated, Subscription Cancelled, etc which might be essential to allowing or disallowing users from accessing those pages on your site.
Thanks Nilotpal for the reply.
Saving the hosted page id and then using the "Retrieve a Hosted Page API" followed by the "Retrieve a subscription API" sounds like a good approach.
I am wondering though if the process could simplified by using the "List Subscriptions API" with the customer_id as a filter.
So the process would be as follows...
1. Create a Customer on ChargeBee and pass id to the Hosted Page Checkout
2. When User tries to access my site I pass their customer id to the list subscription API to retrieve their subscription or subscriptions
3. Verify subscription is active.
Does that also seem doable?
Sorry for the delay in response!
Yes, you are absolutely right. The process which you mentioned will also work in the same way.
You can go ahead with that approach as well if you wish to.
Do let us know if you have any questions.