Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
Core Concepts

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.

payment (SDK Client)

checkout

sessions

customers

products

prices

subscriptions

meters

creditGrants

... and other resources

environments (Utility)


Each module provides methods for interacting with its corresponding API resource (e.g., create, retrieve, update, list). The primary resources available are:

Module

Description

checkout.sessions

Create and manage sessions for processing payments and setting up subscriptions.

customers

Manage customer records.

creditGrants

Issue and manage credit grants for customers.

creditTransactions

List and summarize customer credit transaction history.

meters

Create and manage meters for tracking usage.

meterEvents

Report usage events to a meter.

paymentCurrencies

List supported payment currencies.

paymentIntents

Handle the lifecycle of a payment, from creation to confirmation.

paymentLinks

Create and manage shareable payment links.

paymentMethods

Manage payment method configurations.

prices

Manage pricing models for products.

products

Manage the products or services you offer.

refunds

Process refunds for payments.

settings

Manage application-wide settings.

subscriptions

Manage customer subscriptions to products.

subscriptionItems

Manage individual items within a subscription.

webhookEndpoints

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.