Get Started
This guide provides the essential steps to install the PaymentKit Node.js SDK, configure your environment, and make your first API call. Following these instructions will get you up and running quickly.
Installation#
The PaymentKit SDK is available as a package on npm. You can install it in your Node.js project using npm or another package manager.
npm install @blocklet/payment-jsConfiguration#
After installation, you need to import and configure the SDK in your application. The main configuration step involves setting the environment to either test or live mode.
1. Import the SDK#
First, import the payment object from the SDK into your application file.
import payment from '@blocklet/payment-js';2. Set the Environment#
PaymentKit operates in two distinct modes. You must set the environment programmatically before making any API calls.
- Test Mode: For development and testing. Transactions are simulated and do not involve real money.
- Live Mode: For production use with real transactions.
// Use test environment (recommended for development)
payment.environments.setTestMode(true);
// Use live environment (for production)
// payment.environments.setLiveMode(true);Make Your First API Call#
With the SDK configured, you are ready to interact with the PaymentKit API. The following example demonstrates how to list existing subscriptions in your test environment.
import payment from '@blocklet/payment-js';
// Set the environment to test mode
payment.environments.setTestMode(true);
async function getSubscriptions() {
try {
console.log('Fetching the first 5 subscriptions...');
const subscriptions = await payment.subscriptions.list({
pageSize: 5, // Limit to 5 results
order: 'updated_at:DESC' // Get the most recently updated first
});
console.log('API Response:', subscriptions);
} catch (error) {
console.error('An error occurred:', error.message);
}
}
getSubscriptions();Example Response
When you run this code, it confirms that your SDK is correctly set up and can communicate with the API. In a new account, you will likely receive an empty list.
{
"page": 1,
"pageSize": 5,
"total": 0,
"data": []
}What's Next?#
You have successfully installed and configured the PaymentKit SDK. To dive deeper into its capabilities, we recommend exploring the following sections:
- Core Concepts: Understand the fundamental principles of the SDK, including its structure and error handling.
- Usage Guides: Follow practical, step-by-step guides for common workflows like creating products, managing subscriptions, and handling payments.