Skip to main content
This guide provides a complete overview of integrating Rownd Subscriptions into your React application.

Table of Contents

Overview

Rownd Subscriptions provides a simple API to manage subscription plans and user subscriptions in your application. The API is accessible through the global window.rownd object.

Prerequisites

  1. Rownd SDK must be installed and configured in your application
  2. User must be authenticated to access subscription features
  3. Subscription plans must be configured in your Rownd dashboard

API Methods

1. Get Available Subscription Plans

Description: Fetches all available subscription plans for the current application. Returns: Promise that resolves to an object containing available subscription plans.

2. Subscribe to a Plan

Parameters:
  • subscriptionId (string): The subscription ID from the available plans response
  • planId (string): The specific plan/price ID to subscribe to (format: prod_XXX__price_YYY)
Returns: Promise that resolves when subscription is successful (status 200).

3. List User’s Subscriptions

Description: Fetches all active subscriptions for the authenticated user. Returns: Promise that resolves to an object containing the 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:

  1. Timing: Show celebration for 4-5 seconds total
  2. Smooth Transitions: Use cubic-bezier easing for natural motion
  3. Fade Out: Always fade out before removing to avoid jarring transitions
  4. Accessibility: Ensure celebration doesn’t interfere with screen readers
  5. Performance: Use CSS animations instead of JavaScript for better performance
  6. Customization: Match celebration colors to your brand

Troubleshooting

Issue: “Cannot read properties of undefined”

Solution: Ensure window.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 the planId - 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:
  1. 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
  2. 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

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

  1. Finding the Right IDs:
  2. Handling Multiple Plans:
  3. Checking Subscription Status:
  4. Error Handling:
Remember:
  • 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