Node JS
Install
To get started with Saazpay in your Node.js backend, install the Saazpay Node SDK:
Environment Variables
Make sure to add the following environment variables to your backend server:
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 (keep secret)
Usage
Import Functions
API Endpoints Implementation
Here are comprehensive examples of how to implement API endpoints using the Saazpay Node SDK:
Get Plans
Fetch all available pricing plans for your application.
Response Format:
Get Active Subscription
Retrieve the active subscription for a specific user.
Response Format:
Get Management URLs
Fetch management URLs for a specific subscription.
Response Format:
Preview Plan Change
Preview the changes and costs when switching to a new plan.
Response Format:
Change Plan
Change the subscription to a new plan.
Response Format:
Complete Express.js Example
Here's a complete example of an Express.js server with all Saazpay endpoints:
Error Handling
The SDK may throw errors in the following scenarios:
- Invalid App ID: When the provided
appIdis incorrect - Invalid API Key: When the API key is invalid or missing
- Network Errors: When there are connectivity issues
- Invalid Parameters: When required parameters are missing or invalid
Always wrap SDK calls in try-catch blocks and handle errors appropriately:
TypeScript Support
The SDK includes TypeScript definitions. Here are the main interfaces: