Skip to main content
Question

Paywall: How to get the recently purchased subscription_id?

  • 24 June 2024
  • 2 replies
  • 34 views

We are using RevenueCat Paywalls (Android, ios) for our subscriptions.
Upon a successful purchase, a "PaywallResult" response is returned, from which we can retrieve the "CustomerInfo".

Since a customer can theoretically have multiple entitlements, is there an easy way to identify the currently purchased subscription?

Background: We need to
1. send this subscription_id to our backend after the purchase
2. on backend: fetch the subscription details using the RevenueCat API v2 beta,
3. on Backend: save the subscription in our database, and provide the user with access to the purchased product.
4. Send response back to app

 

This post has been closed for comments

2 replies

Userlevel 2
Badge +5

Hi,

When you refer to `subscription_id` you mean the entitlement id?

You could also be using webhooks for that matter, you would get all the info straight away to the backend without the client needing to pass that information.

You could also be checking at the customerInfo object, inside subscriptions and sort it by date to get the latest one. Would that work for your case?

 

Best,

Badge +2

Hi Joan,

Thank you for your reply.

I am currently using the v2-beta REST API, where the subscription_id appears in the format "sub1ab2c3d4e2".

Step 1:

When a user subscribes, I want to send the subscription_id to the backend, fetch the subscription details via https://api.revenuecat.com/v2/projects/{project_id}/subscriptions/{subscription_id}, and then grant access to the user. However, the response only includes CustomerInfo.

Step 2:

Additionally, I want to listen to webhooks on the backend. Here, I also intend to fetch the latest data using the same endpoint: https://api.revenuecat.com/v2/projects/{project_id}/subscriptions/{subscription_id}. However, it seems that this new subscription_id (e.g., sub1ab2c3d4e2) is not present in the webhook event payloads.

What I’m doing right now is following:

Current workaround for Step 1:

  1. After payment I send the customer_id from App to the backend.
  2. On Backend: I fetch all subscriptions for the customer via https://api.revenuecat.com/v2/projects/{project_id}/customers/{customer_id}/subscriptions.
  3. Sort the subscriptions by date and use the most recent active subscription.
  4. Fetch the up-to-date subscription data via https://api.revenuecat.com/v2/projects/{project_id}/subscriptions/{subscription_id}.
  5. Save the data in our database and return a response to the app.

Current workaround for Webhooks:

  1. When I receive a webhook event I fetch all customer subscriptions via https://api.revenuecat.com/v2/projects/{project_id}/customers/{customer_id}/subscriptions.
  2. Attempt to find the subscription based on the event.transaction_id and store_subscription_identifier(by splitting “..”)
  3. Fetch the up-to-date subscription data via https://api.revenuecat.com/v2/projects/{project_id}/subscriptions/{subscription_id}and sync it to the database.

Are there any plans to ensure that the new subscription_id is present in all relevant places (app SDK and webhook events)?

Thank you,
Jonas