SDK Structure
The PaymentKit Node.js SDK is organized into a set of modules, each corresponding to a specific API resource like products, customers, or subscriptions. This modular design provides a clear and predictable way to interact with different parts of the PaymentKit API. After initializing the client, you access each resource as a property on the main payment object.
Before diving into the structure, ensure you have completed the setup described in the Get Started guide.
Client Initialization and Resource Access#
First, import and initialize the client. The default export is an object that serves as the entry point to all API resources.
import payment from '@blocklet/payment-js';
// Access the 'products' resource to list products
async function getProducts() {
const productList = await payment.products.list({ pageSize: 5 });
console.log('Fetched products:', productList.data);
}
// Access the nested 'checkout.sessions' resource to create a session
async function createCheckoutSession() {
// Assumes you have line_items defined
const session = await payment.checkout.sessions.create({
// ... session parameters
});
console.log('Created session:', session.id);
}The structure follows a consistent pattern: payment.<resource_name>.<method_name>().
API Resource Modules#
The SDK's structure is visualized below, showing how different resources are accessed from the main client object.
Each module provides methods for interacting with its corresponding API resource (e.g., create, retrieve, update, list). The primary resources available are:
Module | Description |
|---|---|
| Create and manage sessions for processing payments and setting up subscriptions. |
| Manage customer records. |
| Issue and manage credit grants for customers. |
| List and summarize customer credit transaction history. |
| Create and manage meters for tracking usage. |
| Report usage events to a meter. |
| List supported payment currencies. |
| Handle the lifecycle of a payment, from creation to confirmation. |
| Create and manage shareable payment links. |
| Manage payment method configurations. |
| Manage pricing models for products. |
| Manage the products or services you offer. |
| Process refunds for payments. |
| Manage application-wide settings. |
| Manage customer subscriptions to products. |
| Manage individual items within a subscription. |
| Configure endpoints to receive event notifications. |
Utility Modules#
In addition to API resources, the SDK includes utility modules.
environments
The environments module is used to configure the SDK, primarily for switching between test and live modes. You can learn more in the Environments guide.
TypeScript Types#
The SDK also re-exports all type definitions from the @blocklet/payment-types package. This enables strong typing and autocompletion in your development environment if you are using TypeScript. For more details, see the TypeScript Support section.
Now that you understand how the SDK is organized, the next step is to learn how to configure your API keys and environments. Proceed to the Environments guide to continue.