Next JS
Install
To get started with Saazpay in your Next.js application, you need to install the necessary dependencies. Begin by installing the client library provided by Paddle itself:
Then, install the Saazpay Node SDK:
After that, install the fully 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
Pricing Plans
To display pricing plans in your Next.js application, you'll need to fetch the plans from Saazpay and pass them to the PricingPlans component. Here's how to implement it:
First, import the necessary functions and components:
Important: Make sure you use methods from
@saazpayhq/node-sdksecurely with server actions or a separate backend server without revealing the API key to the client side. All SDK methods should be called on the server to protect your sensitive credentials.
Then, create your page component with the pricing plans functionality:
Key Features:
- Plan Fetching: Uses
getPlans()to retrieve all available pricing plans from Saazpay - Active Subscription: Checks if the user has an active subscription using
getActiveSubscription() - 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
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 functions and components:
Then, create your subscription management page:
Key Features:
- Active Subscription Management: Displays the user's current subscription details
- Plan Preview: Allows users to preview changes before switching plans using
previewPlan() - Plan Changes: Enables users to change their subscription plan using
changePlan() - Management URLs: Provides access to external management interfaces via
getManagementUrls() - Server Actions: All API calls are handled securely on the server side
API Props:
The api prop contains server actions for handling subscription operations:
getPlans: Fetches all available planspreviewPlan: 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
Environment Variables
Make sure to add the following environment variables to your .env, .env.local file:
Variable Descriptions:
NEXT_PUBLIC_PADDLE_CLIENT_KEY: Your Paddle client key for frontend integrationNEXT_PUBLIC_SAAZPAY_APP_ID: Your Saazpay application ID (public, used on client-side)SAAZPAY_BASE_URL: The base URL for Saazpay API calls (server-side only)SAAZPAY_API_KEY: Your Saazpay API key for server-side operations (keep secret)