Table of Contents
- Overview
- Prerequisites
- API Methods
- Response Structures
- Implementation Examples
- Best Practices
- Quick-Start Implementation Prompt
- Understanding the API Methods and IDs
Overview
Rownd Subscriptions provides a simple API to manage subscription plans and user subscriptions in your application. The API is accessible through the globalwindow.rownd
object.
Prerequisites
- Rownd SDK must be installed and configured in your application
- User must be authenticated to access subscription features
- Subscription plans must be configured in your Rownd dashboard
API Methods
1. Get Available Subscription Plans
2. Subscribe to a Plan
subscriptionId
(string): The subscription ID from the available plans responseplanId
(string): The specific plan/price ID to subscribe to (format:prod_XXX__price_YYY
)
3. List User’s Subscriptions
Response Structures
Available Plans Response
User Subscriptions Response
Implementation Examples
Example 1: Fetching and Displaying Available Plans
Example 2: Subscribing to a Plan
Example 3: Displaying User’s Subscriptions
Best Practices
1. Error Handling
Always wrap API calls in try-catch blocks to handle potential errors gracefully:2. Loading States
Provide visual feedback during API calls:3. Authentication Check
Ensure user is authenticated before showing subscription features:4. Price Formatting
Always format prices for display (Stripe stores amounts in cents):5. Date Formatting
Convert Unix timestamps to readable dates:Common Use Cases
1. Subscription Selection Modal
Create a modal that displays available plans and allows users to subscribe.2. Subscription Management Page
Show users their current subscriptions with details like billing dates and status.3. Upgrade/Downgrade Flow
Allow users to change their subscription plan by showing available options.4. Trial Period Handling
Display trial information and countdown for plans with trial periods.5. Celebration Modal for Successful Subscriptions
Create a delightful upgrade experience to celebrate when users successfully subscribe to a plan.Implementation Example:
CSS for Celebration Animation:
Best Practices for Celebration Modals:
- Timing: Show celebration for 4-5 seconds total
- Smooth Transitions: Use cubic-bezier easing for natural motion
- Fade Out: Always fade out before removing to avoid jarring transitions
- Accessibility: Ensure celebration doesn’t interfere with screen readers
- Performance: Use CSS animations instead of JavaScript for better performance
- Customization: Match celebration colors to your brand
Troubleshooting
Issue: “Cannot read properties of undefined”
Solution: Ensurewindow.rownd
is available before making API calls. The Rownd SDK must be fully initialized.
Issue: Subscription fails silently
Solution: Check the response object and console for error details. Ensure the user has valid payment methods if required.Issue: Empty subscription list
Solution: Verify that subscription plans are properly configured in your Rownd dashboard and that the user is authenticated.Additional Notes
- All subscription amounts are in cents (multiply by 100 when saving, divide by 100 when displaying)
- The
subscriptionId
is different from theplanId
- use the correct one for each API call - Subscription status can be: active, trialing, canceled, past_due, etc.
- Always handle the case where a user has no active subscriptions
Quick-Start Implementation Prompt
Copy and paste this prompt into Cursor to implement Rownd Subscriptions in your app:
Note: This prompt is designed to work with Cursor’s AI capabilities to generate a complete implementation based on the Rownd Subscriptions documentation. The generated code will include proper error handling, loading states, and TypeScript types.
Understanding the API Methods and IDs
Finding and Using Subscription IDs
When working with Rownd Subscriptions, you’ll need to understand two important IDs:-
subscriptionId: This is the ID of the subscription configuration in your Rownd dashboard. You can find this by:
- Calling
window.rownd.subscriptions.available()
- Looking at the
id
field in the response (e.g.,"sub_r7i3j3hf7nliv0somxl99d08"
) - This ID represents the subscription configuration, not a user’s subscription
- Calling
-
planId: This is the specific plan/price ID within a subscription. You can find this by:
- Looking at the
presentation.options[].id
field in the available plans response - Format is typically
prod_XXX__price_YYY
- This ID represents the specific plan a user can subscribe to
- Looking at the
API Methods in Detail
1. Fetching Available Plans
- Returns all subscription plans configured in your Rownd dashboard
- Response structure:
2. Subscribing to a Plan
- Parameters:
subscriptionId
: From the available() response (e.g.,"sub_r7i3j3hf7nliv0somxl99d08"
)planId
: From the plan options (e.g.,"prod_XXX__price_YYY"
)
- Returns: Promise that resolves on successful subscription
- Status codes:
- 200: Success
- 400: Invalid parameters
- 401: Unauthenticated
- 402: Payment required
- 403: Forbidden
3. Listing User’s Subscriptions
- Returns all active subscriptions for the authenticated user
- Response structure:
Common Patterns and Gotchas
-
Finding the Right IDs:
-
Handling Multiple Plans:
-
Checking Subscription Status:
-
Error Handling:
- Always handle the case where a user has no active subscriptions
- Convert price amounts from cents to dollars for display
- Check authentication status before making API calls
- Handle loading states during API calls
- Provide clear error messages to users