React JS
Install
To get started with Saazpay in your React application, you need to install the necessary dependencies. Begin by installing the client library provided by Paddle itself:
After that, install the ## Alternative: Direct API Usage
If you're not using a Node.js backend, you can make direct API calls to Saazpay endpoints. Please refer to the Saazpay API documentation for the complete list of endpoints and request/response formats.
API Reference: For direct API usage without the Node.js SDK, see the API Reference documentation for complete endpoint specifications and examples. customizable template files using the following command:
This command will add all the files under the components/saazpay directory with the following structure. The templates are written in TypeScript and Tailwind CSS:
Usage
Important: Since React is a client-side library without server-side capabilities, all API calls to Saazpay must be handled through a separate backend server. We currently support the Node.js SDK
@saazpayhq/node-sdkfor backend integration. If you're using a Node.js backend, configure it accordingly. Otherwise, use the direct API endpoints.
Pricing Plans
To display pricing plans in your React application, you'll need to fetch the plans from your backend and pass them to the PricingPlans component. Here's how to implement it:
First, import the necessary components:
Then, create your component with the pricing plans functionality:
Backend API Endpoints:
You'll need to create API endpoints in your backend server to handle Saazpay operations. For detailed implementation examples and comprehensive backend setup, please refer to our Node.js SDK documentation.
See Node.js SDK Documentation: For complete backend API implementation examples, error handling, and best practices, check out the Node.js SDK guide.
Key Features:
- Plan Fetching: Fetches all available pricing plans from your backend API
- Active Subscription: Checks if the user has an active subscription through your backend
- User Authentication: Integrates with your authentication system to identify the current user
- Customizable Settings: The
settingsprop allows you to customize the appearance and behavior of the pricing plans
Props:
plans: Array of pricing plans fetched from your backendactivePlanId: The ID of the user's currently active plan (if any)settings: Configuration object for customizing the component appearance and behavior
Subscription Management
The subscription management component allows users to view and manage their active subscriptions, change plans, and access management URLs. Here's how to implement it:
First, import the necessary components:
Then, create your subscription management component:
Additional Backend API Endpoints:
For complete implementation of all required backend endpoints including management URLs, plan preview, and plan changes, please refer to our comprehensive Node.js SDK documentation.
Complete Backend Setup: See the Node.js SDK guide for detailed implementation of all required API endpoints with proper error handling, validation, and security practices.
Key Features:
- Active Subscription Management: Displays the user's current subscription details
- Plan Preview: Allows users to preview changes before switching plans
- Plan Changes: Enables users to change their subscription plan
- Management URLs: Provides access to external management interfaces
- API Integration: All operations are handled through your backend API
API Props:
The api prop contains functions for handling subscription operations:
getPlans: Fetches all available plans from your backendpreviewPlan: Previews the cost and changes when switching to a new planchangePlan: Changes the user's subscription to a new plan
Settings:
primaryColor: Customizes the primary color of the componentactiveSubscription: The user's current subscription datamanagementUrls: External URLs for subscription management
Backend Configuration
For complete backend setup including installation, configuration, and implementation details, please refer to our comprehensive Node.js SDK documentation.
Complete Backend Guide: See the Node.js SDK documentation for detailed backend setup instructions, environment configuration, and complete Express.js implementation examples.
Environment Variables
Make sure to add the following environment variables to your backend server:
For your React frontend, you'll need:
Variable Descriptions:
SAAZPAY_APP_ID: Your Saazpay application ID (backend only)SAAZPAY_BASE_URL: The base URL for Saazpay API calls (backend only)SAAZPAY_API_KEY: Your Saazpay API key for server-side operations (backend only, keep secret)NEXT_PUBLIC_PADDLE_CLIENT_KEY: Your Paddle client key for frontend integration