@cabloy/paypal-server-sdk

中文文档
2.2.0发布于 2026/03/05MITTypeScriptESM + CJS近 30 天下载 5103

PayPal's SDK for interacting with the REST APIs

原始使用文档
文档目录16 节
  1. Introduction
  2. Important Notes
  3. Information
  4. Install the Package
  5. Initialize the API Client
  6. Code-Based Client Initialization
  7. Configuration-Based Client Initialization
  8. Environment-Based Client Initialization
  9. Environments
  10. Fields
  11. Authorization
  12. List of APIs
  13. SDK Infrastructure
  14. Configuration
  15. HTTP
  16. Utilities

Getting Started with PayPal Server SDK

Introduction

Important Notes

  • Available Features: This SDK currently contains only 5 of PayPal's API endpoints. Additional endpoints and functionality will be added in the future.

Information

The PayPal Server SDK provides integration access to the PayPal REST APIs. The API endpoints are divided into distinct controllers:

Install the Package

Run the following command from your project directory to install the package from npm:

npm install @paypal/[email protected]

For additional package details, see the Npm page for the @paypal/[email protected] npm.

Initialize the API Client

Note: Documentation for the client can be found here.

The following parameters are configurable for the API Client:

ParameterTypeDescription
environmentEnvironmentThe API environment.
Default: Environment.Sandbox
timeoutnumberTimeout for API calls.
Default: 0
httpClientOptionsPartial<HttpClientOptions>Stable configurable http client options.
unstableHttpClientOptionsanyUnstable configurable http client options.
loggingPartialLoggingOptionsLogging Configuration to enable logging
clientCredentialsAuthCredentialsClientCredentialsAuthCredentialsThe credential object for clientCredentialsAuth

The API client can be initialized as follows:

Code-Based Client Initialization

import { Client, Environment, LogLevel } from '@paypal/paypal-server-sdk';

const client = new Client({
  clientCredentialsAuthCredentials: {
    oAuthClientId: 'OAuthClientId',
    oAuthClientSecret: 'OAuthClientSecret'
  },
  timeout: 0,
  environment: Environment.Sandbox,
  logging: {
    logLevel: LogLevel.Info,
    logRequest: {
      logBody: true
    },
    logResponse: {
      logHeaders: true
    }
  },
});

Configuration-Based Client Initialization

import * as path from 'path';
import * as fs from 'fs';
import { Client } from '@paypal/paypal-server-sdk';

// Provide absolute path for the configuration file
const absolutePath = path.resolve('./config.json');

// Read the configuration file content
const fileContent = fs.readFileSync(absolutePath, 'utf-8');

// Initialize client from JSON configuration content
const client = Client.fromJsonConfig(fileContent);

See the Configuration-Based Client Initialization section for details.

Environment-Based Client Initialization

import * as dotenv from 'dotenv';
import * as path from 'path';
import * as fs from 'fs';
import { Client } from '@paypal/paypal-server-sdk';

// Optional - Provide absolute path for the .env file
const absolutePath = path.resolve('./.env');

if (fs.existsSync(absolutePath)) {
  // Load environment variables from .env file
  dotenv.config({ path: absolutePath, override: true });
}

// Initialize client using environment variables
const client = Client.fromEnvironment(process.env);

See the Environment-Based Client Initialization section for details.

Environments

The SDK can be configured to use a different environment for making API calls. Available environments are:

Fields

NameDescription
ProductionPayPal Live Environment
SandboxDefault PayPal Sandbox Environment

Authorization

This API uses the following authentication schemes.

List of APIs

SDK Infrastructure

Configuration

HTTP

Utilities

版本与发布记录

@cabloy/paypal-server-sdk 共发布 1 个版本,首次发布于 2026/03/05;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.2.0latest2026/03/058 个月前

关于 @cabloy/paypal-server-sdk 的常见问题

@cabloy/paypal-server-sdk 是什么?

PayPal's SDK for interacting with the REST APIs

如何安装 @cabloy/paypal-server-sdk?

在项目目录运行 npm install @cabloy/paypal-server-sdk,或使用 pnpm add / yarn add / bun add。

@cabloy/paypal-server-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cabloy/paypal-server-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cabloy/paypal-server-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.17.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cabloy/paypal-server-sdk 可以商用吗?

@cabloy/paypal-server-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cabloy/paypal-server-sdk 的下载量有多少?

根据 npm 官方下载统计,@cabloy/paypal-server-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 5,103 次,日均约 170 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cabloy/paypal-server-sdk 还在维护吗?

最新版本 2.2.0 发布于 2026/03/05(8 个月前);至今共发布 1 个版本,其中过去 12 个月发布了 1 个;首次发布于 2026/03/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。